Calculation of Bit Timing Register values for the CAN controller

Introduction

For most CAN bus applications, the device (terminal, I/O-module, etc) will already support the required CAN baudrate (in kbit/second). For example, the following CAN speeds are supported by most of MKT's programmable terminals :

20 kBit/sec, 50 kBit/sec,  100 kBit/sec,  125 kBit/sec, 250 kBit/sec, 500 kBit/sec, 1 MBit/sec .

Furthermore, most display terminals for automotive applications also support these baudrates:

83.333 kBit/sec, 666.667 kBit/sec, 800 kBit/sec .

So in most cases, there is no need to calculate the CAN controller's Bit Timing Register value (BTR) yourself. But in some exotic cases, when the required baudrate is not one of the "standard baudrates" listed above, you must define the BTR value yourself. This document will show you how.

How to calculate the BTR value

To calculate the BTR value, you need to know the CAN controller's clock frequency. Unfortunately there is a large variety of clock frequencies, depending on the CPU (and the frequency of the crystal clock oscillator). Here are the clock frequencies of some devices by MKT Systemtechnik which allow programming of the BTR values :

The formula to calculate the BTR value for a given CAN-baudrate, a given sampling point, etc depends on the CAN controller in use. Fortunately, the design of many CAN controllers used by MKT is similar to the Intel 82527 ("Full-CAN controller"). A good explanation of the BTR can be found in its datasheet. Beware that the "XTAL" frequency mentioned in the 82527 datasheet is not the same as fCAN ! In this document, fCAN is the clock frequency for the CAN controller, not the "crystal frequency", and not the bitrate on the CAN-bus !

(In fact, fCAN is often the microcontroller clock divided by two because the prescaler in another register of the CAN controller is programmed to divide by two. The value of "fCAN" listed above already takes this into account ).

The BTR value can be split into (at least) 4 bit groups, which are placed in a single 16-bit word here for simplicity. They are:

Note: The actual division ratios are usually <register value + 1>. The following formulas take this into account.

Calculation of the CAN baudrate for a given BTR value:

Baudrate = fCAN / (  2 * ( BRP+1)  *  (3 + TSEG1 + TSEG2 )  )

Example (for MKT-View "Plus" with fCAN=20 MHz, BTR=0x1C09 ->

BRP = 0x09 = 9 decimal ( BTR bits 5..0)
TSEG1 = 0x0C = 12 decimal ( BTR bits 11..8 )
TSEG2 = 0x01 = 1 decimal ( BTR 14..12 )

Baudrate = fCAN / (  (BRP+1) * (3+TS1+TS2) )
 = 20e6 / (  ( 9+1)  *  ( 3 + 12 + 1 ) = 125000

So, for this example, a BTR value of 0x1C09 gives a CAN baudrate of 125 kBit/second .

But again, the BTR value depends on the clock frequency of the CAN controller !

If someone tells you "the BTR value for my CAN controller is 0x1C09", always ask the question "and what is the clock frequency of your CAN-controller ?". Many CAN controllers with the original 82527 chip are clocked with a 16 MHz crystal (which is divided by two, so fCAN as we use it here would be 8 MHz). In that case, a BTR value of 0x1C09 would give a CAN baudrate of

8e6 / (  ( 9+1)  *  ( 3 + 12 + 1 ) = 50000 = 50 kBit/second !

For this reason, we strongly recommend that you only use "direct BTR programming" if really necessary (to avoid the hassle with the clock-frequencies). The following table lists the BTR values for some CAN baudrates so you don't have to calculate them yourself.

fCAN

CAN baudrate

BTR value (hex)

Relative position of the sampling point

20 MHz

1000 kBit/sec

0x1401

0.7 * t_bit

20 MHz

800 kBit/sec

0x7F00

0.64 * t_bit (caution !)

20 MHz

666.67 kBit/sec

0x1B01

0.8 * t_bit

20 MHz

200 kBit/sec

0x2F04

0.85 * t_bit

20 MHz

83.3 kBit/sec

0x145D

0.75 * t_bit

20 MHz

10 kBit/sec

IMPOSSIBLE

How to enter the BTR value in the MKT-View (not MKT-View II ! )

The following steps are required for the MKT-view terminal (which only has three function keys and a rotary button as replacement for the cursor keys and the ENTER key). Other devices may have a larger keyboard, which makes entering the hexadecimal value a lot easier. But the basic principle remains the same as explained below :

  1. Enter the terminal's system menu (press and hold F2+F3 simultaneously)
  2. Scroll to "User Settings" and enter that submenu
  3. Scroll to "CAN Bit Timing Registers" and enter that submenu
  4. Navigate to "BTR-Value for CAN1" (or CAN2) and press enter to switch to edit-mode
  5. Enter the BTR value in hexadecimal form, and modify the value.
    While doing this, observe the text in the status line at the bottom of the display:
    If shows the "theoretic" CAN baudrate for the currently displayed BTR value.
  6. Finish editing by pressing the ENTER key again
  7. Navigate to "Save and EXIT" and press ENTER again
  8. Turn the power off and on again to restart the CAN controller with the new BTR value


When you return from the BTR programming screen to the "User Settings", you will notice that the "CAN baudrate" display is now marked with a question mark. This is not a bug but a feature ;-) ... instead, the combo box (which allows a simple selection of the STANDARD CAN baudrates) doesn't know what to do with the BTR value. So, instead of guessing the baudrate, the combo shows a question mark, followed by the BTR code in hexadecimal form.

< to be completed >