CAN Bit-time calculation playing a crucial role in CAN protocol for real-time implementation of a CAN bus since It is an asynchronous type serial bus. Generally, you will be having the basic knowledge that in synchronous data communication data measurement unit is the bit rate, and in the asynchronous data communication data rate measurement is baud rate. If you are new to these terminologies please go through my CAN tutorial to understand this. Since it is used in most of the embedded industry nowadays, it is very important to implement it correctly to get the error-free CAN bus to prevent data loss.

### Why CAN Bit Time Calculation Need?

To make this successful, the bit timing and synchronization of a CAN bus play an important role to ensure a better performance. A misplaced sampling point in a CAN network can lead to one of the transmitters going error passive state for a long period of time. The selection of right timing parameters requires a deep knowledge of CAN bit synchronization. And also it may lead to complexities owing to the number of input parameters & a variety of possible solutions. The CAN system engineer should choose the optimum Sampling Point and Time Quanta to ensure a robust CAN implementation in a vehicle CAN network. The CAN bit-time calculation will be easy and simple if you have a system-level knowledge on CAN protocol that you will get it from this article.

The main objective of this article is to provide you a simplified CAN bit time calculation. But before that let me explain to you some basic ideas about the CAN controller and all. Actually first the CAN protocol designed by Robot BOSCH and the patent is in the name of BOSCH. So if anyone wants to use the can they need to purchase the CAN controller. They don’t share what the real-time work implementation is done in that chip, they only share the application principle for their clients and customers. After that, the Processor chip manufacturer directly purchased the license from them to use it in their System On Chip (SoC) nothing but the microcontroller. So that instead of interfacing the standalone CAN controller with limited features, they can program the chip as per their requirement.

### Why You Should Give Priority on Bit Time Calculation?

The CAN bus is running with different baud rates so as per your requirement you need to set the baud rate for your CAN network if you want to use it in your vehicle or anywhere. To set the baud rate, you need to set the bit time in your CAN controller register after the completion of CAN bit time calculation. This is a primary parameter of any CAN bus. If you will not calculate the CAN Bit time with a proper specification, then the CAN network can also generate the continuous error frame which creates the CAN bus conflicts and so on CAN “**bus off**”. To prevent this, the proper investigation and analysis should be done for a CAN network to set the bit time. So why wait, let’s go discuss this and learn how to really calculate the bit time.

## CAN Bit Time Calculation Input Parameters

To calculate the bit time, the minimum required inputs parameters are:

- The desired baud rate for that CAN bus is very common across this network.
- Propagation delay defines the distance between the most distant nodes in a CAN network.
- CAN System clock frequency which is used to derive the bitstream sampling clock.

**CAN System Clock**

The CAN is having its own system clock on which it will work as nothing but the physical crystal oscillator connected to the CAN controller. The baud rate will get calculated from this crystal oscillator’s physical frequency. To ensure the zero error in CAN network, the Time quanta is required for CAN bit time calculation. So the time quanta are nothing but the smallest time value for a CAN controller which can be used to increase or decrease the time value of a bit time for soft synchronization or re-synchronization.

**CAN Baud Rate**

The baud rate is nothing but the real data rate which defines the data transmission rate for a particular CAN network. Basically, if you want to connect any ECU in a particular CAN network, you should know that CAN bus baud rate and it should be set in all the ECU’s going to be connected in that network. The baud rate will get calculated from the CAN system frequency. Because basically your network will run a maximum of 1mbps at 40-meter length as per ISO 11898-1 standard. But the microcontroller will run in higher frequency, so to calculate it you need to get the required frequency from the oscillator frequency by using the Baud Rate Pre-scaler method that we will discuss later below in CAN bit time calculation.

**CAN Propagation Delay**

The propagation delay is the main source of CAN bit time calculation. The propagation delay calculated from two main sources such as the speed of electromagnetic propagation along with the bus network or wiring and the extra delay due to the CAN transceivers, isolation, or other interface circuitry used in this network. Basically this is a time from when the Tx ECU Microcontroller will enable its Tx-interrupt of CAN controller -> Tx-Can transceiver -> Tx Isolator (optional) -> cable from Tx ECU to can bus -> can bus cable -> cable from can bus to Rx ECU -> Rx Isolator (optional) -> Rx can transceiver -> CAN Controller Rx interrupt to Rx ECU Microcontroller. This is the total time required for each bit to make a successful data transmission on a CAN bus. The integration of all these values and converting it into units of time quanta is nothing but the Propagation delay of that ECU.

**CAN Bit Time Structure**

The CAN-bit structure is nothing but the Nominal Bit Time (**NBT**). The Nominal Bit Time is derived from the Nominal Bit Rate (**NBR**) that is uniform throughout the network. The Nominal Bit Rate is nothing but the baud rate for a CAN network.

The NBT = 1/NBR

Where, NBT is Nominal Bit Time, and NBR is Nominal Bit or baud Rate. Once you will get the bit time from the bit or baud rate, it will be used to calculate how many number of time quanta required.

The CAN bit time is a combination of 4 segments such as:

- Synchronization Segment register (
**SYNC_SEG**). - Propagation Segment Register (
**PROP_SEG**). - PHASE BUFFER SEGMENT1 (
**PHASE_SEG1**). - PHASE BUFFER SEGMENT2 (
**PHASE_SEG2**).

tNBT = tSYNC_SEG + tPROP_SEG + tPHASE_SEG1 + tPHASE_SEG2

Where t is time

**Synchronization Segment (SYNC_SEG)**

The synchronization segment is the first segment of a nominal bit time and also the first segment in CAN bit time calculation register. This segment is used to synchronize all the ECU or nodes connected to the network. This segment is fixed at 1 Time quanta always. The beginning of each received bit is expected to occur in this segment. Because the CAN bus frequency is nothing but the baud rate which is different from the physical oscillator frequency and the propagation delay changes due to the CAN bus length in between the transmitter and receiver node by which the bit might be received before or after the synchronization segment. This is called the Phase angle error in CAN protocol. Phase Error is divided into two types of synchronization such as Hard synchronization and Soft synchronization nothing but the re-synchronization. tSYNC_SEG = 1 Tq is fixed.

**CAN Hard synchronization**

The Hard synchronization will occur at every recessive to the dominant edge of the Start Of Frame (SOF field of CAN data frame) after the Idle period or the intermission field period of can bus.

**CAN Re-Synchronization**

The re-synchronization occurs during the whole whenever a recessive to the dominant edge is detected after the synchronization segment. The re-synchronization will be achieved by lengthening of **PHASE_SEG1 **or shortening of **PHASE_SEG2 **during the message reception of each CAN controller available in ECU microcontroller.

**Propagation Segment (PROP_SEG):**

The propagation segment register is nothing but the propagation delay time in a number of time quanta. It includes the can bus cable physical delay time and the internal delay times of CAN nodes or ECU. The propagation segment can be programmable from 1 to 8-time quanta (Tq).

=tPROP_SEGtTx(Tx-Can Driver + T isolator + T transceiver) +tBus(T BusPropagation) +tRx(T transceiver + T isolator + Rx-Can Driver)CAN Controller or Driver = 50 to 75 ns bus delay.

CAN twisted-pair cable transmission line propagation delay = 5ns/meter.

And the maximum un-terminated stub length for a network is 1/3rd of the critical length is = 5/3 m = 1.67 meter.

Digital isolator = 10 – 140 ns for an optocoupler (Need to select the right value from the chip design document).

CAN transceiver = 100 – 250 ns (Need to select the right value from the chip design document).

Generally we can not give a 100% formula to calculate a propagation delay. Because there are different ECU design manufacturers including the Automotive vehicle manufacturer and Tier1 suppliers, so they have their own design to provide an optimum CAN bus design to reduce the bus failure. So they will be having their own calculation. So i will suggest please follow their ECU design document to calculate the propagation delay time.

First, blindly calculate the time to ensure the correct sampling of bit values is:

tPROP_SEG=tProp(A,B) +tProp(B,A)If both the nodes are in the opposite side of the CAN bus then, tPROP_SEG = 2(tBus + tTx + tRx)

After this, you need to compare the total propagation time with the multiplication of the number of time quanta, if it is not matching then you need to round up it. PROP_SEG = RoundUp(tPROP_SEG /TQ)

But basically you can consider this formula for most of projects as: tProp(A,B) = tTx(A) + tBus(A,B) + tRx(B)

Where the A and B represent the distance between the Transmitter and receiver distance.

**PHASE BUFFER SEGMENT 1 and PHASE BUFFER SEGMENT 2**

These two segments are basically used for lengthening or shortening of bit time for re-synchronization. The time quanta selection for PHASE_SEG1 depends on the samples per bit. The **PHASE_SEG1 **will be 1 to 8-time quanta if one sample per bit has been selected and 2 to 8-time quanta if three samples per bit selected. If you have selected the 3 samples per bit then the most frequent sample value will be taken as bit value. The Phase Buffer Segment-2 must be equal to Phase Segment Buffer-1 in most of the cases, if not the Phase segment Buffer-2 must be equal to Information Processing Time (IPT) and the Phase Buffer segment Buffer-1 will be less than the Information Processing Time.

tSEG1 = tPROP_SEG + tPHASE_SEG1

tSEG2 = tPHASE_SEG2

**Information Processing Time (IPT)**

The information processing time is the time required CAN bit time calculation phase segment logic to determine the bit level of a sampled bit. The information processing time always starts at the sampling point and it also should not be less than the minimum value of PHASE_SEG2. The Information processing time is mostly always 2-time quanta but sometimes it changes as per the CAN controller SoC design like as for:

TOUCAN Module:The IPT = 3 TQ if the Baud Rate Prescaler = 1 ( Where the MCU system clock equals CAN system clock.)

MCAN Module:The IPT = 3 TQ if 3 samples per bit are selected.IPT = 2TQ = PS2min

SEGMENT | DURATION | MIN DURATION | MAX DURATION |
---|---|---|---|

SYNC_SEG | tSYNC_SEG = 1TQ | 1 Tq | 1 Tq |

PROP_SEG | tPROP_SEG = 1,2…8TQ | 1 Tq | 8 Tq |

PHASE_SEG1 | tPHASE_SEG1= 1,2…8TQ | 1 Tq | 8 Tq |

PHASE_SEG2 | tPHASE_SEG2= Max(IPT or tPHASE_SEG1) | 2 Tq | 8 Tq |

Total Time Quanta (Tq) | 5 Tq | 25 Tq |

**CAN Bit Time Quanta table**

From the above table, we concluded that the minimum number of time quanta per bit is 5. But mostly all the CAN controllers are designed, so the time quanta should be 8 to 25 for a bit.

**CAN Bit time Calculation Sampling Point **

The sampling point is a point of CAN bit time in between the PHASE_SEG1 and PHASE_SEG2. Basically it is measured in percentage. Let me explain to you with a real-time example as suppose the sampling point is 75%, then remaining is 100-75 = 25%. That means if there is any bit time error that will occur at run time, then there is a possibility is to increase or decrease the PHASE_SEG1 and PHASE_SEG2 value in terms of units of time quanta. So that the total time quanta are 20 is 100%, then the 25% is nothing but the maximum of 5-time quanta can be increased or decrease to adjust the bit time by using the **RJW **or **SJW **register available in the CAN network.

Sampling Point in %= (((SYNC_SEG + PHASE_SEG1) /(SYNC_SEG + PHASE_SEG1+PHASE_SEG2)) x100)

**CAN Crystal Oscillator Tolerance**

The Bit time of a CAN system is calculated from the Physical crystal oscillator. Since all the ECU is not designed by using the same crystal or purchased from the same supplier or due to so many reasons you can not give any guarantee that using all the ECU from different vendors will provide you the same oscillator tolerance. Due to which there might be a phase-shifting and oscillator drift that will occur between the CAN nodes. Because you are not using an ideal oscillator between the nodes. As per the CAN specification, the Oscillator Tolerance should be 1.58% in the worst case for a right CAN bit time calculation.

If you are thinking to implement a CAN network for your product like Vehicle or Avionics field. Even where the more nodes are connected in a network, then it is not so easy to calculate the bit time. Then the oscillator tolerance how you are thinking like to do it in your Engineering project based on CAN. You need to do it in a way as a professional CAN engineer in the CAN research and development department.

To calculate the oscillator tolerance, there are two standards for two different physical consecutive bit synchronization:

- When there is no re-synchronization during any error condition for correct evaluation of 13 dominant bits.
**Oscillator Tolerance1 = Df <= min(PHASE_SEG1,PHASE_SEG2)/(2x13x(NBT-PHASE_SEG2))** - When there is a full resynchronization after 10 consecutive bits is:
**Oscillator Tolerance1**= Df <= (SJW / (2X10XNBT))

Where Df deviates frequency and Factor 2 is multiplied in both formulas. Because two ECU having two crystal oscillators as transmitter and receiver ECU are connected which is having the worst-case error in opposite directions.

**CAN Bit Time Calculation Output Parameters**

The Bit time value must provide the 5 parameters or you can say that once you have the bit time for a CAN bus then you need to calculate the below 5 parameters for the setting of bit time in any microcontroller having CAN controller feature.

**Baud Rate Prescaler (BRP):**it is like PLL in a microcontroller to set your CAN baud rate nothing but the sampling period.**Propagation Delay Time Quanta:**It is used to calculate the Propagation segment. And then it should be calculated how many numbers of times quanta required for it.**Length of PHASE_SEG1 in a number of time quanta (TQ):**The**PHASE_SEG1**acts as a Tq buffer that can be lengthened to re-synchronize the bit time, if there is a change at run time.**Length of PHASE_SEG2 in a number of time quanta (TQ):**The**PHASE_SEG2 is a**lso acting as a Tq buffer that can be shortened to re-synchronize the bit time like**PHASE_SEG1.**But it occurs after the sampling point instead of before like PHASE_SEG1.**Synchronization Jump Width (SJW) in the number of Time Quanta**: This is the maximum time that can be used to lengthen or shorten the CAN bit time if there is any change of bit time in between the Transmitter and Receiver ECU.

**How to Calculate the CAN bit time for a CAN bus**

If you are working in any company or for any purpose you want to calculate the CAN bit time, then the below steps should be followed to calculate the bit time to determine the optimum bit sampling.

**STEP1:** Determine the minimum time for Propagation Segment. Calculate the maximum propagation delay time for transmitter and receiver node from the manufacturer datasheet and calculate the CAN bus delay by multiplying the maximum length of the bus cable. Then calculate the total propagation delay formula.

**STEP2:** Select the Baud Rate for your CAN bus. This will be derived from the Microcontroller crystal oscillator with Baud Rate Pre-scaler. After selecting a baud rate you can calculate the Nominal Bit Time (NBT) which is an integer number of time quanta (TQ) derived from the microcontroller system clock frequency. This value can vary from 8 to 25 times quanta per bit.

**STEP3:** Propagation Segment value need for CAN bit time calculation. From **STEP1, **check either the time quanta is less than or equal to 8, if yes then no need to recalculate it. But if it is more than 8 then you need to go back to **STEP2, **to recalculate it by reducing the baud rate that you can not use more data rate in your CAN system as per your system design. If I will explain everything here with more research levels, then it will be very difficult to do it here. Better you guys can ask your doubt in the comment box or else also if you have more doubt you can ask it on our Pi-Forum website.

**STEP4:** Calculate **PHASE_SEG1** & **PHASE_SEG2**. You need to get the number of Time Quanta calculated in **STEP2**. Then subtract it from the **PROP_SEG **which has been calculated in **STEP3 **and one Time Quanta for **SYNC_SEG**, if the remaining Time Quanta is less than 3 then you need to go back to **STEP2 **and select a higher system clock frequency. If more than 3 and has an odd number then add one Tq to Propagation Segment value and recalculate. If again the value is 3 then select **PHASE_SEG1 **= 1Tq & **PHASE_SEG2 **= 2Tq. Or else you can also divide the remaining number by 2 and assign this value to **PHASE_SEG1 **and **PHASE_SEG2**. The **PHASE_SEG1** and **PHASE_SEG2** will help in CAN bit time calculation to set the sample point.

tPHASE_SEG = NBT – (PROP_SEG +SYNC_SEG)

**STEP5**: Calculate the Re-synchronization Jump Width (**SJW**). The number of Time Quanta for SJW should be always less than the 4 and PHASE_SEG1 value.

SJW < PHASE_SEG1 and 4

**STEP6**: Calculate Oscillator Tolerance. I have already explained this above with formula, so you need to use this to get the Oscillator tolerance value.

- If The
**PHASE_SEG1**> 4*TQ, then you need to repeat the steps from 2 to 6 with a larger Prescaler value to get the smaller Time Quanta value. This will result in a reduction of oscillator tolerance. - If The
**PHASE_SEG1**< 4*TQ, then you need to repeat the steps from 2 to 6 with a smaller Pre-scaler value to get the larger Time Quanta value to reduce the oscillator tolerance. - If the Pre-scaler value is 1 and still the oscillator tolerance reduction is required, then there is only a single option to take a higher frequency for the pre-scaler clock source.

I hope now you got the idea and technical system-level knowledge for the CAN bit time calculation. So let’s go take an example of a Microcontroller having a chip CAN controller. And then you can calculate the CAN bit time for this.

**Example of CAN Bit Time Calculation:**

Suppose you are working in an MNC automotive company as a CAN System Engineer and you need to calculate the CAN bit time for a particular CAN bus. The following input parameters as input for you from the system design document is:

```
The Parameters will be input for you to start the CAN Bit Time Calculation
CAN baud Rate = 1 Mbps
CAN bus length = 20 meter.
CAN bus propagation delay = (bus length x propagation delay/meter) = 20x5 =100 ns
Can Transceiver Delay as per the document = 150ns at 85C
CAN System Physical Oscillator Frequency = 8 MHZ.
So from the above input parameters, you need to calculate the bit time for your CAN bus. Here we will just use the simple and basic
```

STEP1:Propagation Delay is:

tPROP_SEG= 2(100ns + 150ns) = 500ns

STEP2:CAN BaudRate = 1mbps, System Frequency = 8 MHZTq = 2 x (

BRP+ 1) / Fosc = 125ns at BRP of 1NBT = 1000/125 = 8 Tq

STEP3: Propagation Segment=RoundUp(Propagation Delay/NBT)=(500ns/125ns)= 4

RoundUp is optional, if it is not equivalent to the number of time quanta, then you can use this.

STEP4: tPHASE_SEG=NBT– (PROP_SEG+SYNC_SEG) = 8 – (4-1) =3

PHASE_SEG1= 1 andPHASE_SEG2= 2

STEP5: SJW = 1

STEP6:Oscillator Tolerance is:Oscillator Tolerance1 in % = (SJW/(2x10xNBT))x100 = (1/(20X8))x100 = 0.00625 = 0.625%

Df <= min(

PHASE_SEG1,PHASE_SEG2)/(2x13x(NBT–PHASE_SEG2))Since here

PHASE_SEG1= 1 andPHASE_SEG2= 2, hence we will considerPHASE_SEG1as the lowest value.Oscillator Tolerance2 = (1/2x13x(8-2))x100 = 0.00490×100 = 0.49%

The Oscillator Tolerance-2 is less than Oscillator Tolerance-1, so we will consider Oscillator Tolerance-1

#### CAN Bit Time Calculation Parameter to set the baud rate in CAN Controller

After the calculation of bit time, you will have the below parameters to which you need to set or program it for your microcontroller to get the 1Mbps data rate.

Prescaler = 1

Nominal Bit Time = 8

PROP_SEG = 4

PHASE_SEG1 = 1

PHASE_SEG2 = 2

SJW = 1

Oscillator tolerance = 0.49%

Simple points should remember before calculating the CAN bit time:

- The clock Baud Rate Pre-scaler (
**BRP**) value. - Choose the number of Time Quanta before the sampling point.
- Then select the number of Time Quanta after the sampling point.
- Choose the number of Time Quanta for the Synchronization Jump Width (SJW).

I hope you will able to calculate the CAN bit time after completion of this tutorial. Actually, if I will write like this it will not end. There are so many things that you should know. But there are so many people having there own needs like some basic and straight forward logic. There are some people who want deep knowledge of that. To keep in mind I have tried my best to write it in a way so that all the people will able to understand. I would also like to request you that if you are getting any benefit in your career development from this article, please give your comments and suggest how to improve this. Bets Of Luck…