CAN network bit timing clarification

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN network bit timing clarification

Jump to solution
3,258 Views
Maciek
Contributor V

Hi,
I have problems with setting proper CAN baud rate for CAN network with baud rate approx. 65.83Kbit/s.

Please clarify the following points:

1. For default settings of S32K144 Devkit (XTAL freq. 8MHz, System Clock freq. 80MHz):
- setting "CAN Engine Clock Source" as 'Peripheral clock' -> gives CAN PE clock 80MHz
- setting "CAN Engine Clock Source" as 'Oscillator clock' -> gives CAN PE clock 8MHz
Is it true ?

2. Usually the 'nominal bit rate/nominal CAN baud rate' for CAN is calculated using the sum of 4 segments: Sync. segment, Propagation segment, Phase Segment 1 and Phase Segment 2.
Looking at the generated code for standard Bitrates like: 50Kbit/s, 100Kbit/s, 250Kbit/s - I've found that FCAN_Config block computes 'nominal bit time' as the sum of 5 segments: sync., propag., phase1, phase2 and RJW (resync. jump width). Why RJW is used in computing nominal bit time ? Or maybe I've misinterpreted something ?

3. Because calculated values for Prescaler Divider and Segments didn't work for me (there was no communication in 65.83Kbit/s network) - I've adjusted the bit length (nominal bit time) 'by hand' using oscilloscope.
I've set the following fields in the FCAN_Config block mask:
- clock source: 'Peripheral clock'
- Prescaler Divider: 75 (which gives Sclock = 80MHz/(75 + 1)
- Resync Jump Width: 2
- Phase Segment 1: 6
- Phase Segment 2: 5
- Propag. Segment: 1
(thus the full bit is 15TQ - including RJW into bit time)
And with these settings the S32K144-devkit successfully receives messages from the 65.83Kbit/s network. The problem is that from calculations the nominal bit length should be: (76 * 15)/80MHz = 14.25us.
But on the oscilloscope I see the actual bit length around 15.25us! This is a very big difference! Why do I see such length with these settings ? Maybe I don't understand the calculations behind the CAN baud rate ?
(I've checked all that on low-bandwidth Tektronix - but 1us difference is clearly visible; I will measure the difference with better oscilloscope/logic analyzer soon...)

Waiting for Your response
Maciek

Tags (1)
1 Solution
2,909 Views
paulvlase
NXP Employee
NXP Employee

Hi Maciek

1. Yes, that's true.

   'Peripheral clock' gives CAN PE clock of 80MHz
   'Oscillator clock' gives CAN PE clock of 8MHz


2. No, RJW is not used in the CAN nominal bitrate calculation.

You can see in Chapter 53.5.9.7 Protocol timing from the S32K RM, on page 1775, that nominal CAN bitrate is

pastedImage_5.png

where Tq (Time Quanta) is

pastedImage_6.png

and 1 CAN bit time is

pastedImage_7.png

CAN bit time = SYNC_SEG + (PROPSEG  + PSEG1 + 2) + (PSEG2 + 1)

RJW (Resync Jump Width) also called as SJW (Sync-Jump Width), is the maximum number of time quanta that a bit time can be changed by one resynchronization.

It allows a receiving CAN node to resync (increase PSEG1 duration / decrease PSEG2 duration up to RJW time quanta) to a receiving CAN frame that has a bitrate slightly faster or slower than that of the receiving CAN node.

I think that +2 constant from Time Segment 1 made you believe that RJW is used for nominal CAN bitrate calculation.

The values of bitfields PROPSEG, PSEG1, PSEG2, and RJW from CTRL1 register, which are the same ones from the CAN_Config block, are not used directly, instead in the FlexCAN hardware they are incremented by 1. As a result instead of

CAN bit time = SYNC_SEG + PROPSEG + PSEG1 + PSEG2 time quanta

it is

  CAN bit time = SYNC_SEG + (PROPSEG + 1) + (PSEG1 + 1) + (PSEG2 + 1) time quanta

3. Using these formula and the values from the CAN_Config block let's compute the CAN bitrate.

We have:

- tCANCLK (CAN PE clock): 80 MHz (Peripheral clock)
- PRESDIV (Prescaler Divider): 75

- PROPSEG (Propag. Segment): 1
- PSEG1 (Phase Segment 1): 6
- PSEG2 (Phase Segment 2): 5

Tq = (PRESDIV + 1 ) / tCANCLK = (75 + 1) / 80000000 = 0.00000095 s

CAN bit time = SYNC_SEG + (PROPSEG + 1) + (PSEG1 + 1) + (PSEG2 + 1) = 1 + (1 + 1) + (6 + 1) + (5 + 1) = 16 time quanta = 16 * 0.00000095 s = 0.0000152 s = 15.2 us

CAN bit rate = 1 / CAN bit time = 1 / 0.0000152 = 65789.47368421053 bit/s = 65.79 Kbit/s

These are almost the same values that you measured.

For the next release of S32K toolbox we'll compute and display the CAN PE clock, Tq and CAN bitrate when you configure the bitrate using the time segments. And maybe display the final incremented values of the time segments parameters.

Hope this helps,

Paul

View solution in original post

5 Replies
2,910 Views
paulvlase
NXP Employee
NXP Employee

Hi Maciek

1. Yes, that's true.

   'Peripheral clock' gives CAN PE clock of 80MHz
   'Oscillator clock' gives CAN PE clock of 8MHz


2. No, RJW is not used in the CAN nominal bitrate calculation.

You can see in Chapter 53.5.9.7 Protocol timing from the S32K RM, on page 1775, that nominal CAN bitrate is

pastedImage_5.png

where Tq (Time Quanta) is

pastedImage_6.png

and 1 CAN bit time is

pastedImage_7.png

CAN bit time = SYNC_SEG + (PROPSEG  + PSEG1 + 2) + (PSEG2 + 1)

RJW (Resync Jump Width) also called as SJW (Sync-Jump Width), is the maximum number of time quanta that a bit time can be changed by one resynchronization.

It allows a receiving CAN node to resync (increase PSEG1 duration / decrease PSEG2 duration up to RJW time quanta) to a receiving CAN frame that has a bitrate slightly faster or slower than that of the receiving CAN node.

I think that +2 constant from Time Segment 1 made you believe that RJW is used for nominal CAN bitrate calculation.

The values of bitfields PROPSEG, PSEG1, PSEG2, and RJW from CTRL1 register, which are the same ones from the CAN_Config block, are not used directly, instead in the FlexCAN hardware they are incremented by 1. As a result instead of

CAN bit time = SYNC_SEG + PROPSEG + PSEG1 + PSEG2 time quanta

it is

  CAN bit time = SYNC_SEG + (PROPSEG + 1) + (PSEG1 + 1) + (PSEG2 + 1) time quanta

3. Using these formula and the values from the CAN_Config block let's compute the CAN bitrate.

We have:

- tCANCLK (CAN PE clock): 80 MHz (Peripheral clock)
- PRESDIV (Prescaler Divider): 75

- PROPSEG (Propag. Segment): 1
- PSEG1 (Phase Segment 1): 6
- PSEG2 (Phase Segment 2): 5

Tq = (PRESDIV + 1 ) / tCANCLK = (75 + 1) / 80000000 = 0.00000095 s

CAN bit time = SYNC_SEG + (PROPSEG + 1) + (PSEG1 + 1) + (PSEG2 + 1) = 1 + (1 + 1) + (6 + 1) + (5 + 1) = 16 time quanta = 16 * 0.00000095 s = 0.0000152 s = 15.2 us

CAN bit rate = 1 / CAN bit time = 1 / 0.0000152 = 65789.47368421053 bit/s = 65.79 Kbit/s

These are almost the same values that you measured.

For the next release of S32K toolbox we'll compute and display the CAN PE clock, Tq and CAN bitrate when you configure the bitrate using the time segments. And maybe display the final incremented values of the time segments parameters.

Hope this helps,

Paul

2,909 Views
sparkee
Contributor V

Phenomenal answer, paulvlase‌.  Great to hear that the configuration is going to be more transparent in the next update.

0 Kudos
2,909 Views
dumitru-daniel_
NXP Employee
NXP Employee

paulvlase‌,

Can you have a look please ?

Thank you!

Daniel

0 Kudos
2,909 Views
sparkee
Contributor V

It says assumed answered at the top but I don't see any answers.  Did this ever get worked out??

Maciekdumitru-daniel.popapaulvlase

0 Kudos
2,909 Views
paulvlase
NXP Employee
NXP Employee

Hi sparkee‌,

I don't know why it is marked as assumed answered, possibly by mistake.

See my answer below.