System clock and CAN communication reliability
2 posters
Page 1 of 1
System clock and CAN communication reliability
Hello there,
Microchip dsPIC30F4012 was chosen for our application. According to its reference design, we used 7.3728 MHz crystal to generate system clock 29.4912 MHz. I noticed that UART communication works reliably, while CAN communication does not. Can you explain why and advise any suggestion?
Thanks.
Microchip dsPIC30F4012 was chosen for our application. According to its reference design, we used 7.3728 MHz crystal to generate system clock 29.4912 MHz. I noticed that UART communication works reliably, while CAN communication does not. Can you explain why and advise any suggestion?
Thanks.
lyh8- Posts : 14
Join date : 2008-08-25
Re: System clock and CAN communication reliability
Hi there,
You shall select a crystal or oscillator frequency so that the baud rate of the serial communication is precise enough. With your system clock 29.4912 MHz, you can generate pretty precise UART baud rate, for example, if your UART baud rate is 115200 bps, the UART baud rate generator setting can be calculated with the following equation
UxBRG = Fcy / (16 x Baudrate) – 1 = 29491200 / (16 x 115200) – 1 = 15
On the other hand, CAN communication is less tolerant than UART in terms of baud rate discrepancy. CAN baud rates are usually 125 kbps, 250 kbps, 500 kbps, and 1000 kbps. Each bit length is made up of integer units of time quanta (Tq), which is calculated with the equation below, supposing the prescale BRP = 2.
Tq = 2 x (BRP + 1) x Tcan = 2 x (2 + 1) x 1/29491200 = 203 ns
Now, suppose you want baud rate to be 250 kbps, i.e., 4000 ns bit length, the number of Tq of each bit would be 4000 / 203 = 19.7. Then if you choose 20 Tq for each bit, you end up with 246 kbps baud rate, with discrepancy = (250 – 246) / 250 = 1.6%, which caused the CAN communication reliability issue. To favor CAN communication, you’d better choose a crystal value to ensure CAN baud rate discrepancy within 1%; such values would be 7.5 MHz, 10 MHz, etc. UART can tolerate baud rate discrepancy up to around 3%. Good luck.
You shall select a crystal or oscillator frequency so that the baud rate of the serial communication is precise enough. With your system clock 29.4912 MHz, you can generate pretty precise UART baud rate, for example, if your UART baud rate is 115200 bps, the UART baud rate generator setting can be calculated with the following equation
UxBRG = Fcy / (16 x Baudrate) – 1 = 29491200 / (16 x 115200) – 1 = 15
On the other hand, CAN communication is less tolerant than UART in terms of baud rate discrepancy. CAN baud rates are usually 125 kbps, 250 kbps, 500 kbps, and 1000 kbps. Each bit length is made up of integer units of time quanta (Tq), which is calculated with the equation below, supposing the prescale BRP = 2.
Tq = 2 x (BRP + 1) x Tcan = 2 x (2 + 1) x 1/29491200 = 203 ns
Now, suppose you want baud rate to be 250 kbps, i.e., 4000 ns bit length, the number of Tq of each bit would be 4000 / 203 = 19.7. Then if you choose 20 Tq for each bit, you end up with 246 kbps baud rate, with discrepancy = (250 – 246) / 250 = 1.6%, which caused the CAN communication reliability issue. To favor CAN communication, you’d better choose a crystal value to ensure CAN baud rate discrepancy within 1%; such values would be 7.5 MHz, 10 MHz, etc. UART can tolerate baud rate discrepancy up to around 3%. Good luck.
lzmind- Posts : 18
Join date : 2008-08-20
Re: System clock and CAN communication reliability
Thank you for your great advice, lzmind.
First, we changed to 10MHz crystal, and both CAN and UART worked reliably. However, with 10 MHz crystal, the system clock can only be 20 MHz.
Second, in order to achieve max system clock, we changed to 7.5 MHz oscillator, because it is hard to find a 7.5 MHz crystal, and it turned out to be perfect solution, we achieved 30 MHz system clock, as well as reliable CAN and UART communication.
Thank you very much again for your advice.
First, we changed to 10MHz crystal, and both CAN and UART worked reliably. However, with 10 MHz crystal, the system clock can only be 20 MHz.
Second, in order to achieve max system clock, we changed to 7.5 MHz oscillator, because it is hard to find a 7.5 MHz crystal, and it turned out to be perfect solution, we achieved 30 MHz system clock, as well as reliable CAN and UART communication.
Thank you very much again for your advice.
lyh8- Posts : 14
Join date : 2008-08-25
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|