50.7.4.1 CAN Bit Timing Configuration
All controllers on a CAN bus must have the same bit rate and bit length. At different clock frequencies of the individual controllers, the bit rate has to be adjusted by the time segments.
The CAN protocol specification partitions the nominal bit time into four different segments.
If the SMP field in the Baudrate register (CAN_BR) is set, then the incoming bit stream is sampled three times with a period of half a CAN clock period, centered on sample point.
In the CAN controller, the length of a bit on the CAN bus is determined by the parameters (BRP, PROPAG, PHASE1 and PHASE2).
The time quantum is calculated as follows:
To compensate for phase shifts between clock oscillators of different controllers on the bus, the CAN controller must resynchronize on any relevant signal edge of the current transmission. The resynchronization shortens or lengthens the bit time so that the position of the sample point is shifted with regard to the detected edge. The resynchronization jump width (SJW) defines the maximum of time by which a bit period may be shortened or lengthened by resynchronization.
Example of bit timing determination for CAN baudrate of 500 kbit/s:
fPeripheral clock = 48 MHz
CAN baudrate = 500 kbit/s => bit time = 2 μs
Delay of the bus driver: 50 ns
Delay of the receiver: 30 ns
Delay of the bus line (20 m): 110 ns
The total number of time quanta in a bit time must be comprised between 8 and 25. If we fix the bit time to 16 time quanta:
tCSC = 1 time quanta = bit time / 16 = 125 ns
=> BRP = (tCSC x fperipheral clock) - 1 = 5
The propagation segment time is equal to twice the sum of the signal’s propagation time on the bus line, the receiver delay and the output driver delay:
tPRS = 2 * (50+30+110) ns = 380 ns = 3 tCSC
=> PROPAG = tPRS/tCSC - 1 = 2
The remaining time for the two phase segments is:
tPHS1 + tPHS2 = bit time - tCSC - tPRS = (16 - 1 - 3)tCSC
tPHS1 + tPHS2 = 12 tCSC
Because this number is even, we choose tPHS2 = tPHS1 (else we would choose tPHS2 = tPHS1 + tCSC).
tPHS1 = tPHS2 = (12/2) tCSC = 6 tCSC
=> PHASE1 = PHASE2 = tPHS1/tCSC - 1 = 5
The resynchronization jump width must comprise between one tCSC and the minimum of four tCSC and tPHS1. We choose its maximum value:
tSJW = Min(4 tCSC,tPHS1) = 4 tCSC
=> SJW = tSJW/tCSC - 1 = 3
Finally: CAN_BR = 0x00053255