Putting it all together
Eventually, the software was ready, the hardware was ready, it was just time to properly fit it into the scooter. I mounted the controller under the seat, ran the wires through the frame, made sure everything was secure. I connected the two LCD’s in the dash, I put the keypad on the handlebars, mounted the temperature sensor. When I turned on the bike, everything seemed to work fine. I thought everything would be okay because when I did the test fit everything was also okay. However, I quickly found out that the speedo would only mostly work! It was fine most of the time but occaisionally the speed would increase dramatically for a second or so, then it would settle down again. Obviously, this was a problem. It was also confusing because:
- It had worked fine during the test fit
- It only seemed to happen intermittently
- It worked with my test setup on the bench
I thought about this for a while and thought there must be some problem with the new board as it was quite close to the controller for the bike. So, initially, I was working under the assumption that it was an interference problem inducing noise on the lines from the hall effect sensor.
I brought out the oscilloscope and measure the signal when the bike was on and the throttle was running.
This picture is showing the step change from low to high for the hall effect sensor on the hub motor. If you look at this, there is a very large amount of noise when the output is high. The signal to noise ratio is so low that the microcontroller was treating each drop in that signal as another ‘tick’ from the motor. Again, it was confusing as to why I hadn’t seen this before but clearly it was a problem now (whatever had changed). I tried moving the box away from the controller but it didn’t seem to help. I tried a different connection on the hall effect sensor (there are three – one for each phase) but again, no change. I tried shielding some of the signals and putting something between the bike controller and the BMS – no change.
This was a puzzle. I tried retrofitting capacitors and eventually a full low (ish) pass filter to try to filter out the high frequency noise. This helped but it didn’t solve the problem completely. It did spoil the PCB a bit but I was getting a bit desperate.
I was starting to think I should just give up on getting it working and go back to the drawing board. Then I accidentally forgot to reconnect the battery one time when I as removing and replacing the circuit. It all worked perfectly! The signal became very clean and the speedo was very accurate. I even took out the filter and it still worked!
So what was going on? I tried *just* connecting the battery and not the 12V to 5V Switch mode power supply and that also worked fine. So it only went wrong when both the battery and the 12V to 5V converter were both on. This was a clue.
After some thought, I believe I’d figured out what it was. It was a fault that was in the design in one of the very first parts of the hardware I had put together. In order to save components, in the relay latch which allowed the microcontroller to keep the power active (from the battery), I had used an NPN transistor in emitter follower mode. I show part of the circuit here:
The issue with this seemed to be that if the relay was on, there was a current path through the transistors that connected the battery and the 12V to 5V converter together. This is an issue because they are effectively both switch mode power supplies. The resulting seeking of the two switch mode power supplies meant that they were effectively fighting to control the supply. This resulted in high frequency noise being added to the supply rail. I surmised that the whole thing could be solved with some base resistors in the transistor circuits. However, in the end, I found an easier fix. I knew that when the scooter wasn’t moving, the speedo always showed 0. So, even with this hardware issue, it only happened when the back wheel was rotating. The solution was to change the software so that the battery was only latched on if the speed was zero. I was lucky in that the battery automatically activated if it was being charged. So, this meant the circuit was powered if the ignition was on anyway. The battery would stay on as long as current was being drawn. Hence, if you turn the relay off, not enough current is drawn to keep the battery active.
So, changing the software to only activate the latch if the speed > 0 fixed the issues with the speed reading. However, the only side effect was I had to now only turn off the scooter when it wasn’t moving. If I turned the scooter off with the latch deactivated, power would be cut instantly and the microcontroller would not be able to write data to the flash storage (for example for the odometer). However, this wasn’t really an issue. Who turns the ignition off when the scooter is moving?
The reason I hadn’t seen this during the test fit is because I was only running it from the battery and touching wires together to simulate the ignition.
Therefore, in the end I managed to fix a hardware problem in software! I’m sure there is a joke in there somewhere.
Up and Running
After solving the power supply problem, everything else went pretty smoothly. All the modules and software seemed to function fine. The first test run was good, the display was easy to read. I could review the journey and look at the battery profiles, exactly as I wanted. There were a few bugs in the software to iron out but nothing too serious. Here is a video showing various menus. Unfortunately, with the blue display, unless the camera was directly facing it, it does appear to be worse quality than it actually is.
This is a video of me taking the scooter out on a run. I think this was some time later!
Conclusion
The design and modification to the scooter BMS was a great project. It worked perfectly for the entire time I kept the scooter. It passed several MOTs (although I had to explain that the odometer was now reading in miles not km). In the end I rode it for over 50,000 miles. The only reason I got rid of it was that I was on my 4th charger (they don’t last that long and they cost 300 pounds each). Also, some other parts of the scooter had started to wear like the suspension. I’d replaced the brake cylinders a few times. There was quite a bit of rust on the frame and I had to replace the controller (with the only spare). The parts I had added were basically outlasting the rest of the scooter. Again, I was driving it pretty hard. When the charger broke again, I decided it was time to change.
I have ridden bikes for some time and I always had another motorbike (as well as the scooter) and I had thought about replacing both the scooter and the motorbike with a single electric bike. I wanted something I could commute on and something I could have some fun with.
Eventually, I bought myself a Zero DSR. I cannot say that this was a cheap option but it would solve both my needs and is a world away from the little Chinese scooter. I part exchanged my other bike but I couldn’t sell the scooter to anyone (it had been significantly modified after all). Before it went (to the scrap man), I stripped it down and took everything I wanted out of it – my garage has a load of lithium batteries in it! I also removed the system I had built and decided to keep it.
My commute changed significantly with the Zero – I could now ride on the motorway. I love the Zero but there are times when I miss the comfort of riding the scooter and the feeling that I had pretty much rebuilt it. There is something very satisfying about that.
Post Mortem
After I took the BMS out of the scooter, I didn’t want to lose all the work I had done on the system. So I ended up putting the system onto a display board. I wanted to be able to run it (even out of the scooter), so I ended up designing a “scooter emulator”. This was again just another arduino which faked the signals from the scooter. I had to build a system that would use 20 batteries, the same as the ones in the scooter. I could still monitor these but mostly I wanted to send a fake pulse to replace the hall effect signal.
I knew that I would need some interface to be able to drive this scooter emulator and I decided on an Elegoo touch screen LCD display. I wanted to really emulate the operation of the scooter, so I also generated fake random terrain which would mean the scooter would effectively go up and down hills. I also put a throttle and a brake into the software as part of the interface. I wanted to display my logo and an image of the scooter on the LCD which required writing some run length encoding compression so that I could get the picture to draw quick enough.
- Batteries
- Temperature sensor
- 12V to 5V (scooter)
- Ignition
- Hall effect connector
- Scooter Emulator
- Scooter BMS
- 30V to 5V (for running emulator)
- Scooter keypad
- Scooter Dashboard
Here is a video of it running: