2
\$\begingroup\$

I have the following situation. I have a master (consumer) and a slave (producer), the slave has to be between nodes 1-127, in this case the slave is in the node 125.

I'm trying to syncronize both of them, for that, after some research I found about the heartbeat function.

I'm prety new to CANopen, so I've tried changing values in the master.dcf file. If you know about CANopen you will know that there are several parameters that are the same for everybody, so you can configure them in the way you need. In this case I've modified the 1017h (Producer heartbeat time) parameter by changing the DefaultValue to 1000 ms so every second I get a heartbeat from the producer (slave). Here you can see the master.dcf where I made the change:

[1017]
ParameterName=Producer heartbeat time
DataType=0x0006
AccessType=rw
DefaultValue=1000

My problem is making the same with the master (consumer). For this, in the master.dcf the parameter 1016h (Consumer heartbeat time) is suposed to function the same way as the 1017h but I don't know what to change in here in order to get a hearbeat from the master every second. Here is the 1016h in the master.dcf:

[1016]
ParameterName=Consumer heartbeat time
ObjectType=0x08
DataType=0x0007
AccessType=rw
CompactSubObj=127

[1016Value]
NrOfEntries=0

As mentioned, I've tried modifying the value of NrOfEntries, but I don't think this is somthing relevant to my case, so I left it as it was (NrOfEntries = 0).

I've also tried with other two parameters: 1006h and 1007h.

[1006]
ParameterName=Communication cycle period
DataType=0x0007
AccessType=rw
DefaultValue=0

[1007]
ParameterName=Synchronous window length
DataType=0x0007
AccessType=rw
DefaultValue=0

Both of them have a starting value of 0, and I've tried changing them to 1 but I still can't get to see the hearbeat of the slave.

To see what happens in CAN I'm using candump can0 in a terminal and I can see every message of the comunication, in the next image you can see a part of the comunication: Image candump

As you can see in the image, the line can0 701 [1] 05 is the line of the producers heartbeat that appears every second, as configured. The other lines are for CAN initialization (NMT messages) and valve opening and clossing.

In case someone thinks it's important. As a master I'm using a NVIDIA Xavier and as an slave I have a CR2041 ifm module, to where I've connected some valves to be controlled. The comunication happens when I execute the application that controls the valves.

If you need more information to help me ask for it without problems.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ "I'm trying to syncronize both of them" What do you mean? Heartbeat isn't to be used for that purpose, it is for supervision and trouble-shooting. It sounds like the feature you are actually looking for is the PDO SYNC message. \$\endgroup\$
    – Lundin
    Commented Jun 29, 2023 at 13:18
  • \$\begingroup\$ I agree. Heartbeat can be understood as a communication watchdog. \$\endgroup\$
    – Velvet
    Commented Jun 29, 2023 at 17:04

1 Answer 1

2
\$\begingroup\$

I've added comments next to the CANopen dump output (next time please add the dump in text form).

Red comment: Master (node 1)
Yellow comment: NMT (most probably from the master)
Green comment: Slave (node 125)

enter image description here

As you can see, it's not the slave (node 125) that's sending the bootup and heartbeat messages, but the master (node 1). There is nothing wrong with the master sending heartbeat messages. But in your case you said you wanted the slave to be the heartbeat producer and the master to be the heartbeat consumer.

In order to configure the slave (node 125) as heartbeat producer, yo need to configure 0x1017.0 accordingly:
Write 0x1017.0 = 1000: 67D [8] 2B 17 10 00 E8 03 00 00

This will let node 125 send heartbeat messages in a 1 second interval.

The heartbeat message produced by node 125 should look something like this: 77D [1] 05
The COB-ID should be 0x700 + NodeID; byte 1 indicates the NMT state.

You also have to configure the master as heartbeat consumer appropriately:
0x1016.1: (NodeId << 16) | HeartbeatConsumerTime

NodeId: node ID of the heartbeat producer
HeartbeatConsumerTime: it has to be greater that the heartbeat producer time (in ms)

For example, for node 125 and 2000 ms: (125 << 16) | 2000 = 0x007D07D0

Object 0x1016 is defined as an array of UNSIGNED32 values. 0x1016.0 holds the number of entries, which is read-only. For example when 0x1016.0 = 8, then the heartbeat consumer can consume up to 8 heartbeat producer messages, which means sub-indices 1 to 8 are available.


An excerpt from CiA 301.

Object 0x1016: Consumer Heartbeat Time

Structure of Consumer Heartbeat Time

Parameter Description
Index 0x1016
Name Consumer heartbeat time
Object code ARRAY
Data type UNSIGNED32
Category Optional

Entry Description:

Parameter Description
Sub-index 0x00
Description Highest sub-index supported
Entry category Mandatory
Access const
PDO mapping No
Value range 0x01 to 0x7F
Default value profile- or manufacturer-specific
Parameter Description
Sub-index 0x01
Description Consumer heartbeat time
Entry category Mandatory
Access rw
PDO mapping No
Value range UNSIGNED32 (Figure 62)
Default value 0x00000000
Parameter Description
Sub-index 0x02 to 0x7F
Description Consumer heartbeat time
Entry category Optional
Access rw
PDO mapping No
Value range UNSIGNED32 (Figure 62)
Default value 0x00000000

Object 0x1017: Producer Heartbeat Time

Object Description:

Parameter Description
Index 0x1017
Name Producer heartbeat time
Object code VAR
Data type UNSIGNED16
Category Conditional; Mandatory, if guarding not supported

Entry Description:

Parameter Description
Sub-index 0x00
Access rw; const, if default value is profile-specific and not changeable
PDO mapping No
Value range UNSIGNED16
Default value 0 or profile-specific
\$\endgroup\$
3
  • \$\begingroup\$ Hi, thanks for your answer. How can I convert the dump data to text form? Regarding the changes you comented, I'm going to try now and I'll let you know as soon as I can. \$\endgroup\$
    – Linux
    Commented Jun 28, 2023 at 8:18
  • \$\begingroup\$ In some Linux terminals you can simply select the text and paste it with the middle mouse button. In others you can right-click to open a context menu. (I don't know which terminal you're using.) \$\endgroup\$
    – Velvet
    Commented Jun 28, 2023 at 9:00
  • \$\begingroup\$ I'm using gnome terminal: xterm \$\endgroup\$
    – Linux
    Commented Jun 28, 2023 at 9:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.