CANbus formula for BRP, Stage1, and stage1

25 Views Asked by At

I was in the process of trying to set the frequency of CAN to 250khz on a SAMe70 microchip board and all the Atmel documentation was flat out wrong. I found a few others post about how their documentation leave a lot to be desired so working around with some of the example code and playing with the formula I was able to deduce how to set a up a specified freq. the formula that was coming across was desired bit rate = (clock freq)/(BRP +1) x(stg1+stg2+1). this was due to many believing that the plus one to the BRP was to account for the JW but that is incorrect and microchip studio either accounts for it or it isn't part of the equation. to successfully achieve a 250kHz bit rate signal I set my clock to 16MHz, had a BNP of 4 and stage one set to 10tq and stage 2 set to 5tq. the reason stage 1 should be about double stage 2 is to allow for proper signal error handling and time propagation. this is something I was toying with and other settings were able to get me to my desired bit rate but 2:1 is what I ended on.

we have this solved. For ISO 11898 use the formula: desired bit rate = (clock freq)/(BRP)x(stage1 + stage2 + 1)

no need to account for JW

1

There are 1 best solutions below

2
Lundin On

I pointed out this very bug to Microchip/Atmel many years ago but they don't like to fix bugs, apparently. See this: https://electronics.stackexchange.com/a/479411/6102. There's an example how to set baudrate based on the amount of tq and the desired sync point. It's for SAMC21 but I believe the CAN controller is about the same.

So the formula you are rather looking for is:

total_tq = sync_seg_tq + (phase_seg1_tq+1) + (phase_seg2_tq+1)

Where sync seg is always 1 and has nothing to do with SJW indeed.