Two CAN nodes start talking in the same microsecond, and the lower identifier wins without losing a single bit. EtherCAT gets the same order the other way: one frame visits every node.
Learn how the wires that join a robot’s joints stay on time: who gets to speak, how a bit is read, how the frames got bigger, and why one Ethernet frame can serve a hundred drives.
Press Send to start a frame from three nodes at once. Change an identifier and send again. Then turn the terminators off, press Send, and watch the error counter climb. After that we build, piece by piece, the wire, the timing, the faster frames, the layers above them, and EtherCAT.
You need to know what a bit is and to read a little C. We build the rest from zero. The lesson before this one is Buses on the Wire.
Built from primary sources, not from slides: the Kvaser and TI CAN tutorials, the CiA pages on CAN FD and CAN XL, the TI TCAN1042 and TCAN6062 data sheets, the ST STM32G4 FDCAN driver header and the EtherCAT Technology Group pages. The full list is in the Field Guide. Where the lesson draws a model, it says so.
A model, not silicon. The bus is a wired-AND of the bits the nodes send, the frame is the standard 11-bit CAN frame with 8 data bytes (01 to 08) and its real CRC-15, and the speed is 1 Mbit/s. With the terminators off, which bit is hit is a seeded pseudo-random pick, because real reflections depend on the cable. The error counter rule (add 8 for each failed send, bus-off above 255) is the CAN rule as the Kvaser tutorial states it.
Chapter 0
Follow a robot joint that fell silent, learn what its two error counters say, and find the cause with a meter before you touch any code
A robot arm has six joints. Each joint has a small chip that reads its angle and drives its motor. One pair of twisted wires runs along the arm, and all six chips and the main controller share it. This shared wire is a bus. Every chip on it is a node, and one message on it is a frame.
The team swaps a cable on the arm. Joint four goes quiet. The controller gets no reply from it, and the motor holds its last command. The chip is not broken. It is running, and it is reading its angle. Its bus controller has switched itself off the wire. In CAN terms, joint four is bus-off.
This chapter explains why a node switches itself off, and how you find the cause in five minutes. You do not need the details of the protocol yet. Chapter 1 builds those.
CAN is the Controller Area Network, a two-wire bus. Its first rule is simple. A node that sends a bit also listens to that bit on the wire. If the wire shows something else, the node knows the frame was damaged.
When a node sees damage, it sends an error frame: six bits in a row at the same level, which breaks the rule that no frame has six equal bits in a row (Chapter 2 explains why). Every node sees the break and throws the frame away. The sender then tries again on its own.
Trying again is right for a bad moment, such as a spark of noise. It is wrong for a bad wire, because the retries fail too. The CAN designers needed a way for a node to notice that it has become the problem. They gave each node two counters.
The transmit error counter (TEC) counts the damage a node causes as a sender. The receive error counter (REC) counts the damage it sees as a listener. The rule, as the Kvaser CAN tutorial gives it: a sending error adds 8 to TEC, a receiving error adds 1 to REC, and each correct frame takes a little off.
The counters set a state. Below about 96 the node is healthy and its error flag is loud (error active). Around 96 it raises a warning. Above 127 it is error passive: it still sends, but its error flag is quiet, so it cannot ruin other nodes’ frames. Above 255 on the TEC it is bus-off: it stops sending completely.
Now the arithmetic for joint four. Each failed send adds 8.
A controller that retries as fast as it can does this in about 32 frame times. At 1 Mbit/s a short frame lasts about 111 to 135 microseconds, so joint four goes dark in about five milliseconds.
Why does the rule subtract 1 for each good frame? It lets a node forgive rare faults. Say a fault hits one send in p. Each send adds 8 with chance p and subtracts 1 with chance 1 − p. The counter drifts upward only when 8p > 1 − p, so when p is above 1/9, about 11 percent. A fault below that level heals itself. A fault above it ends in bus-off, slowly.
Most bus-off faults on a new robot are wiring faults, not code. The wire is a transmission line, and a signal that reaches the end of an unmatched line bounces back and corrupts the next bits. The cure is a terminator: a 120 Ω resistor across the two wires at each end of the line. It matches the 120 Ω characteristic impedance of the twisted pair (TI application note SLOA101B), so the signal is absorbed instead of reflected.
You can check this with the power off. Put a meter across the two wires, called CANH and CANL. Two 120 Ω resistors in parallel give 60 Ω, because the parallel value is 120 × 120 / (120 + 120). So 60 Ω means both ends are terminated. 120 Ω means one is missing. A reading in the kilo-ohms means both are missing. Try the four wirings below, then drag the failures to see where the counter lands.
Top: the cable with its terminators and the meter reading across CANH and CANL, power off. Bottom: the transmit error counter after the number of failed sends in a row you choose.
The resistor arithmetic is exact: R = 1 / (n / 120 Ω) for n equal 120 Ω resistors. A real meter also sees each node’s transceiver input in parallel, which adds a small error. With none, the reading is high but not infinite (kilo-ohms), shown here as “open”. The counter uses the +8 rule with no good frames in between.
TxErrorCnt (0 to 255), RxErrorCnt (0 to 127) and the flags BusOff, ErrorPassive and Warning.c /* STM32G4 HAL: why is this joint quiet? */ FDCAN_ErrorCountersTypeDef ec; FDCAN_ProtocolStatusTypeDef ps; HAL_FDCAN_GetErrorCounters(&hfdcan1, &ec); /* ec.TxErrorCnt, ec.RxErrorCnt */ HAL_FDCAN_GetProtocolStatus(&hfdcan1, &ps); /* ps.BusOff, ps.ErrorPassive, ps.Warning */ if (ps.BusOff) { /* stop retrying: log ec.TxErrorCnt, then recover on purpose */ }
TxErrorCnt once a second.Chapter 1
See how a shout always beats silence, why that lets the lowest identifier win without damage, and how to count the wait of the message with the lowest priority
Two joints finish a measurement in the same microsecond. Both want to report to the controller. They share one pair of wires, so both start to send. On an office Ethernet cable of the old shared kind, this is a collision: the two signals mix, both frames are garbage, both senders stop, wait a random time and try again. Time is lost, and nobody can say how much.
A robot cannot accept that. CAN uses a different trick. The two frames mix, and one of them comes out whole. The hero at the top of this page does it: the loser backs off in the middle of the frame, and the winner never notices.
A CAN node does not send a voltage on one wire. It drives two wires, CANH and CANL, and the receiver looks at the difference between them. This is differential signalling. Noise from a motor lands on both wires about equally, so it cancels when the receiver subtracts them. TI’s CAN application note calls this the reason for the high noise immunity.
The bus has two levels. In the dominant level a node drives CANH toward 3.5 V and CANL toward 1.5 V, a difference of about 2 V. In the recessive level nobody drives and the terminators pull the two wires to nearly the same voltage. A receiver reads a difference below 0.5 V as recessive (ISO 11898-2 as summarised on the CAN bus article of Wikipedia). By convention dominant is the bit 0 and recessive is the bit 1.
Picture a dark room where anyone may shout. Silence means 1. A shout means 0. If one person shouts and the rest stay silent, everybody hears a shout. If nobody shouts, everybody hears silence. So the room carries the AND of what people do: a 1 only if all of them said 1. Engineers call this a wired-AND. The Kvaser tutorial says it directly: if just one node drives the bus dominant, the whole bus is dominant.
Now give each frame a start-of-frame bit, a 0, and then an 11-bit identifier, sent most significant bit first. The identifier says what the message is, for example “joint 3 position”. Every sender listens to each bit it sends. The rule of arbitration is one sentence: if you send a 1 and hear a 0, someone with a lower number is also sending, so stop and wait.
A worked example, the one in the hero. Node A holds 0x100 and node B holds 0x0F0. In 11 bits:
Because the lower number has more leading zeros, the lower number wins. 0x0F0 is 240 and 0x100 is 256, and the smaller one wins. The identifier is both a name and a priority.
This is non-destructive arbitration. Nothing is lost except the loser’s turn. The loser tries again when the bus is free. Worry about one thing: two nodes must never send the same identifier, because no bit differs and nobody backs off. Try it in the hero by typing the same number in A and B.
To count waits, you need the length of a frame. The standard frame has these fields, with their sizes in bits (Wikipedia, CAN bus): start 1, identifier 11, RTR 1, IDE 1, reserved 1, length code 4, data 0 to 64, CRC 15, CRC delimiter 1, ACK slot 1, ACK delimiter 1, end-of-frame 7, and a 3-bit gap. With 8 data bytes that is 1 + 11 + 1 + 1 + 1 + 4 + 64 + 15 + 1 + 1 + 1 + 7 + 3 = 111 bits.
The real frame is longer, because of stuffing (Chapter 2 explains the rule). The sender adds one extra bit after five equal bits, in the part from the start bit to the end of the CRC, which is 98 bits long. Worst case, a stuff bit follows the first five bits and then one more every four bits. That is ⌊(98 − 1) / 4⌋ = 24 extra bits. The worst case is 111 + 24 = 135 bits. In general, a frame with s data bytes takes at most 8s + 47 + ⌊(34 + 8s − 1) / 4⌋ bits including the gap, which gives 135 for s = 8. At 1 Mbit/s each bit takes 1 µs, so a frame lasts 111 to 135 µs. The hero’s example frame is 121 bits.
Arbitration picks who goes next. It never stops a frame already running. So a message that arrives just after another has started must wait for that frame to end. This wait is the blocking time: at most one frame of a lower priority, 135 bits. Then it also waits for every higher-priority message that arrives while it waits.
Add these waits up with a loop. Start with the blocking time w = B. Repeat: w = B + the sum, over each higher-priority message j, of ⌈(w + 1 bit) / Tj⌉ × Cj, where Tj is its period and Cj its frame time. Stop when w stops changing. Then the worst response is w + the message’s own frame time.
The failure mode is quiet. A motor-command message at the top of the priority list is made faster during a test. It never loses arbitration, so it works. But every message below it waits longer, and the lowest ones starve. The symptom is a log or a temperature that goes missing under load. The measurement is a bus-load analysis by identifier. Change the speed of the chatty message below and watch the other bars.
Four messages share the bus. The top bar is the bus load, by identifier. Each row below shows the longest possible wait from queue to end of frame, against a deadline of one period. Drag the period of 0x010 down.
Illustrative message set: 0x010 motor command, 8 bytes; 0x120 joint position, 8 bytes, every 5 ms; 0x200 temperature, 4 bytes, every 20 ms; 0x7F0 log, 8 bytes, every 100 ms. Frame times use the worst-case length formula above. The wait is the standard fixed-priority recurrence for a bus where a running frame cannot be interrupted. Jitter and errors are ignored.
Chapter 2
Slice one bit into small time steps, decide when to look at the wire, and see why a long cable moves that moment
A new arm works on the bench. Two boards, one short cable, no errors for hours. The team installs it. The elbow board sits 40 metres of cable away from the base board, and now the error counters climb. Nothing changed in the code. The bit rate is the same. The cable is longer, and that is the whole difference.
To see why, we need to look inside one bit. A bit is not a point. It is a slice of time, and the node must pick one moment in that slice to read the wire.
A CAN node has no clock wire. Each node counts time with its own oscillator, and it cuts every bit into small equal steps called time quanta. One quantum is the controller clock period times a divider called the prescaler. A bit has a fixed number of quanta in four jobs (Kvaser CAN tutorial):
The node reads the bus once per bit, at the border between phase segment 1 and phase segment 2. This is the sample point. Many controllers, including ST’s, merge the middle two into one number, so you set just two: segment 1 (propagation plus phase 1) and segment 2.
The Kvaser tutorial gives a full example. A 16 MHz clock with a divider that makes each quantum 500 ns. In that example segment 1 is 5 quanta and counts the sync quantum inside it, and segment 2 is 3, so a bit is 8 quanta. 8 × 500 ns = 4 µs, which is 250 kbit/s. The sample point is 5 / 8 = 62.5 percent of the way through the bit. On an STM32 FDCAN controller the sync quantum is separate, so the same bit is NominalTimeSeg1 = 4 and NominalTimeSeg2 = 3, with the divider in NominalPrescaler (ST’s HAL header lists the ranges 2 to 256, 2 to 128 and 1 to 512).
Arbitration needs a hard thing: node A must hear what the farthest node does in the same bit. Here is the worst case. A starts a bit. The signal needs time to reach node Z at the far end. Z sees A’s bit start late and answers with its own dominant bit. That answer needs the same time to come back. So A can only trust the wire after one round trip: twice the cable delay, plus the delay in the two transceivers.
Three numbers go into the sum. A twisted pair carries a signal at about 5 nanoseconds per metre (a typical figure; the cable data sheet gives the real one). The TI TCAN1042-Q1 transceiver has a total loop delay from input to output of about 110 ns typical, and 175 ns at most. Use 110 ns for each of the two transceivers.
The worked example, at 1 Mbit/s, so a bit lasts 1000 ns, over 40 m:
This is the bug from the start of the chapter. On the 5 m bench cable the round trip is 2 × 25 + 220 = 270 ns, so a 50 percent sample point passes. On the 40 m cable it fails, and only there. The symptom is error frames on the long bus. The measurement is the bit timing registers and the length of cable. The fix is a later sample point, or a slower bit rate. The ISO 11898 standard rates 1 Mbit/s for 40 m, and up to 30 nodes (TI application note SLOA101B). Wikipedia gives 500 m as an example for 125 kbit/s. The model below is more generous than the standard: it ignores oscillator error, slow edges and stubs, so trust the standard’s numbers over the model’s.
One bit, cut into 20 time quanta. The warm bar is the round trip of the cable and transceivers. The line is where the node reads the bus. Move the sample point and the cable length.
Illustrative model: a 40 MHz controller clock, 20 quanta per bit, 5 ns per metre of cable, and two transceivers at the 110 ns typical loop delay of the TCAN1042-Q1 data sheet. It checks only that the sample point falls after the round trip. It ignores oscillator tolerance, edge slope and stubs, so it allows longer cables than ISO 11898 does.
The receiver lines up with the sender on every edge. At the start bit it does a hard sync. After that, each edge that falls outside the sync segment makes it lengthen or shorten a phase segment, by up to a set number of quanta called the sync jump width. So a receiver needs edges. A long run of identical bits has none.
CAN fixes this with bit stuffing. After five equal bits the sender adds one bit of the opposite level. The receiver removes it. The Kvaser tutorial states the rule in these words: after five consecutive bits of the same level, add a sixth of the opposite level. Six equal bits in a row can then only mean an error, which is also why an error frame is six equal bits. The cost is length: the frame grows with the data. Pick a payload below and see the same identifier cost more or fewer bits.
The bits of a frame from the start bit to the CRC, with identifier 0x0F0. Yellow cells are stuff bits. Choose a payload.
Real encoder: the frame is built from the standard 11-bit layout with its CRC-15 (polynomial 0x4599) and stuffed by the rule above. The count here covers the 98 bits from the start bit to the end of the CRC; the 13 bits after the CRC are not stuffed.
TxErrorCnt. Raise NominalTimeSeg1 until the errors stop. Then record the cable length and the final sample point.Chapter 3
Find out why a classical frame carries so little, and how FD and XL keep the same arbitration but speed up the data
The arm now sends its full state every millisecond: for each of six joints, a position, a speed and a motor current. That is 64 bytes. A classical CAN frame holds at most 8 bytes. So the controller needs eight frames, and each one costs 111 to 135 bit times, even though only 64 of those bits are data.
At 1 Mbit/s that is about 1.08 ms of bus time (8 × 135 µs) for a message every 1 ms. The bus is full before any other traffic. CAN FD and CAN XL exist to fix exactly this.
CAN FD means CAN with Flexible Data-rate. It changes two things.
The first idea is a bigger payload: up to 64 bytes in one frame. The 4-bit length code keeps its meaning for 0 to 8 bytes. The codes 9 to 15 stand for 12, 16, 20, 24, 32, 48 and 64 bytes (Wikipedia, CAN FD). One header now serves 64 bytes instead of 8, so the share of overhead falls.
The second idea is the bit rate switch. Recall Chapter 2: the sample point must wait for a round trip, because during arbitration any node may answer in the same bit. But after arbitration only one node is sending. It has won. Nobody else needs to answer inside a data bit, so the round trip no longer limits the bit. The frame can switch to a faster clock once arbitration is over, and switch back before the acknowledge. A frame has a bit called FDF that tells receivers it is an FD frame (recessive for FD, dominant for classical), a BRS bit that says whether to switch, and an ESI bit that carries the sender’s error state (Wikipedia).
So an FD frame runs in two phases. The arbitration phase uses the nominal bit rate, which is limited to 1 Mbit/s so that FD and classical nodes can share one bus. The data phase runs faster. Typical data rates are 2 to 5 Mbit/s, and 8 Mbit/s is possible with a CAN SIC transceiver (Wikipedia). The TI TCAN1042-Q1 data sheet says all its versions support classical CAN and 2 Mbps FD, and the “G” versions support 5 Mbps. One more change: the checksum grows to a 17-bit CRC for payloads up to 16 bytes and a 21-bit CRC above that (Wikipedia).
CAN XL is the third generation of the same link layer. The CiA page says it carries 1 to 2048 bytes in a frame, in one-byte steps, and is standardised in ISO 11898-1:2024. It keeps an 11-bit priority field for arbitration and adds a separate 32-bit acceptance field for addressing. Its data bits use a different line code, PWM, which allows bit rates of 20 Mbit/s and higher. For 20 Mbit/s and above a node needs a CAN SIC XL transceiver. The TI TCAN6062-Q1 is a CAN XL transceiver that supports up to 20 Mbps in its FAST mode and up to 8 Mbps in its SIC mode. TI lists the part as preview at the time of this lesson, so treat it as new.
The idea is the same as for FD: win arbitration at a rate the whole cable can follow, then send a long payload fast. Try the three together below. The device counts the bus time for a payload you choose.
Pick how many bytes to move and the FD data rate. Each bar is the bus time, on a log scale: classical CAN at 1 Mbit/s, CAN FD, and the CAN XL data field alone.
A model, accurate to a few percent. Classical: ceil(bytes / 8) frames at the worst-case 135 bits and 1 Mbit/s. FD: about 30 bits at the 1 Mbit/s nominal rate (header up to the bit rate switch, then delimiter, acknowledge, end and gap) plus the data phase: ESI, length, payload with a 1.2 stuffing factor, 4-bit stuff count, CRC 17 or 21 and fixed stuff bits, at the chosen rate. XL: payload bits at 20 Mbit/s only, a lower bound, because the header, CRC and arbitration of an XL frame are not modelled.
Take the 64-byte state. Eight classical frames take 1080 µs. One FD frame with a 5 Mbit/s data phase takes about 30 µs at the nominal rate plus about 130 µs in the data phase: roughly 160 µs, close to seven times faster. The XL data field alone needs 64 × 8 / 20 = 25.6 µs. That frees the bus for the other traffic.
FD nodes can share a bus with classical nodes only when no FD frame is sent that the classical nodes cannot read. A classical node does not know the FD format. It reads an FD frame as a damaged classical frame, expects a classical length and CRC, and signals errors before the frame ends. The symptom is error frames that start as soon as an FD sender joins the bus, and counters that climb on the classical nodes. The measurement is a capture that shows the FDF bit (recessive in an FD frame) and the faster bits after it. The fix is to move every node on the bus to FD, or to keep FD traffic on its own bus.
FDCAN_FRAME_CLASSIC, FDCAN_FRAME_FD_NO_BRS and FDCAN_FRAME_FD_BRS. Repeat this: send the same 64 bytes in the three modes with a scope on CANH minus CANL, and measure the frame length against the numbers above.Chapter 4
Give the bytes of a frame a meaning, pack a joint’s state into one message, and see how a heartbeat finds a dead node
Two joint drives from two vendors both speak CAN. Both obey every rule of Chapters 1 to 3. You connect them, and nothing works. Drive A sends its position in bytes 0 to 3. Drive B sends its status in bytes 0 and 1. A frame is an identifier and up to 8 bytes (or 64, or 2048). CAN does not say what those bytes mean.
The meaning comes from a higher-layer protocol: an agreement, written down, about which identifier carries what. This chapter looks at the one that robot joint drives use most, CANopen, then at a cousin for vehicles, and then at a job that every CAN node must also do: take a new program.
CANopen gives every node a node ID from 1 to 127, which fits in 7 bits. It then builds each 11-bit identifier from a 4-bit function code plus the node ID. The result is called a COB-ID (Wikipedia, CANopen). These are the default values, with node ID written as n:
| Message | Default identifier | Job |
|---|---|---|
| NMT | 0x000 | start, stop and reset nodes |
| SYNC | 0x080 | a shared tick |
| Emergency | 0x080 + n | a node reports a fault |
| TPDO1 | 0x180 + n | fast data from the node |
| RPDO1 | 0x200 + n | fast data to the node |
| SDO reply / request | 0x580 + n / 0x600 + n | read or write one setting |
| Heartbeat | 0x700 + n | “I am alive” |
Look at the order. Chapter 1 said a lower identifier wins. So NMT and SYNC beat everything, process data beats settings, and the heartbeat comes last. The address book is also a priority list, by design.
Every CANopen node keeps a table called the object dictionary. Each entry has a 16-bit index and an 8-bit subindex, and holds one value: the target position, the motor temperature, the current limit. It is a set of named pockets inside the node. CiA 402, the CANopen profile for motion drives (Wikipedia), fixes the indexes of the usual drive values, so drives from different vendors answer to the same numbers. (Common ones are 0x6041 for the status word, 0x6064 for the actual position and 0x6077 for the actual torque; check your drive’s EDS file, its electronic data sheet, for the exact list.)
There are two ways to reach a pocket. A service data object (SDO) reads or writes one entry. It is a question and an answer, so it is slow, and it suits setup. In the expedited form all the data fits in one frame, up to four bytes; bigger values are split over several frames. A process data object (PDO) is fast. It sends the values of several entries in one frame, with no question and no answer.
How does a PDO know which entries to carry? Through PDO mapping. The node holds a short list. Each list item is a 32-bit word: the index (16 bits), the subindex (8 bits) and the size in bits (8 bits). For the first transmit PDO the list lives at index 0x1A00 and its settings at 0x1800 (CiA 301). The word 0x60640020 means: index 0x6064, subindex 0, 32 bits long. The frame is just those values, one after another. A PDO has 64 bits at most, since CANopen uses classical frames. Try packing a joint’s state below.
Choose which entries go into the first transmit PDO of node 5. The row shows the eight bytes of the frame. Add the clash to see two nodes with the same node ID.
Illustrative drive. Sizes are typical; the status word, position, velocity and torque indexes follow the CiA 402 convention, and the temperature uses an index from the manufacturer range (0x2001), so check your drive’s EDS. The heartbeat identifier is 0x700 + node ID from the CANopen default table.
How does the master know a joint died? Each node sends a heartbeat frame at a set period, with identifier 0x700 + n and one data byte that gives its state. The master keeps a timer for each node. If a heartbeat is late, the node is gone.
Now two drives are installed with the same node ID, for example 5. Both send identifier 0x705 and both start at the same instant. Chapter 1 told you what happens: no bit differs in the identifier, so nobody backs off. They clash later, in the data byte, as a bit error. Error frames follow, both counters climb, and the master sees heartbeats that appear and vanish. This is the symptom to remember: half-working nodes that come and go, and rising error counters on two nodes at once. The measurement is a single-node bring-up: unplug all but one and read the node ID. The fix is a unique ID per joint, set by a switch or by the commissioning tool.
Trucks and farm machines use a similar layer called SAE J1939. It uses the 29-bit extended identifier of CAN 2.0B (Kvaser CAN tutorial) and packs priority, message type and sender address into it. This lesson did not open the J1939 standard; read it before relying on the field layout.
The last job is the program itself. A CAN node holds a small bootloader, a program that does nothing but accept a new image. The tool sends the image in chunks. Each chunk goes to a flash address, and the bootloader checks a checksum before it jumps in. The bus time is a plain division. An image of 256 KB is 262,144 bytes. Eight bytes per classical frame means 32,768 frames at 135 µs each, which is 4.4 seconds of pure bus time at 1 Mbit/s. With CAN FD at 64 bytes and about 160 µs per frame (Chapter 3) it is 4,096 frames, about 0.66 seconds. Flash erase and write add more. The lesson Bootloaders and OTA covers the update design itself, and the quiet danger here is power loss in the middle of a write.
Chapter 5
Watch one Ethernet frame thread through every drive on the robot, and count the cycle time with plain arithmetic
A humanoid has forty drives. Each one needs a fresh command and returns a fresh measurement many times a second. Chapter 3 gave CAN a bigger frame. Even so, forty nodes means forty replies, each with its own header, each waiting its turn in arbitration. The bus time adds up fast.
EtherCAT takes a different road to the same goal: a bus whose timing you can compute. It does not let nodes compete. It lets one node talk, and the one frame it sends visits everyone.
EtherCAT rides on ordinary Ethernet wires and frames. A fast-Ethernet link sends 100 million bits per second, so one byte takes 80 nanoseconds. An Ethernet frame has a 14-byte header, a payload, a 4-byte check sequence, and a gap of about 12 bytes before the next frame. EtherCAT marks its frames with the type number 0x88A4 in the header (Wikipedia, EtherCAT).
In a normal Ethernet network a switch sits between nodes. A switch uses store and forward: it receives the whole frame, checks it, and only then sends it on. Each hop costs one full frame time. Forty hops cost forty frame times.
The EtherCAT MainDevice is the master, the one node that controls the line. It sends a single frame. Every SubDevice (the drive or I/O module on the line) holds a hardware chip called the EtherCAT slave controller, or ESC. As the frame’s bits stream through, the ESC copies out the bytes addressed to it and writes its own bytes into the same place in the frame. It does not wait for the frame to end. This is processing on the fly. The ETG technology page says the frame is delayed only by hardware propagation delay times, and that the ESC works entirely in hardware, so no software on the drive is in the path.
The last node on the line sees an open port, turns the frame around, and sends it back to the master. Full-duplex Ethernet lets the frame travel on the return pair while new bytes leave. The master is the only node allowed to start a frame, and all other nodes forward frames downstream. So there is no arbitration, and no collision, and nothing to wait for. Each addressed SubDevice that could reach its memory also adds to a working counter (1 for a read or a write) in the frame. If the master gets the wrong total, it knows a node missed its part and refuses the data.
With no waiting, the time to go round is easy to write down. Call the frame time T, the time to push all its bits onto the wire. The head of the frame then crosses 2 N ESC hops, out and back, and each hop costs a forwarding delay d in the ESC plus the cable. So:
cycle ≈ T + 2 × N × (d + cable delay per hop)
Here is the worked example with sixteen SubDevices, each with 8 bytes of process data. The data is 16 × 8 = 128 bytes. Add about 52 bytes of Ethernet and EtherCAT overhead and the frame is about 180 bytes. At 80 ns per byte, T = 180 × 80 ns = 14.4 µs. Let each ESC delay the frame 500 ns and each 5 m cable add 25 ns. Then 2 × 16 × 525 ns = 16.8 µs. The round trip is about 31 µs. A store-and-forward line would need 16 × 14.4 µs = 230 µs even in one direction. That gap is the point of the design. The ETG page states design targets of cycle times of 100 µs or less, and the Wikipedia article says 1000 distributed digital I/O take about 30 µs. Those are targets and claims for good cases. They are not promises for every line.
The warm bar is the frame, on the way out (top row) and back (bottom row). A SubDevice turns teal while the frame passes it. Change the line and read the cycle time.
An honest model with illustrative numbers. The 80 ns per byte is exact for 100 Mbit/s. The overhead of about 52 bytes (preamble, Ethernet header, EtherCAT header, datagram header, working counter, check sequence, gap) is from memory of the frame format, and the minimum frame is respected. The ESC forwarding delay and the cable delay (5 ns per metre, 5 m per hop) are placeholders: your ESC data sheet gives the real delay. The slow SubDevice is a fault model, not a measured part. The animation runs in slow motion.
The formula shows where the cycle can go wrong. Every term counts twice, because the frame passes each SubDevice out and back. If one SubDevice adds a long delay, the whole line pays double, every cycle. Drag the slow SubDevice slider and watch the cycle time grow 2 µs for each 1 µs of extra delay. The symptom is a control loop that runs late. The measurement is the distributed-clock diagnostics, which report the delay each SubDevice adds (Chapter 6). The fix is to move that SubDevice to the end of the line or to a branch, and to check its ESC settings.
Chapter 6
Find out why two good buses can still disagree about the time, and turn a clock error into millimetres at the end of an arm
The arm’s drives sit on EtherCAT. Its wrist camera and force sensor report over another link. The controller fuses the two streams to decide how hard to push. The loop runs, but the arm hums. The data is good. The timestamps are the problem: the drive samples were taken 300 microseconds before the sensor samples, and the controller treats them as simultaneous.
A deterministic bus has a known delivery time. It does not give two nodes the same clock. This chapter separates those two ideas.
Each node counts time with its own crystal. A crystal is never exact. A tolerance of 20 parts per million (ppm) is a typical illustrative figure, so one node’s second is off by up to 20 microseconds. Two nodes can be off in opposite directions, so they differ by up to 40 microseconds per second. After one minute that is 2.4 milliseconds. A free-running clock needs a correction, again and again.
CANopen SYNC. One high-priority frame, identifier 0x080 (Chapter 4), tells every node to sample now. All nodes see the same bit at nearly the same time, so they agree with each other to within the cable delay, about 5 ns per metre. But CAN cannot interrupt a frame in progress (Chapter 1), so the SYNC can leave the controller up to one frame late: 135 µs at 1 Mbit/s. The nodes agree among themselves, but not with the controller’s clock.
PTP. The Precision Time Protocol, IEEE 1588, makes a node learn the offset to a reference clock by exchanging four timestamps in two messages. Its profile for Ethernet networks in vehicles and robots, IEEE 802.1AS or gPTP, is a constrained subset of 1588, and Wikipedia describes it as having sub-microsecond precision. The offset maths is the subject of Time and Sync. Deterministic Ethernet (TSN) as a whole is a topic for a later lesson in this series.
EtherCAT distributed clocks. The first SubDevice that has a clock acts as the reference. The system time is a 64-bit count of nanoseconds (Wikipedia, EtherCAT). At start-up the MainDevice measures the propagation delay to each SubDevice, because the reference time reaches each one late, and it writes that delay into the ESC for compensation. The ETG page says calibration is done in hardware, that the reference time is redistributed cyclically to fight drift, and that the resulting jitter is significantly less than 1 µs. The page gives no tighter figure in text, so this lesson does not either. Read the ETG specification and the data sheet of your ESC for numbers.
PTP corrects a clock by messages that cross a network of switches. EtherCAT corrects it with frames that already pass through every device. Both aim for the same thing: one time, shared.
Here is the worked example. A joint turns at 2 radians per second. A skew of 300 µs between its feedback and the sensor stream is an angle of 2 × 0.0003 = 0.0006 rad, or 0.6 mrad. On an arm 1 m long, the fingertip is 0.6 mm off. That is the hum. With a skew below 1 µs the same arithmetic gives under 0.002 mm, and the error is gone. The symptom is a smooth but wrong fusion. The measurement is to timestamp both streams against one clock and plot the difference. The fix is to put the sensors on the same distributed clock, or to timestamp them at the pin against a shared reference (the later lesson on the latency budget covers this).
Each bar is the time error between two nodes, on a log scale. The number beside it is the position error at the end of a 1 m arm that turns at the speed you choose.
Free-running: two crystals at 20 ppm each, so the worst-case difference is 40 µs per second elapsed (illustrative tolerance). CANopen SYNC: the 135 µs worst-case frame in progress at 1 Mbit/s (Chapter 1). gPTP and EtherCAT: both sources say sub-microsecond, so the bars show the 1 µs bound, not a measured value. Position error is joint speed times time error times a 1 m reach.
Notice what the three share. In each one a bound on the time error is a design choice, not a gift: CAN needs a SYNC frame and a priority plan, EtherCAT needs a reference clock and a measured delay for each hop, and gPTP needs hardware timestamps in every switch. Without that work, each node simply keeps its own time.
| Bus | Who may send | Why delivery time is known | Weak point |
|---|---|---|---|
| CAN / CAN FD | any node, by identifier | lowest identifier wins; worst-case wait is a sum | bandwidth; no shared clock |
| EtherCAT | only the MainDevice | one frame, processed on the fly | special hardware in every SubDevice |
| TSN Ethernet | any node, on a schedule | shared time plus reserved slots | needs switches that support it |
Chapter 7
Keep the numbers, the bring-up checklist and the core code on one page, and see where each fact came from
CAN and EtherCAT reach a bus you can compute by opposite routes. On CAN, many nodes may send, and the wired-AND bus lets the lowest identifier win a bit-by-bit race without damage. You then add up the worst wait with a recurrence. On EtherCAT, only the MainDevice sends, and one frame is read and written by every SubDevice’s hardware as it flows past. You then add the frame time and the hop delays. Either way the question is the same: can you write the worst case as a sum? If you can, you can promise a deadline.
| Quantity | Value | Source |
|---|---|---|
| Dominant / recessive | CANH toward 3.5 V, CANL toward 1.5 V, about 2 V apart; below 0.5 V reads recessive | Wikipedia, CAN bus (ISO 11898-2) |
| Termination | 120 Ω at each end; about 60 Ω across the wires, power off | TI SLOA101B; the 60 is 120 in parallel with 120 |
| Classical limits | 1 Mbit/s, 40 m, 30 nodes, stub up to 0.3 m | TI SLOA101B |
| Frame, 8 data bytes | 111 bits at least, 135 bits at most, including the 3-bit gap | field sizes from Wikipedia; stuffing worked in Chapter 1 |
| Stuff rule | a sixth bit of opposite level after five equal bits | Kvaser CAN tutorial |
| Bit timing example | 16 MHz, 500 ns quantum, 8 quanta, 250 kbit/s, sample point 62.5% | Kvaser CAN tutorial |
| Error counters | send error +8, receive error +1; warning about 96; passive above 127; bus-off above 255 | Kvaser CAN tutorial; ST STM32G4 HAL header |
| Transceiver loop delay | TCAN1042-Q1: 100 / 110 ns typical, 160 / 175 ns maximum | TI TCAN1042-Q1 data sheet |
| STM32 FDCAN limits | nominal prescaler 1 to 512, segment 1: 2 to 256, segment 2: 2 to 128 | ST stm32g4xx_hal_fdcan.h |
| CAN FD | up to 64 bytes; arbitration at most 1 Mbit/s; data phase 2 to 5, up to 8 Mbit/s; CRC 17 or 21 bits | Wikipedia, CAN FD; TI data sheet |
| CAN XL | 1 to 2048 bytes; 20 Mbit/s and higher; ISO 11898-1:2024 | CiA CAN XL page |
| TCAN6062-Q1 | CAN XL transceiver, 20 Mbps FAST mode, 8 Mbps SIC mode, listed as preview | TI product page |
| CANopen defaults | SYNC 0x080; TPDO1 0x180 + n; heartbeat 0x700 + n; node ID 1 to 127 | Wikipedia, CANopen |
| EtherCAT | EtherType 0x88A4; up to 65,535 devices per segment; cycle target at most 100 µs; 1000 I/O in about 30 µs | Wikipedia, EtherCAT; ETG technology page |
| Distributed clocks | 64-bit count of 1 ns; jitter significantly below 1 µs | Wikipedia; ETG technology page |
| gPTP | IEEE 802.1AS, a subset of IEEE 1588 with sub-microsecond precision | Wikipedia, Time-Sensitive Networking |
Not verified in this lesson: the ESC forwarding delay of any real part, the EtherCAT frame overhead of 52 bytes (from memory), the datagram field sizes, the SAE J1939 field layout, and the CiA 402 object indexes. Each needs the ETG specification, the SAE standard, or your drive’s EDS file.
TxErrorCnt and RxErrorCnt and alert above 96.The arbitration, the stuffing and the worst-case wait fit in a page of C. The first function is the whole of arbitration: a node that sends a recessive bit and reads a dominant one stops.
c /* 1. Arbitration: one bit of the identifier field. 1 = recessive, 0 = dominant. */ typedef enum { KEEP_SENDING, LOST_ARBITRATION } arb_t; static arb_t arbitrate_bit(int sent, int read_back) { return (sent == 1 && read_back == 0) ? LOST_ARBITRATION : KEEP_SENDING; } /* 2. CRC-15 of the CAN frame: polynomial 0x4599, runs over SOF..data bits. */ uint16_t crc15(const uint8_t *bits, int n) { uint16_t crc = 0; for (int i = 0; i < n; i++) { uint16_t nxt = bits[i] ^ ((crc >> 14) & 1); crc = (crc << 1) & 0x7FFF; if (nxt) crc ^= 0x4599; } return crc; } /* 3. Bit stuffing: after five equal bits add one of the opposite level. Returns the new length. The added bit starts the next run. */ int stuff(const uint8_t *in, int n, uint8_t *out) { int m = 0, run = 0, last = -1; for (int i = 0; i < n; i++) { out[m++] = in[i]; run = (in[i] == last) ? run + 1 : 1; last = in[i]; if (run == 5) { out[m++] = !in[i]; last = !in[i]; run = 1; } } return m; } /* 4. Worst-case frame bits for s data bytes, including the 3-bit gap: 135 for s = 8. */ static inline int frame_bits_worst(int s) { return 8*s + 47 + (34 + 8*s - 1) / 4; } /* 5. Worst-case wait of message i (messages sorted by identifier, lowest first). C[] and T[] are frame time and period in microseconds; bit_us is one bit. */ double worst_wait(int i, int n, const double *C, const double *T, double bit_us) { double B = 0, w, prev = -1; for (int k = i + 1; k < n; k++) if (C[k] > B) B = C[k]; /* one lower-priority frame in progress */ w = B; while (w != prev) { prev = w; w = B; for (int j = 0; j < i; j++) w += ceil((prev + bit_us) / T[j]) * C[j]; if (w > 1e7) return 1e30; /* bus overloaded: starved */ } return w + C[i]; }
Wherever a robot has many small controllers, CAN is likely to be there, and EtherCAT is likely to be there when many drives share one fast loop. CAN XL is the newer arrival for in-robot links; this lesson opened the CiA page for it and quotes only what that page says.
Opened for this lesson: the Kvaser CAN protocol tutorial and its bit timing page; TI application note SLOA101B; the TI TCAN1042-Q1 data sheet and the TCAN6062-Q1 product page; the CiA CAN XL page; the Wikipedia articles on CAN bus, CAN FD, CANopen, EtherCAT and Time-Sensitive Networking; ST’s STM32G4 HAL driver (the FDCAN header); and the EtherCAT Technology Group technology page. Not opened: ISO 11898-1, the Bosch CAN specification, the ETG specifications, SAE J1939, CiA 301 and CiA 402. The frame-time, bus-load, bit-timing and cycle-time models are this lesson’s own arithmetic on the numbers above, and each device says so.
Teach it back with the whiteboard prompts, or go back to the three senders at the top and push a node to bus-off again, this time knowing which wire to measure first.