LPC2129 - Setting CAN Baud rate & Getting Errors

Started by "sie...@gmail.com [lpc2000]" May 21, 2014
Hi,

I'm trying to use CAN with some less-common baud rates but I'm not sure if my calculations are right. Crystal is 12MHz, using a 5x multiplier for a frequency of 60MHz. VPB divider is 1, so peripherals run at 60MHz.

I've tested 500kbps and 250kbps, but would like to add 33kbps, 95kbps and 125kbps. I tried setting these rates but it keeps throwing errors onto the network.

Good:
250 kbps: C2BTR = 0x3E000C;
500 kbps: C2BTR = 0x3E0005;

Giving errors:
33.3 kbps: C2BTR = 0x3E005A;
95 kbps: C2BTR = 0x3E0020;
125 kbps: C2BTR = 0x3E0018;

Is there a glaring error here? I know I'm not going to be able to nail the frequency 100%, but hope to come close enough.

Thanks!

An Engineer's Guide to the LPC2100 Series

> Hi,
>
> I'm trying to use CAN with some less-common baud rates but I'm not sure if
> my calculations are right. Crystal is 12MHz, using a 5x multiplier for a
> frequency of 60MHz. VPB divider is 1, so peripherals run at 60MHz.
>
> I've tested 500kbps and 250kbps, but would like to add 33kbps, 95kbps and
> 125kbps. I tried setting these rates but it keeps throwing errors onto the
> network.
>
> Good:
> 250 kbps: C2BTR = 0x3E000C;
> 500 kbps: C2BTR = 0x3E0005;
>
> Giving errors:
> 33.3 kbps: C2BTR = 0x3E005A;
> 95 kbps: C2BTR = 0x3E0020;
> 125 kbps: C2BTR = 0x3E0018;
>



We are using both CAN modules in the LPC1778 so I guess that the same CAN
IP module is used in the LPC2129.

The right settings depend on the bit quanta and the sample point you are
using . Normally the bit quanta vary in between 8 and 20 (some
are using up to 24). The sample point should be somewhere between 75 %
and 90 % of the bitquanta for good results. A spreadsheet will help you
to find out the right settings for the CAN bit timing register.
The input parameters are the pclk, the requested CAN bitrate and the
bitquanta.

Just a hint : I would not choose a very high pclk for the CAN bitrate
timing. You might not achieve a pretty low CAN bitrate result like 10 Kbt/s
or even 5 Kbit/s if you would like to apply them in the future.

Hope this will give you an idea.

Br,

Armand


Posted by: a...@mini-amd.org


Thanks Armand, I'll look into that. Unfortunately I'm locked into these baud rates because I want to work with existing systems.

Seems like I should back out the settings from the known-good bauds and then check the baud rate and use the same quanta. I had tried to do that awhile back, but need to make sure my calculations are right!
On 21.05.2014 19:44, s...@gmail.com [lpc2000] wrote:
> Good:
> 250 kbps: C2BTR = 0x3E000C;
> 500 kbps: C2BTR = 0x3E0005;

I get an impression, that you forgot that the clock is divided with BRP
+ 1. So BRP in 250kbps should be (60MHz / 250kHz / 20) - 1 (where 20 is
the number of clocks in a bit from the C2BTR). That gives 0x3E000B. I
don't know why 250kbps is good but 500kbps seems to be accurate whereas
the other rates seems to contain the error.

--

Timo


Posted by: Timo


Hello,

in addition to Armands post I would like to mention that you should
check first if
the time for one time quanta can be divided by the PCLK period,
without(!) fraction.
In your case you're using a number of 20 time quantas at a sample point
of 80%. Many
standards (CANopen or J1939) use sample points close to 87.5%. In our
systems we are
using the following setup:

0x002F0017, // 125 KBit/sec, 20 Tq, BRP = 24
0x002F000B, // 250 KBit/sec, 20 Tq, BRP = 12
0x002F0005, // 500 KBit/sec, 20 Tq, BRP = 6

Bitrates below 50 kBit/s are not possible with a CAN clock of 60 MHz,
because the
prescaler value is limited (BTW: please make sure that your CAN
transceiver can handle
bitrates below 50 kBit/s due to the "dominant bit timeout feature").

The bitrate 95 kBit/s is not possible with your settings, I calculated a
prescaler
value of 31.5789 (i.e. no fun at all for CAN to re-synchronize).
Best regards,
Uwe

---------------------------------
MicroControl GmbH & Co. KG
Lindlausstr. 2c, 53842 Troisdorf, Germany

Homepage: www.microcontrol.net
Facebook: www.facebook.com/MicroControl.net
Twitter : twitter.com/_microcontrol_
---------------------------------