For the love of Engineering

Electric Scooter Part 3 – BMS

Introduction

As I showed in part 1, I’d already put connections into the scooter to be able to read the voltage for every battery.  In total this is 21 wires, 1 for 0v and 20 wires for each battery.  I wanted to put some system in the bike that monitored the batteries and the speed of the bike and possibly some other things like temperature.  Of course, if you are monitoring the speed you also have to keep track of the mileage.  I also wanted to monitor the rate of charge (when charging) for the batteries and ultimately I wanted to automatically balance the batteries so that they all stayed at the same level of charge.

LiFePo4 Batteries

The voltage range (depending on charge level) of LiFePo4 batteries is about 2.6V to about 3.6V.  To add a bit of buffer to this, I needed a system that measured each cell from 2V to 4V.  Outside this range, I didn’t care too much.

The problem with this is that the 20 batteries are wired in series.  So, you cannot measure the voltage of each cell with reference to the 0V (negative of the first battery).  By the time you would measure the last battery the voltage is of course up to 72V.  So each battery has to be measured relative to the battery before it in the series.  After testing a few methods for doing this, I eventually decided on using analog opto-isolators (SFH618A).  These have pretty good linear range and if you balance them correctly they can easily handle the voltage range that I want.

So, the optoisolator schematic looks like this:

 

In the end I decided to use variable resistors so I could tune the voltages as there will always be differences in the ICs.  After doing some bench tests, I was satisfied enough to quickly etch a prototype circuit board.

Power Supply

Because I also wanted to monitor the battery charging process, I needed to keep the system powered up even after the ignition was turned off.  This would also solve the problem of writing the current mileage to flash storage.  If the mileage is forgotten every time the ignition is turned off, this isn’t going to be a very good dashboard!  So whatever microcontroller I eventually used would have to have the ability to latch the power on.  The simplest way to do this was to make a relay circuit that would be switched on with the ignition but could then be latched on by the microcontroller.  The scooter has one of these devices:

This is a watertight box which converts the 72 (ish) V into 12V but only when the ignition is on.  The box is only watertight because the entire circuit has been potted (sealed with a hardening compound).  So, it is pretty much impossible to modify this.  If you look at the picture you can see where some of the potting compound has crystalised and is leaking out.  This means that there is no way to get access to the 12V power when the ignition is turned off.  After a bit of experimentation I decided that a USB battery was a good option.  Although this worked at 5V, that would be fine for the microcontroller.  It took a few attempts to find a battery that would deliver 5V at the same time as charging – some chargers turn off the 5V out when they are being charged.  I settled on an Anker battery that would do this.  That way I could (almost) just treat it as a permanent 5V supply that would just happen to be charged when the ignition was on.  Again, some prototyping:

 

Here is the schematic for the power latch (note, I also wanted a USB debugging/firmware update connector):

 

Prototype fitting of the battery, latch and opto-isolators is shown below.  My thought at this stage was that I would design the controller and the other parts separately.  The blue circuit board an the bottom left is a settable switch mode power supply that I used to convert the ignition 12V to 5V.  They are pretty cheap and available from eBay.  However, they are a bit ‘ripple-y’ in terms of quality of power supply but are fine for my purposes.

 

Microcontroller

I started to think about the microcontroller that I wanted to use.  I’d done a lot with 8-bit and 16-bit PIC microcontrollers before and I had thought of using those.   I then realised I could just use an easy off-the-shelf solution like an Arduino.  The issue with this is that the pin connectors are not very robust for automotive applications, unless you build a ‘shield’ to fit on top of the arduino.  However, I cam up with the idea of mounting the arduino inverted on top of a motherboard.  This would probably survive an automotive application.  I looked at the different models of the arduino and decided on the MEGA.  I wanted a reasonable amount of space for the software because I knew it would be quite sophisticated with the battery monitoring and other features.  To be honest the price wasn’t even that different, you can get a clone Arduino MEGA these days from less than £15.

One of the problems with the Arduino is the arrangement of the pins.  They are not all arranged on the same 2.54mm grid.  This means it is difficult to mount this on a prototyping board.  So, that meant it was time to get the PCB CAD software out.  Of course, as part of my day job I have free access to multiple CAD software programs.  I decided to use CADSTAR to design the PCB.  I created a custom library of parts that I thought I would need including an inverted mount for the Arduino Mega 2560.  I redesigned the opto-isolators to include 2 variable resistors per channel for a bit more control, then fed the output of these into the arduino.

The problem now was that the arduino doesn’t have 20 analog inputs.  It only has 16.  A solution to this was to use an analog multiplexer.  I decided on the 14051.  This is an 8-bit analog multiplexer/demultiplexer, so I needed three to cover the 20 batteries and could feed them into three different analog inputs on the arduino.

As I now had so many spare digital signals on the controller, I started to think about what else I might want.  I had already thought I wanted some outside temperature monitoring to check the affect on battery performance and as I rode throughout the winter, knowing when the temperature was below freezing would probably be a good idea.  I found a simple thermostat that used a 1-wire interface which I could mount somewhere else in the bike.  I also thought about how much space I had in the surround for the dashboard that I would be replacing.  It seemed feasible to have a large (40×4) LCD and a small (8×1) LCD, so I needed two LCD interfaces.  I also needed some way of getting input, so I decided on 4 buttons to control menus and anything else I wanted.  There was also some miscellaneous things like knowing when the scooter lights were turned on, so I could backlight the LCD etc.  So, the rest of the schematic looked like:

 

PCB Version 1

I modelled the PCB with the CAD software so I could see how the arduino would fit on the board and also how the whole thing would fit in the case.  The model looked like:

 

I wrote some custom libraries for OpenSCAD to generate the board shapes and mounts for different PCBs in the case.  After a bit of design and moving boards and the battery around, I eventually ended up with this:

I used d-type connectors from the case.  I realised that these are probably not ideal in an automotive environment but at least I could screw them in securely.  I also knew that the mounting place for the box would be under the space under the seat, so this would be pretty safe in terms of road dirt/moisture.

I used pcbtrain.co.uk in the UK to manufacture the bare PCB.  It turned out great.

 

I populated the board (partially complete shown below) and then did some testing of the board and test fits in the case.

 

Although this worked, I think it is fair to say I wasn’t massively pleased with the result.  There were far too many loose wires in the case with all the boards in there.  Again, this has to be robust enough to work in an automotive environment.  However for now it was fine and I wanted to work on the dashboard.

 

User IO

I wanted to model and 3D print a replacement dashboard with all the fittings.  I did try initially 3D scanning the original dash but it proved not to be accurate enough.  So, I ended up having to take many, many measurements and modelled the dash case in (my favourite) OpenSCAD again.  To get the shape of the back of the dash I used a technique I have used before.  I start by doing a 2D scan of the shape using a normal flatbed scanner.  Next, I generate an outline of the scan using inkscape then using a script in inkscape I generate an openscad 2d shape (which I can then extrude).

 

 

Comparing the old and new dashboard side by side (note the old dash was also reading in KM not miles which had annoyed me for ages):

 

I found some waterproof buttons (again probably eBay) that I could use for the interface.  I designed a box that I could mount on the center of the handlebars to hold the buttons.  I tested different arrangements of interface and ‘fonts’ for the numbers.  Picture below is not the final version.  In fact, I ended up using a blue LCD as it was more visible to be able to read the speed when riding along.  Note that the odometer is now reading miles!  Although in the end it was switchable using the software.

 


Test Fit

I did a test fit of the controller underneath the seat mount:

 

As you can see from the picture, it fitted but only just.  I added the temperature sensor with the 1-wire interface near the back of the bike on the frame so that it could get an ‘outside’ temperature reading.  The battery-backed realtime clock was mounted in the case.  In the end, although this version seemed to work okay, I still wasn’t happy with the amount of loose wires inside the case.  I had the idea that it would be better (more robust) to mount the connectors directly to the PCB.

Also, after doing some real tests with the batteries, I was happy that I could replace some of the variable resistors with fixed resistors and make the PCB much smaller.  To further reduce the size, I decided to replace some of the resistors with surface mount 0805 packages and also replace the multiplexers with the SMD versions.  I hadn’t fitted the dash and the I/O yet anyway but all the connectors could stay exactly the same.

I wanted to add a diagnostic buzzer and also a bluetooth interface so that I could get more detailed information via a phone.  The new PCB looked like:

 

 

Again, a quick bit of PCB manufacturing later:

 

One thing I would say is that soldering 0805 components by hand can be tricky but I managed to get a reasonable technique at the end.

I redesigned the case to fit the new PCB and built in some cutouts at the edge of the case.

 

It looked much better but in the end I redesigned it yet again to put the battery underneath the circuit board as I had a lot of vertical space in the bike (version 4 now?).

 

This was the final version that ended up in the bike. I calibrated each battery line by setting some different voltages and measuring the reading after the opto-isolators.  As I said earlier, I replaced the main LCD in the dashboard with a blue one, this was much clearer.  I finished off the dash and then it was time to create the software.

Previous

Leave a comment

Your email address will not be published. Required fields are marked *