E-Bike system – Part 2 – CAN Interface

The first part of the E-bike system will be a computer interface to connect to all the nodes using the CAN-bus. This will be used for diagnostics, parametrization and software flashing. This makes it the logical starting point before developing the other parts of the system.

There are several commercial tools for this. Of course I could have used one of them, but it’s more fun, and cheaper to build my own. The tool I’m used to, is CANalyzer from Vector which is extremely competent but also extremely expensive. CANalyzer woll be a big inspiration for the windows application I build to communicate with the hardware interface.

Windows application

The windows application will have some basic features for setting up a signal database and debug generic messages, but also some specific features for communication with the different parts of the E-bike system. The application is created in C# .NET using Microsofts free Community edition of Visual Studio

Hardware Interface

The hardware will be built around the STM32F042C6 processor which have built in crystal-less USB and a CAN-interface which makes for a very low part-count device. Apart from some LEDs and passives, its only a processor, can transceiver and voltage regulator. For low volume production the BoM cost of the v0.1 prototype is around $10.

I’ve already designed and built the first prototype hardware and ordered the boards from OSH Park.

USB2CAN PCB v0.1 top
Top view of the USB2CAN board prototype v0.1
USB2CAN PCB v0.1 bottom
Bottom view of the USB2CAN board prototype v0.1

Firmware

The embedded firmware is built on top of the ChibiOS RTOS using ChibiStudio which is a great tool for getting started with ARM Cortex-M development. Functions for communicating with the USB and CAN hardware and task synchronization is already done in the RTOS with the corersponding HAL.

The first version of the firmware works fine for sending and receiving CAN messages. There is still some work on the bootloader and the windows application. But I’m far enough to move on to the next part of the e-bike system, the BMS.

E-Bike system – Part 1 – Introduction

I’m currently working on replacing the complete electric system on my E-bike. The new system will be completely DIY and consist of several parts connected by a CAN-bus. I will post about the progress here continuously.

The system will be divided into several parts, all of them controlled by a STM32-series ARM Cortex-M processor running ChibiOS RTOS. The image below shows a system overview.

Overview of E-Bike system
Overview of E-Bike system

Handlebar Control Unit [HCU]

The main node controlling the rest of the bike will be mounted on the handlebars. Later on I’m thinking about something with a ~4.3″ TFT screen. To begin with it’ll probably be something much simpler. The main tasks would be to sample the acceleration and braking request and forward to the motor controller. It will also controll and display status from the BMS

Motor controller [DCAC]

I will probably start with a VESC with a redesigned PCB more suitable for e-bike use with heftier power transistors. Perhaps I’ll develop my own software to this later on since I find motor control software very interesting.

Battery Management System [BMS]

The battery will be built of 12 cells long series of 18650 cells. To monitor, balance and protect these I will build a BMS around the Maxim MAX14920 chip. This is an analog front end for voltage level conversion and balance discharge of 12 cell batteries. A STM32F373 processor will handle the sampling, control SoC estimation and communication with the rest of the system. The BMS will be able to continue running after the rest of the bike is shut down to handle charging and balancing after a ride.

Voltage Stepdeown [DCDC]

To generate 12 V from the main battery for driving the other nodes and things like lights. To begin with this will probably be designed around an off-the-shelf switching regulator controlled with a hard wire from the BMS which should have its own power supply.

CAN interface [CAN2USB]

This will be the first part I develop, the first prototype is already built up and somewhat tested. I will write a longer post about this later on. The CAN interface will be used to be able to download software, parameters and to read diagnostics using a computer. There are comersialy available alternatives but how fun is that. I manage to get the BoM down to the $10-$15 range as well. The can interface is based on a STM32F042 processor with built-in crystal-less USB and a CAN transceiver chip. This will talk with a Windows application over a virtual com port. The Windows application is written in C# using the community edition of Visual Studio.

Charger

A “dumb” standard Lithium battery charger like the one I have for my previous E-bike could be used as a start, but it would be nice if the charger was connected to the CAN-bus and let the BMS handle the charge and current control.

Mechanics

The mechanics will be the same ase described in for example [these] posts. The difference is that the bike will be touched up quite a lot with both paint and parts.