CAN arbitration and the frame on the wire
Bitwise, non-destructive arbitration: why the lowest identifier always wins; and what a real classical CAN frame looks like bit by bit, with CRC, stuff bits and the CAN_H/CAN_L differential voltages.
What it demonstrates
Bitwise, non-destructive arbitration: why the lowest identifier always wins; and what a real classical CAN frame looks like bit by bit, with CRC, stuff bits and the CAN_H/CAN_L differential voltages.
How it works
Three nodes start transmitting at the same instant. On each identifier bit, the bus level is the wired-AND of everything being sent: a dominant 0 overrides a recessive 1. A node that sends 1 but reads 0 stops transmitting and becomes a receiver.
The winning frame is built exactly as a classical CAN 2.0A data frame: SOF, 11-bit identifier, RTR, IDE, r0, DLC, data, a CRC-15 computed over those bits, then bit stuffing (a complementary bit after five equal bits), and the fixed delimiter, ACK, end-of-frame and intermission bits. The waveform maps each bit to typical high-speed CAN voltages. Optional common-mode noise is added equally to both wires, so the differential signal is unchanged.
Adjustable parameters
- Three 11-bit identifiers (hex)
- Payload per node (0–8 bytes hex)
- Common-mode noise on/off
- Bit rate (125k, 500k, 1M)
Known limitations
- Only identical-start arbitration on standard 11-bit data frames is shown; remote frames and extended-ID arbitration (SRR/IDE) are not animated.
- Voltages are idealised square levels: no rise time, ringing or propagation delay.
- The ACK slot is drawn as dominant, as it appears once at least one receiver has acknowledged.
Equations
Core update rule
for (let b = 0; b < 11; b++) {
const levels = ids.map((id, i) => (active[i] ? (id >> (10 - b)) & 1 : null));
const bus = levels.some((l) => l === 0) ? 0 : 1; // wired-AND
active = active.map((a, i) => a && levels[i] === bus); // sent 1, saw 0 → back off
}
// stuffing: after five equal bits insert the complement
if (run === 5) { out.push(1 - b); run = 1; }Explained in Chapter 5: Communication & Firmware