Книга: Advanced PIC Microcontroller Projects in C

9.9.9 Calculating the Timing Parameters

9.9.9 Calculating the Timing Parameters

Setting the nodes’ timing parameters is essential for the bus to operate reliably. Given the microcontroller clock frequency and the required CAN bus bit rate, we can calculate the values of the following timing parameters:

• Baud rate prescaler value 

• Prop_Seg value 

• Phase_Seg1 value 

• Phase_Seg2 value 

• SJW value

Correct timing requires that

• Prop_Seg = Phase_Seg1 ? Phase_Seg2 

• Phase_Seg2 ? SJW

The following example illustrates the calculation of these timing parameters.

Example 9.2

Assuming the microcontroller oscillator clock rate is 20MHz and the required CAN bit rate is 125KHz, calculate the timing parameters.

Solution 9.2

With a 20MHz clock rate, the clock period is 50ns. Choosing a baud rate prescaler value of 4, from Equation (9.4), TQ=2*(BRP+1)*TOSC, gives a time quantum of TQ=500ns. To obtain a nominal bit rate of 125KHz, the nominal bit time must be:

 TBIT = 1/0.125MHz = 8?s, or 16TQ

The Sync_Segment is 1TQ. Choosing 2TQ for the Prop_Seg, and 7TQ for Phase_Seg1 leaves 6TQ for Phase_Seg2 and places the sampling point at 10TQ at the end of Phase_Seg1.

By the rules described earlier, the SJW can be the maximum allowed (i.e., 4). However, a large SJW is only necessary when the clock generation of different nodes is not stable or accurate (e.g., if ceramic resonators are used). Typically, a SJW of 1 is enough. In summary, the required timing parameters are:

Baud rate prescaler (BRP) = 4
Sync_Seg                  = 1
Prop_Seg                  = 2
Phase_Seg1                = 7
Phase_Seg2                = 6
SJW                       = 1

The sampling point is at 10TQ which corresponds to 62.5% of the total bit time.

There are several tools available for free on the Internet for calculating CAN bus timing parameters. One such tool is the CAN Baud Rate Calculator, developed by Artic Consultants Ltd (http://www.articconsultants.co.uk). An example using this tool follows.

Example 9.3

Assuming the microcontroller oscillator clock rate is 20MHz and the required CAN bit rate is 125KHz, calculate the timing parameters using the CAN Baud Rate Calculator.

Solution 9.3

Figure 9.14 shows the output of the CAN Baud Rate Calculator program. The device type is selected as PIC18Fxxx8, the oscillator frequency is entered as 20MHz, and the CAN bus baud rate is entered as 125KHz.


Figure 9.14: Output of the CAN Baud Rate Calculator program

Clicking the Calculate Settings button calculates and displays the recommended timing parameters. In general, there is more than one solution, and different solutions are given in the Calculated Solutions field’s drop-down menu.

In choosing Solution 2 from the drop-down menu, the following timing parameters are recommended by the program:

Baud rate prescaler (BRP) = 4
Sync_Seg                  = 1
Prop_Seg                  = 5
Phase_Seg1                = 5
Phase_Seg2                = 5
SJW                       = 1
Sample point              = 68%
Error                     = 0%

Оглавление книги


Генерация: 1.681. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз