Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to calculate CAN baud rate
How to calculate CAN baud rate
The following is the information I am looking for, I hope I can help you!

Can controller can communicate with only a few settings and can be used like RS232/48.

The hardest part is the calculation of communication baud rate. CAN bus CAN tolerate the deviation of communication baud rate of CAN nodes in a certain range, which makes CAN bus have strong fault tolerance and reduces the oscillator accuracy of each node.

In fact, the baud rate of CAN bus is a range. Suppose the defined baud rate is 250KB/S, but in fact, according to the setting of the register, the actual baud rate may be 200~300KB/S (the specific value depends on the setting of the register).

This paper briefly introduces the calculation of baud rate. In the underlying protocol of CAN, each bit time (TBit) of CAN data is divided into many time periods (Tscl), including:

A. bit synchronization time (Tsync)

B. Time period 1(Tseg 1)

C. time period 2(Tseg2)

Where the bit synchronization time takes up1tscl; ; Time period 2 occupies (tseg1+1) tscl; ; Time period 2 occupies (Tseg2+ 1) Tscl, so the bit time (TBit) of CAN controller is: tbit = tseg1+tseg2+tssync = (tseg1+tseg2+3) * tscl, so the baud rate of CAN (CANbps).

But the value calculated in this way is a theoretical value. In actual network communication, the calculation of network baud rate will become complicated due to transmission delay, crystal oscillation errors of different nodes and other factors. CAN introduces the concept of resynchronization in technology, which solves these problems well. Because of this re-synchronization, either TSJW (synchronization jump width SJW+ 1) increases in the time period 1(Tseg 1) or TSJW decreases in the time period, so the baud rate of CAN actually has a range:1(TBIT+TSJW) ≤ CAN.

The baud rate value of CAN is 4, which is determined by the following factors:

A. minimum time period Tscl;;

B. Time period1tseg1;

C. Time period 2tseg2

D. synchronous jump width SJW

So how is Tscl calculated? This is the prescaler register BRP in the bus timing register, TSCL = (BRP+ 1)/Fvbp. FVBP is the peripheral clock of the microprocessor.

And how are TSEG 1 and TSEG2 divided? The length of TSEG 1 and TSEG2 determines the sampling point of CAN data, allowing a wide range of data transmission delay and crystal oscillation error. Among them, TSEG 1 is used to adjust the error caused by data transmission delay time, and TSEG2 is used to adjust the error of crystal oscillation frequency of different nodes. But they are so flexible that people who first come into contact with CAN are a little at a loss. The difference between TSEG 1 and TSEG2 generally follows the following rules: Tseg2≥Tscl2, Tseg2≥2TSJW, Tseg 1≥Tseg2.

Generally speaking, it is enough to grasp a general direction for baud rate calculation of CAN, and its calculation formula can be specified as follows: bit rate = fpclk/((BRP+1) * ((tseg1+1)+(tseg2+1)+60.

The calculation of CAN baud rate is described in detail in the data sheet. Here is a simple calculation method:

Tcsc :bit The time length of bit encoding, which can be configured as 8~25 bits encoding per bit, and is permanently 16.

Tcsc= 1/ baud rate/coding length; Press to calculate TCSC =11MHz/16 = 62.5ns (take 63).

BRP = (TCSC x mck)-1= 6.3-1(you can take 5).

Various delays (TPR:)

Delay of bus driver: 50 ns

Receiver delay: 30ns

Bus line delay (20m): 1 10ns

tprs = 2 *(50+30+ 1 10)ns = 380 ns

Propagation = 380 ns/TCSC-1= 6.08 TCSC-1(take 6).

Tphs 1+Tphs2 = bit time-TCSC-tprs = (16-1-7) TCSC = 8.

Tphs 1 = Tphs2 is often taken, so tphs1= tphs2 = 4;

Tsjw = Min(4 Tcsc, Tphs 1) = 4 Tcsc (from 1 to Tphs 1)

SJW = Tsjw/Tcsc- 1 = 3;

Now all the parameters in CAN_BR can be used (BRP = 5;; SJW = 3; Propagation = 6; PHASE 1=PHASE=4), and it should be OK if you fill it in.

Suppose we don't consider the SJW bit in BTR0 and the SAM bit in BTR 1 Then, BTR0 and BTR 1 are two frequency division coefficient registers; Their product is the extended frequency division coefficient. Namely:

Bt r0×btr 1 = F _ BASE/Fbps( 1)

These include:

Internal frequency reference source f _ base = Fclk/2, that is, the frequency of external crystal oscillator divided by 2. Note that in any application, when an external crystal oscillator is used as a reference source, it is first shaped by dividing by 2.

In the formula (1), when the crystal oscillator is 16M, f _ base = 8000k.

When the crystal oscillator is 12M, f _ base = 6000k.

Fbps is the frequency of CAN bus we want. The unit is K.

Let btr0 = m, btr 1 = n and external crystal oscillator 16M in formula (1), then:

n =8000/ Fbps (2)

In this way, when Fbps takes the value we want, it will get a combined value of m * n, and when n is selected, the value of m is unique.

N-value CAN specification specifies 8 ~ 25. (i.e. the value of BTR 1) The basic principle is that the higher the Fbps value, the greater the N value (by setting BTR 1). The reason is not difficult to understand.

I assume that the general application chooses n = 10, that is:

Synchronization segment+phase buffer segment 1+ phase buffer segment 2 = 1+5+4.

Then (2) is simplified as follows

m=800/Fbps

The maximum setting value of m is 64, and the maximum frequency division coefficient of SJA 1000 is m * n = 64x25 = 1600. Therefore, the standard algorithm usually takes 16M crystal oscillator as an example. In fact, with the formula (1), any crystal oscillation value (6m ~ 24m) can be easily calculated.

Determination of SAM: At low frequency, select SAM = 1, that is, sample 3 times. When the high frequency is above 100K, Sam = 0, that is, sampling 1 time.

SJA resynchronization jump width selection: related to digital phase-locked loop technology. When the value of n is large, SJA can be large, that is, multiple pulse shares Tscl can be corrected at one time. When the value of n is small or the frequency is low, SJA = 1 is selected. In other words, BTR0.7 and BTR0.6 are both set to 0.

File: Baud rate calculation. Textfile (textfile)