Magic CAN Node

Overview

Magic CAN Node is a small, convenient microcontroller board, designed to measure automotive sensors onboard our electric racing motorcycle, RW-2x.

Photo of Magic CAN Node PCB

It’s got a bunch of useful features:

  • TI C2000 processor (TMS320F28035), with the associated goodies
  • Two SPI interfaces
  • One I2C interface
  • 14 PWM outputs
  • 16 analog inputs (15 accessible on our board)
  • One switched 12V output, capable of sourcing 5 A
  • CAN transceiver with automatic CAN termination circuit
  • Big heavy-duty sealed connectors for interfacing to the outside world
  • Two general-purpose LEDs and one general-purpose pushbutton
  • Configurable RC low-pass filtering for each analog input channel
  • Power loss detection, including a big 1000 uF electrolytic capacitor that gives us at least 1 ms of execution time after we lose power
  • Introduction

    After our third-place finish last year, we got back to Ohio with our heads full of improvements to be made to our motorcycle, RW-2. One of the biggest changes we decided to make was revamping our data acquisition system (blog post here.

    We have a bunch of different sensors around the bike we need to measure:

    • A bunch of different temperature sensors (thermistors): battery pack temperatures, coolant temperatures, etc
    • Some other resistance-based sensors, like our suspension travel sensors (big linear pots)
    • A few 0-5V and 0-12V sensors (we have brake pressure transducers and a differential air pressure sensor)
    • Digital sensors (our GPS speaks serial, we have an accelerometer/gyro IC that we talk to using SPI)

    And since our vehicle is basically a rolling electromagnetic noise bomb, we wanted to measure all of these analog sensors as close to the source as possible.

    Hence, the Magic CAN Node. The Magic CAN Node was devised as a multipurpose board that could measure anything we wanted to measure, anywhere on the bike. We made a bunch of them at once, tied them all together in one datalogging CAN bus, and for the first time we have access to any sensor measurement on the bike by plugging in one cable.

    Hardware

    Processor

    Magic CAN Node is based around a TI uC, the TMS320F28035. We’ve been happy with the features and the power of these things, as well as the low power consumption.

    We thought about using the MSP430, too, but it was a little bit underpowered for our application, and we would have needed to use an external CAN communication IC. So we bumped ourselves up to the C2000. TI has been very kind to us and sent us all the C2000s we needed for the project.

    CAN interface

    We’re using the built-in CAN module in the F28035 for our message handling. The transciever is another TI part, the SN65HVD230.

    One thing we noticed with last year’s CAN network was that people are always forgetting to plug in termination resistors. Since we have to jack in at the ends of the bus, we were always unplugging the termination plugs and losing them. So the Magic CAN Node has auto-termination:

    Schematic and PCB layout of Magic CAN Node auto-termination circuit

    All of the CAN plugs have two of the pins shorted to GND or +12V, so when there’s only one plug connected, the analog switch IC will connect a 120 ohm resistor across the CAN lines. Sweet.

    Expansion interface

    We assumed we would want to play with a weird IC or use some other functionality of the F28035 later on, so we included an expansion interface. We took a cue from the Arduino here: expansion boards take the form of “backpacks”:

    The rest of the board is laid out in SI units, but the expansion interface is 0.1” pin headers on 0.1” centers, so that we can make a backpack out of some perfboard if we need to. Seven of the analog inputs are available on the expansion header, as well as PWM outputs and digital interfaces (serial, SPI, I2C).

    We’ve already made two backpacks: one of them is a combined GPS and 6dof IMU, and the other one is a board that measures the resistance between the high-voltage circuit and the motorcycle chassis and warns us if there’s a short. We were able to make both of those boards as 2-layer PCBs and lay them out in about a week -- way faster and cheaper than designing them with built-in microcontrollers.

    12V switching

    The Magic CAN Node can switch a single 12V load. Since a lot of automotive accessories expect to be switched on the high side (they have their own connection to GND), we used a P-channel FET to do the high-side switching.

    Filtering

    Every one of the analog input channels has its own RC lowpass filter:

    Filter components on Magic CAN Node

    We got really paranoid about noise after last year’s race, and decided to include these filters so that we could be sure to get data from some of our more delicate sensors, like thermistors.

    For an idea of what we’re dealing with, here’s a comparison between filtered and unfiltered sensor data. The data on the left had no filter installed (the thermistor was connected directly to the ADC input). The data on the right is the measurements from another sensor with a first-order RC filter installed.

    Sensor data before and after filtering. The 'before' data is very noisy.

    Software

    We designed the Software template to be easy to use for other team members who are not familiar with microcontroller programming and takes care of the basic features of the Magic CAN Node behind the scenes.

    Software Features include:

    • Programmable over CAN
    • Safely powers down when power is lost.
    • Works with a large range of CAN Bitrates.
    • Can send CAN messages at variable rates.
    • Able to receive and respond to Commands over the CAN bus

    The software template also provides API for commonly used modules in the microcontroller.

    Software Functions Included:

    • Send and receive CAN messages
    • Software “stopwatch” for time critical operations
    • Setup and change GPIO pins.
    • Programmable over CAN

      Because of the size of the motorcycle, electronics are often deeply embedded into the motorcycle making it hard to program the nodes from the typical jtag header. We wrote code that allows the node to be put into a bootloading mode then reflash its code through the CAN bus which means any node can be reprogrammed without taking the node out of the motorcycle.

      Software Stopwatch

      Timing is often important in microcontroller programming. To make time critical tasks we wrote functions to implement a software stopwatch. The stopwatch is an object (actually a structure, we are working in C) that records how long it has been since it has been reset and tells you if too much time has elapsed. This object is useful in many cases including delaying, breaking out of loops that have taken too long, or timing the time from the last CAN message has been received.

      Results and Problems

      The Magic CAN Node will be on the bike for the 2014 TT Zero, but we’ve already had several days of track testing with the full complement of Magic CAN Nodes and sensors. Some thoughts from our hands-on experience:

      Data

      With 3 Magic CAN Nodes we were able to collect a large amount of data about our electric motorcycle during testing allowing us to tune the motorcycle to the Isle of Man TT Zero. These 3 Magic CAN Nodes will also be used during the Isle of Man TT Zero to collect data so we can build a better motorcycle next year.

      Electromagnetic Interference

      We’re constantly fighting with EMI. The electromagnetic noise from our power inverter couples into our sensors, but we were able to fight this fairly effectively by adding per-channel input filters.

      More worryingly, while the motor is spinning, we saw so many error frames that some nodes started to drop off the bus. We implemented some software fixes and CAN bus filtering. Future revisions will consider these electromagnetic problems more heavily.