CAN Bus Baudrate Auto Sensing

Task

Currently, our can node software has a fixed CAN bus baudrate. If the CAN bus baudrate is changed on the flight controller side, our CAN node will fail to work. The idea of this project is similar to UART baudrate auto sensing, the CAN node is able to sense the bit rate on the bus and change its bit rate accordingly either by trial and error or something smarter.

Background

The Baud-rate on a CANBUS device refers to the rate (speed) at which data is transmitted on the network. This is typically expressed in kilobits-per-second (kbps).

Selecting the incorrect Baud-rate can cause erratic behavior on the network.

 

What is Silent Mode?

The Silent mode allows a node to be set to a state, in which it is absolutely passive to the bus, meaning it is "invisible" to the rest of the network and it does not influence the bus in any shape or form. The node does not even provide an ACK frame when a message is placed on the CAN bus correctly. Thus, the Silent mode provides a perfect Listen-Only mode for diagnostic features such as the baudrate detection.

 

Changing CAN Bit Rate

Changing the CAN controller's bit timing does not require restarting, just going back into initialization mode to reconfigure and then going to Normal mode and participating on the bus again.

Research

Implementation: https://microchip.my.site.com/s/article/CAN-bus-baud-rate-auto-detection#:~:text=The%20CAN%20Bus%20node%20can,with%20automatic%20baud%20rate%20detection.

  • Explains how CAN Bus baud rate detection can be implemented

  • Analyzing in listen-only mode method

  • Preqrequisites

    • The CAN Bus node can only detect the CAN Bus transmission rate when it is connected (and starts up) to a running network.

    • You need at least two other CAN Bus nodes (i.e. a running network) who communicate with each other before you can connect or test the bus node with automatic baud rate detection.

    • The CAN bus node responsible for baud rate detection must support Listen Mode (or Silent Mode). Using this mode the specific node behaves like a passive node, it doesn't influence the the communication or bus errors. It is mandatory to not provide any ACK for received messages.

How CAN Bus Automatic Baudrate Detection Works And What To Consider When Connecting To A Network

Potential methods: https://os.mbed.com/questions/79056/CANbus-baud-rate-detection/

  • Method 1

    • Configure your CAN controller to *NOT* assert the hardware acknowledge.

    • Connect at one speed and listen .

    • If you see CAN errors, switch to the other speed.

    • If you see no CAN errors, reconfigure to enable hardware acknowledge.

  • Method 2 → Will be attempting this method

    • Most CAN transceivers have a pin that can put the chip into a listen only mode.

    • Wire that pin to a micro pin.

    • Configure the transceiver for listen only.

    • Configure CAN for one speed and listen.

    • If you see CAN errors, switch to the other speed.

    • If you see no CAN errors, toggle the pin to the CAN transceiver to enable the full mode.

  • Method 3

    • If the CAN Rx pin on the micro could be configured to grab a hardware timestamp, measure the time of CAN pulses.

    • It would need to capture many, to ensure it found the smallest pulse.

    • Compute the bit-rate and configure the CAN controller.

 

Common Baudrates

Calculated from this website: http://www.bittiming.can-wiki.info/

  • 125 kbps (kilabit per second)

    • Clock Rate: 110 MHz

    • Pre-scaler: 55

    • Seg 1: 13

    • Seg 2: 2

  • 250 kbps

    • Clock Rate: 110 MHz

    • Pre-scaler: 40

    • Seg 1: 9

    • Seg 2: 1

  • 500 kbps

    • Clock Rate: 110 MHz

    • Pre-scaler: 20

    • Seg 1: 9

    • Seg 2: 1

  • 1000 = 1 mpbs

    • Clock Rate: 110 MHz

    • Pre-scaler: 10

    • Seg 1: 9

    • Seg 2: 1