# Clock Frequency of different node on CAN BUS



## WolfTronix (Feb 8, 2016)

The microcontroller clock speed does not matter, so long as they can divide it down to the CAN bus speed.

Typical CAN bus speeds are:
1Mbps
500kbps
250kbps
125kbps
etc...

All microcontrollers on the CAN bus network need to be set to the same CAN bus speed.

Hope that helps, 
Wolf


----------



## Lalit barawal (Aug 30, 2016)

Hi Wolf,

Thanks for answering this query..

You are saying all Micro Controller having same speed means All have same bit timing( sync phase + propagation+pahse1 + pahse2) ?????

Regards
Lalit


----------



## Kevin Sharpe (Jul 4, 2011)

Lalit barawal said:


> please explain me how CAN BUS system works mainly clock synchronization.


does this help?

https://en.wikipedia.org/wiki/CAN_bus


----------



## CKidder (Dec 12, 2009)

Lalit barawal said:


> Hi Wolf,
> 
> Thanks for answering this query..
> 
> ...


No, not exactly. Lets say you have two devices, one has a 4MHz processor, the other a 9MHz processor. You want both to run on a 250k CAN bus. So, for the 4MHz processor this means the processor clock is 16x the speed of the bus. For the second processor it is 36x the bus speed. Now, you need for both processors to end up at 250k. For the 4MHz processor you can probably figure out a set of bit timing values that directly works. My recollection about the valid values for each is a little fuzzy but 1+3+6+6 = 16 so I believe that would work for the 4MHz processor. You always need to have a combination between bit timing values and clock divisors that brings you to the target speed. For the 9Mhz you would need a divisor first. CAN hardware tends to have this capability. So, divide by some value. If you have a freely programmable divisor then 3 would be perfect. Now you're at 3MHz which is 12x the target bus speed. 1+2+5+4 would then give you the proper speed.

So, your bit timing values will change based on the processor speed but the end result is: (CPU Speed) / Divisor / (Total of bit times) = Bus speed.


----------



## WolfTronix (Feb 8, 2016)

High level CAN stuff:
http://ww1.microchip.com/downloads/en/DeviceDoc/adn004.pdf

Low Level CAN stuff:
http://ww1.microchip.com/downloads/en/AppNotes/00754.pdf


----------



## dcb (Dec 5, 2009)

specifics on timing and tolerance (oscillators aren't perfect, nor is the rest of the equipment)
http://www.nxp.com/files/microcontrollers/doc/app_note/AN1798.pdf

a fair number of variables. Examples given are from 0.5% to 1.25%


----------



## Lalit barawal (Aug 30, 2016)

Hi Wolf,

Thanks for sharing documents link..

I got a fare idea about timing of can node. 

But still i have one doubt ..
Document says same NBT(nominal bit time) for all node, which connected on CAN bus. And Prop segment , phase 1 and Phase 2 are depend on bus length and oscillator tolerance.

So i have an scenario 


Node 1 --------------Node 4--------------Node 3---------------- Node 2 


In this case node 1 and node 2 present at max distance . So prop delay is max in this case. Then How we set bit timing phase values (Prop delay, phase1, phase2) , These are according to max length for all node or these are according to length of every node respective to other node..

I have attached a image also please refer that image....


In this image Temp sensor 1 and temp sensor 2 are at max distance. Then bit timing (prop delay ) is max. Then For other node which have less distance then for these node we follow same ( prop delay , phase 1 , phase 2) bit timing or we set these according to distance of each node respective to each other.



Thanks & regards
Lalit


----------



## WolfTronix (Feb 8, 2016)

The Prop segment is for really long cable runs...

It looks like from your example that this is going in a vehicle, So I would just set them all in the middle of the range.

Then test with the Magic Packets:
Address: 0x3E0 Data: 0xF83E0F83E0F83E0F
Address: 0x01F Data: 0x07C1F07C1F07C1F0

Since bit stuffing happens after 5 consecutive bits, these are some worse case packets.

If those packets make it to and from the two farthest nodes, then you should be good. 

If not, then start making adjustments.


----------



## Lalit barawal (Aug 30, 2016)

Thanks wolf it works...


----------

