LPC11Cxx CAN baud rate calculation?

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

LPC11Cxx CAN baud rate calculation?

2,706 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kty-tty on Fri Jan 27 02:57:39 MST 2012
Hi,
I have a 12MHz crystal on an LPC11C12, and I am trying to initialise the C_CAN for 1MHz.
I am having trouble with the bit timing initialisation. I can't find the PROP_SEG value or register!!
As you know the CAN bit timing is broken into 4 segments, and the baud rate is the inverse of the sum of each of them ie f=1/(tsync + tprop+tph1+tph2). Without the prop term how do i work this out?
ie can someone please help me with the BT register settings for 1MHz from a 12MHz crystal?

I have tried to reverse engineer the settings from the sample codes to work out what the PROP_SEG value is if it is fixed but am not having any luck. I am also new to CAN so would like some guidance on positioning of the thp1/tph2.
Any help appreciated.

Also, I have very low power requirements I am trying to meet so cannot just change the PLL for 48MHz. If worst comes to worst I might change it for 16MHz, but i would rather not!
0 Kudos
17 Replies

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 10 12:54:21 MST 2012

Quote:
I have global networks of 1000 or 2000 nodes . I divide this network in CAN sub-networks of 250 nodes.

#1 Dividing to 120 or 125 nodes would give you the opportunity to use CANopen with LPC11Cxx.

#2 This separate 120 node BUS could be managed by 1 LPC17xx Gateway (CAN1 connected to 120 node BUS, CAN2 connected to Gateway BUS). This Gateway could do all the dump stuff like heartbeat :)

#3 Master is connected to Gateway BUS and transmitting / receiving compressed data.

Advantages:[INDENT][LEFT] #1 BUS problems don't disturb all nodes, just 120. Troubleshooting in modular design is much easier ;)

#2 A lot of traffic is limited in Node BUS (especially heartbeat).

#3 To add 120 nodes you just add a new gateway.

#4 CANopen supported nodes. So there's enough Flash left to use a nice little colored Touchscreen TFT instead of old fashioned Buttons :D

#5 Node BUS can be separated from Gateway to update software via CANopen.

#6 Gates and Master could use a different system to communicate (485, Ethernet) [/LEFT]
[/INDENT]Disadvantages:[INDENT] #1 Three different hardwares: Node, Gate, Master :([/INDENT]
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by roger.esoft on Fri Feb 10 03:13:50 MST 2012
I see you are experienced working with CAN, but I'm not. This is the first time.

Quote: Zero

Don't know what traffic your nodes are producing and how your 'repeater' work, also I don't know what you've tried already.



Here I give you more detailed info :).
I  have global networks of 1000 or 2000 nodes . I divide this network in  CAN sub-networks of 250 nodes. Our nodes are formed with one LCD and 4  pushbuttons. All nodes are connected in a daisy chain method making a  ring that starts and finish at the master. When a pushbutton is pressed  on the node the master needs to collect it. These nodes are allways  waiting info from the master, the master can send 35 characters for the  LCD and normally the master will have to refresh the LCD characters of a  20 nodes on no more than 300ms every 5 seconds. The master need to know  if a node is disconected or is duplicated in no more than 3 seconds.  I  install this devices arround factorys on a longer

I started at 250kps, and I finally moved to 125kbps. I tried sending  3 message types. Heartbeat, setmem and getmem. Every 10ms I do a  heartbeat to 1 node, rest of time is for pushbuttons events and posible  data transfer to nodes. This works great and fast.

My goal was  to achieve this values but with a easy installation guidelines for any  people. Related to delay problems I get a little scared of using CAN.


Quote: Zero

Don't know who of 'we' decided and who of 'we' has to do the work and to pay the price, but anyway, that's not my problem :)



For shure, feel free to say what you think. It's my decision and my problem :)


Quote: Zero

Or just switch off Message-Acknowledging with test mode and use a simple protocol to acknowledge are worth to think about,



I thinked on this, but this resolves ACK problem due to delay but not  the arbitration problem. Arbitration must be guaranteed if event want to  be catch.
To get a fast response at 125kps I thought on events,  pushbutton events. (Pooling all nodes for pushbutton values could be too  slow). But if there is no arbitration guaranteed what could happen with  these events.
What could happen If 2 nodes want to talk and the 2 get the access to the bus?
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 09 13:39:50 MST 2012

Quote:
3. All this questions were becouse we were planing to migrate to RS485.
5. Yesterday we started migrating to RS485.

I'm confused :confused: So this is an academic discussion here?


Quote:

4. The problems began trying to assume the total lenght using 125kbps for 250 nodes in a daisy chain CANbus network. At first we thoutgh that CANBus is useful for it's price $$, improvements vs RS485 and all of those freatures that allows to update the firmware using CAN... But at last we see problems on the instalation of the devices. We think that It's more easy to have a timeout for the node answer (RS485) than beeing carefully of how do you install your devices for preventing more delays.
Today we hear about Canbus and think on small networks. Big networks requires too slow data rates.

Don't know what traffic your nodes are producing and how your 'repeater' work, also I don't know what you've tried already.
Without further information it's just a (useless) guessing game :rolleyes:
Don't know who of 'we' decided and who of 'we' has to do the work and to pay the price, but anyway, that's not my problem :)
I've left RS485 world in 1995 and would always use CAN (what a surprise).
Using 2 CANOPEN BUS systems with 127 nodes connected via CAN-Gateway or even upgrade to 100Mbit Ethernet Gateway could reduce a lot of problems.
Or just switch off Message-Acknowledging with test mode and use a simple protocol to acknowledge are worth to think about,
but probably someone of 'we' has done that already with estimating project time / budget and member potential.


Quote:
What do you think about my reasons?

If you feel more confident with RS485, use it. Or something else ;)
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by roger.esoft on Thu Feb 09 10:01:01 MST 2012
1. Thanks for your reply.
2. Those parameters seems to work good.
3. I'm not starting the project. I've developed the interface, the nodes and at last we were trying to develope the repeater in Canbus. I'm using LPC11C12 in my nodes and LPC1758 in my interface.
3. All this questions were becouse we were planing to migrate to RS485.
4. The problems began trying to assume the total lenght using 125kbps for 250 nodes in a daisy chain CANbus network. At first we thoutgh that CANBus is useful for it's price $$, improvements vs RS485 and all of those freatures that allows to update the firmware using CAN... But at last we see problems on the instalation of the devices. We think that It's more easy to have a timeout for the node answer (RS485) than beeing carefully of how do you install your devices for preventing more delays.
Today we hear about Canbus and think on small networks. Big networks requires too slow data rates.
5. Yesterday we started migrating to RS485.

What do you think about my reasons?
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Feb 08 10:52:32 MST 2012
I don't know anything about your system requirements and traffic requirements. But I would always prefer CAN :)
It's a little bit more complicated to start, but chips like LPC11Cxx are supporting you with a few ROM CANOPEN functions and they can even be programmed via CAN.
How do you update your firmware? Running to 250 nodes?
I know you are living in Spain and probably damned cold weather isn't a problem, but in good old cold Germany I prefer to update my nodes via CAN.

I'm not sure if 250 nodes will work at 500m, but with 2 simple LPC11C24 boards it shouldn't be too difficult to start and make a few tests.

With a nice late sample point I would start with a standard setup :rolleyes:

Freq (MHz)    48           
CLKDIV    2
NT    8           
Baudrate    1,25E+005           
Sample Point>    85%           
SJW    2           

Result:               
BRP    24           
TSEG1    6           
TSEG2    1           
Sample Point    87,5%           
Register: BTR    0x0557           

or

Freq (MHz)    24           
CLKDIV    1
NT    8           
Baudrate    1,25E+005           
Sample Point>    85%           
SJW    2           

Result:               
BRP    24           
TSEG1    6           
TSEG2    1           
Sample Point    87,5%           
Register: BTR    0x0557
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by roger.esoft on Wed Feb 08 09:23:28 MST 2012
[FONT=Verdana][SIZE=2]Thanks zero, but I'm a little confused. Last three days I started thinking on changing to RS485 because oft the problems involved on syncronitzation of CAN. I'm not shure my system could work using CANbus. What do you think?

We are not shure about my last calculations. Can you help me to get the best configuration?

I've have been developing a system including CAN comunication to operate with devices at a 125kbps with 250 nodes max. Our goal was to achieve the lenght of 500m between 2 nodes as we seen that's the max. for CANopen protocol.

So, [/SIZE][/FONT][FONT=Verdana][SIZE=2]those are my inputs:[/SIZE][/FONT]
[COLOR=Blue][FONT=&quot]
[/FONT][FONT=&quot]Transceiver = TJA1050 assumed 245ns input/output delay[/FONT]
[FONT=&quot]CAN bus length = tbus = 500 m, with 5 ns/m signal delay time.
[/FONT][FONT=&quot]Tprop = 2*(tbus+tcmp+tdrv) = 6000ns[/FONT]
[/COLOR][FONT=Verdana][SIZE=2][COLOR=Blue]Clock imput (48MHz or 24MHz)[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2]
[FONT=&quot]TSEG1 = [B]?[COLOR=red][/COLOR][/B]
TSEG2 = ?
SJW_p = ?[/FONT][FONT=&quot]

[/FONT][/SIZE][/FONT][FONT=Verdana][SIZE=2]I'll repeat these calculations with the repeater delay.[/SIZE][/FONT][FONT=Verdana][SIZE=2][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][FONT=&quot] [/FONT]Thanks for everything[/SIZE][/FONT]
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Feb 05 14:19:16 MST 2012

Quote: roger.esoft
[FONT=Verdana][SIZE=2]I would like to know if TSEG1 register includes the TPROP_SEG value. [/SIZE][/FONT]



Of course, where else should it be included :rolleyes:


Quote:

5. Configuration of the CAN Protocol Controller

In most CAN implementations, the bit timing configuration is programmed in two register bytes. The sum of Prop_Seg and Phase_Seg1 (as TSEG1) is combined with Phase_Seg2 (as TSEG2) in one register, SJW and BRP are combined in the other register (see Figure 5).

See: http://www.port.de/pdf/CAN_Bit_Timing.pdf

or

Quote:

4.10.5 Configuration of the CAN Protocol Controller

In most CAN implementations and also in the C_CAN, the bit timing configuration is programmed in two register bytes. The sum of Prop_Seg and Phase_Seg1 (as TSEG1) is combined with Phase_Seg2 (as TSEG2) in one byte, SJW and BRP are combined in the other byte (see figure 16).

See: http://www.silabs.com/Support%20Documents/TechnicalDocs/Bosch_CAN_Users_Guide.pdf
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by roger.esoft on Sun Feb 05 09:34:26 MST 2012
[FONT=Verdana][SIZE=2]Hi,

[/SIZE][/FONT][FONT=Verdana][SIZE=2]I'm trying to configurate the Canbus bit timing too, and I've the same question. I would like to know if TSEG1 register includes the TPROP_SEG value.

I'm trying to adjust the controller to my system requirements, where length is the most important thing. I'm using this configuration:[/SIZE][/FONT]

[FONT=&quot]System clock f_sys = 48 MHz.
System clock period t_sys = 1/f_sys = 20,833333 ns.[/FONT]
  [FONT=&quot]Bit rate prescaler (BRP) =16
CAN time quantum [B]tq = t_sys*16 = 333,3333ns[/B] (at [B]BRP = 16[/B])[/FONT]
  [FONT=&quot]El nº de timequanta ha d’estar entre [B]8..25[/B].[/FONT]
[FONT=&quot]
[/FONT]
  [FONT=&quot]Desired bit rate is 125 KBit/s, desired bit time is thus 8000 ns.
Actual bit time = [B]24[/B] tq = 7999,992 ns
Actual bit rate is [B]125,125[/B] KBit/s[/FONT]
  [FONT=&quot]
[/FONT]
[FONT=&quot]CAN bus length = 550 m, with 5 ns/m signal delay time.[/FONT]
[FONT=&quot]My transceiver loop delay = 245ns
[/FONT]
[FONT=&quot] Propagation delay time : 2*transceiver loop delay + bus line delay = 3000 ns
(maximum loop delay between CAN nodes)[/FONT]
[FONT=&quot]
[/FONT]
  [FONT=&quot]Each bit transmitted on a CAN network has 4 segments (Sync_Seg, Prop_Seg,Phase_Seg1, and Phase_Seg2). The sum of these segments determines the CAN bit time (1/bit rate).
[/FONT]
[FONT=&quot]
[/FONT]
  [FONT=&quot]Prop_Seg = 10 tq = [B]3333,333 ns[/B] ( >= 3250 ns).
Sync_Seg = 1 tq = [B]333,333 ns[/B][/FONT]
  [FONT=&quot]Phase_seg1 + Phase_Seg2 = (24-11) tq = 13 tq
Phase_seg1 <= Phase_Seg2, => Phase_seg1 = 9 tq and Phase_Seg2 = 4 tq
SJW = (min(Phase_Seg1, 4) tq = 4 tq[/FONT]
[FONT=&quot]
[/FONT]
  [FONT=&quot]TSEG1 = ([B][COLOR=Red]Prop_Seg[/COLOR][/B] + Phase_Seg1 - 1) = [COLOR=Red][B]19[/B][/COLOR]
TSEG2 = (Phase_Seg2 - 1) = 3
SJW_p = (SJW - 1) = 3[/FONT]
[FONT=&quot][/FONT]

[FONT=&quot][/FONT]
[FONT=&quot]It couldn't be this value, is not allowed. So I only can think this is not TSEG1 not includes Prop_Seg.[/FONT]
[FONT=&quot]So TSEG1 = (Phase_Seg1 - 1) = [COLOR=Black]8[/COLOR][/FONT][FONT=&quot]
[/FONT]
[FONT=&quot]
I'll try this and tell if it is
[/FONT]
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sat Jan 28 11:12:06 MST 2012
Thanks :)
Kay
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Jan 28 09:50:23 MST 2012

Quote: kayoda
Is there a table available which shows this sample points for other CANOpen Baud rates?



Try CiA Application Note 801:

http://read.pudn.com/downloads63/doc/comm/220956/CANOpen/801_v01000000.pdf
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sat Jan 28 09:10:40 MST 2012

Quote: Zero
Recommended CANOpen sample point:

Bit-rate   / Sample point location / Range
1000 kbits / 87.5%                 / 75.0% - 90.0%



Thanks for clarification :)

Is there a table available which shows this sample points for other CANOpen Baud rates?
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Jan 28 07:51:50 MST 2012

Quote: kayoda
Could you please explain me if there's a difference between:
0x1201UL      // CAN_BTR: 1000khz
and
0x4500UL      // CAN_BTR: 1000khz



There are several options to generate a correct Baud rate

But, of course different settings change sample point location :eek:
(Sample point is the point where each bit is measured)[INDENT]Sample point = (TSEG1 +1)/(TSEG1 + TSEG2 + 1) = (TSEG1_val +2)/(TSEG1_val + TSEG2_val + 3)
[/INDENT]So with[INDENT]0x1201 sample point is at 4/6 = 67%
[/INDENT]and[INDENT]0x4500 sample point is at 7/12 = 58%
[/INDENT]So you are moving your sample point forward. Don't know which protocol you are using, but your sample point setting should fit to your protocol.

Recommended CANOpen sample point:

Bit-rate   / Sample point location / Range
1000 kbits / 87.5%                 / 75.0% - 90.0%

A better setting for CANOpen would be:[INDENT]0x2700 sample point is at 9/12 = 75%
[/INDENT]or[INDENT]0x1800 sample point is at 10/12 = 83%
[/INDENT]
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sat Jan 28 03:39:21 MST 2012

Quote: Zero

// Initialize CAN Controller  @12MHz
uint32_t ClkInitTable[2] =
{
  0x00000000UL, // CANCLKDIV: /1 = 12MHz
  0x1201UL      // CAN_BTR: 1000khz
};



Could you please explain me if there's a difference between:
0x1201UL      // CAN_BTR: 1000khz
and
0x4500UL      // CAN_BTR: 1000khz
Thanks,
kay
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jan 27 20:14:41 MST 2012

Quote: kty-tty
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][SIZE=3][COLOR=black]Can someone help me understand this so I know what to set the BT register?[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE]



What's not clear there?

There are 3 time segments:

#1: TSJW   (1-4)
#2: TSEG1  (2-16)
#3: TSEG2  (1-8)

TSEG1-2 are dividing your CAN signal (=every damned bit) to measure it. Together they determinate your  NT (Nominal bit time) = TSEG1_val + TSEG2_val + 3

Note:  To avoid confusion I've added '_val' to show register values. As mentioned in UM, hardware is often reading them + 1
       Sample: BRP_val = 0    means BRP = 1
Quote: Hardware interprets the value programmed into these bits as the bit value + 1.

Sample: Default setting is 0x2301 for 500kBit/s with 8MHz.

As described in 'Table 185. CAN bit timing register (CANBT)' that's:

BRP_val   = 1 (bit5:0)  -> BRP   = 2
SJW_val   = 0 (bit7:6)  -> SJW   = 1
TSEG1_val = 3 (bit11:8) -> TSEG1 = 4
TSEG2_val = 2 (bit14:12)-> TSEG2 = 3

The trick with this settings is to generate a divisible sum with (TSEG1 + TSEG2 +1).In this sample this sum is 8 :eek:

To calculate your Baud rate you just have to:

#1: divide your main clock by SYSAHBCLKDIV(usually 1) to get system clock

#2: divide your system clock by CAN clock divider register (CANCLKDIV), which is usually used to divide to a standard clock like 8MHz.

#3: divide by CAN baud rate prescaler extension register (CANBRPE), which is usually 0 (= divider:1).

#4: divide by (TSEG1 + TSEG2 +1)*(BRP) to get your Baud Rate

That's together:

CAN Baud rate = (main clock)/SYSAHBCLKDIV/(CANCLKDIV_val+1)/(CANBRPE_val+1)/(BRP_val+1)/(TSEG1_val + TSEG2_val +3)

If setting of (main clock)/SYSAHBCLKDIV/(CANCLKDIV_val+1)/(CANBRPE_val+1) is 8MHz already, calculating CANBT is easy:

CAN Baud rate = 8MHz / (BRP_val+1)/(TSEG1_val + TSEG2_val +3)

Now we understand why this sum (TSEG1_val + TSEG2_val +3) is 8.

CAN Baud rate = 8MHz / 8 / (BRP_val+1) = 1MHz / (BRP_val+1)

With BRP_val = 1 we get 0.5MBit/s :rolleyes:


Next task: 1MBit/s with 12MHz

#1 With CANCLKDIV=1 and CANBRPE=1 we still have 12MHz to calculate CANBT

#2 We select a nice (TSEG1_val + TSEG2_val +3) sum of 6:  SJW_val=0 TSEG1_val=2 TSEG2_val=1. That's CANBT = 0x12xx.

#3 With 12MHz / 6 = 2MHz we just have to divide by 2 for 1MBit/s. So BRP=2 and BRP_val =1.

#4 Result: CAN_BT = 0x1201 :)

// Initialize CAN Controller  @12MHz
uint32_t ClkInitTable[2] =
{
  0x00000000UL, // CANCLKDIV: /1 = 12MHz
  0x1201UL      // CAN_BTR: 1000khz
};
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DaveNadler on Fri Jan 27 19:41:36 MST 2012
[FONT=Arial]Sorry I do not have the exact references handy, but... Find and study the Bosch reference documentation for the CAN controller module included in LPC11Cxx (licensed from Bosch) ! The Bosch reference does explain this reasonably well, but be warned it is not simple. Also be warned in some places the Bosch reference conflicts with the NXP reference, and the Bosch reference is correct.
Hope this helps !
Best Regards, Dave
[/FONT]
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jan 27 07:28:41 MST 2012

Quote: kty-tty
..can someone please help me with the BT register settings for 1MHz from a 12MHz crystal?



Try:
// Initialize CAN Controller  @12MHz
uint32_t ClkInitTable[2] =
{
  0x00000000UL, // CANCLKDIV: /1 = 12MHz
  0x1201UL      // CAN_BTR: 1000khz 
};
0 Kudos

1,632 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kty-tty on Fri Jan 27 03:06:43 MST 2012
actually i just found this in the sample code header file notes:

[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f] /*
BRP+1 = [U]Fpclk[/U]/(CANBitRate * QUANTAValue)
QUANTAValue = 1 + (Tseg1+1) + (Tseg2+1)
QUANTA value varies based on the [U]Fpclk[/U] and sample point
e.g. (1) sample point is 87.5%, [U]Fpclk[/U] is 48Mhz
the QUANTA should be 16
(2) sample point is 90%, [U]Fpclk[/U] is 12.5Mhz
the QUANTA should be 10
[U]Fpclk[/U] = [U]Fclk[/U] /APBDIV
or
   BitRate = [U]Fcclk[/U]/(APBDIV * (BRP+1) * ((Tseg1+1)+(Tseg2+1)+1))
*/

[SIZE=3][COLOR=black]Can someone help me understand this so I know what to set the BT register?[/COLOR][/SIZE]
[SIZE=3][COLOR=#000000][/COLOR][/SIZE]
[/COLOR][/SIZE][/COLOR][/SIZE]
0 Kudos