CAN Bit Timing and Calculation
Vikesh Kumar Mishra
AUTOSAR BSW |CAN/CAN-FD|LIN|Ethernet SOME/IP|UDS| DCM | DEM| Comstack |Memstack| ADAS |Rte|RTOS| Automotive Cybersecurity| Vector/EB Stack | C/ C++| ISO26262|Embedded Software Developer|HackerRank 4 star problem solver
Bit timing is the count of time Quanta(tq, a basic unit of bit time) required to carry a single bit(I.e. tour of a bit on CAN bus from writing to reading) on CAN Bus. Reciprocal of Bit timing is known as Bit rate or Nominal bit rate.?c
As per CAN standard ISO11898, CAN supports bit-rate up to 1000 kbps. It all depends on the CAN network length. Bit rate can be configured individually for each CAN node connected on CAN network.
The oscillator frequencies of Nodes(ECUs) have some instability because of some environmental factors which can cause synchronization error but every Node is configured itself to maintain its bit synchronization by adjusting bit time if the frequency deviation is within its tolerance limit.
Keeping the attention at bit synchronization, a bit time is divided into 4 segments and each segment has some specific programmable number of time quanta(tq):
1. Synchronization Segment(Tsync_seg)
2. Propagation Segment(Tprop_seg)
3. Phase Segment 1(Tphase_seg1)
4. Phase Segment 2(Tphase_seg2)
Bit Time Components:
Nominal Bit Time = Tsync_seg+TSEG1+TSEG2
Where,
TSEG1 = Tprop_seg+Tphase_seg1
TSEG2 = Tphase_seg2
Tsync_seg = 1Tq
TSEG1 ,TSEG2?= N*tq(i.e. integral multiple of tq)
See the table for allowed values for each segment:
Time Quanta(Tq):
Time quanta(tq) is the basic unit of the bit time and its formula is tq=BRP/fsys
where,
BRP=Baud Rate Prescaler,
领英推荐
fsys =MCU system Clock(typically =Fosc)
Synchronization Segment:
Bit Rate Calculation Examples:
Q. Calculate Required Time Quanta to achieve 500kbps baud rate if the system clock is 40mhz and CAN clock divider is 4.
CAN clock(fcan)=40/4=10mhz
time Quanta(tq)=1/fcan=1/10=100ns
bit rate =500kbps
bit time=1/500kbps=2us
no of tq=2us/100ns=20tq.
Q. Configure TSEG1 and TSEG2 to set sampling at 80% of a bit time.
(Tsync_seg+TSEG1)/(Tsync_seg+TSEG1+TSEG2)=80%
as we calculated above: bit time = Tsync_seg+TSEG1+TSEG2=20tq
so , (1+TSEG1)/(20)=80%
TSEG1=16-1=15
so TSEG2=20-1-15=4
so final values are :
1. Tsync_seg = 1(fixed)
2. TSEG1 = 15
3. TSEG2 = 4
Hope it will help to configure the baud rate of can!