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.

Dual pulse battery spot welder

I recently bought 20 Sanyo NCR18650GA Lithium batteries. 12 of them will be used for developing a BMS for a upcoming E-bike project. From the other cells I will put together 2 battery packs for my bicycle lights, 4 cells each in 2s2p configuration.

This type of cells are usually spot welded together using thin nickel strips. I’ve read that many have been successful soldering the cells together but how fun is that when you can build a DIY battery spot welder.

Most designs that I have found is based on a SSR (Solid State Relay) controlled MOT (Microwave Oven Transformer) with the secondary replaced by few turns of heavy wire which converts mains voltage to high welding current. This doesn’t seem like a good solution since the current comes in 100 Hz pulses which makes welding energy control very difficult. I know some SSR can only break the current at the zero-crossing-point of the mains voltage resulting in a pulse time resolution of 10 ms. I don’t think this is good enough to get a consistent result.

There are also variants which discharge a large capacitor bank through a MOSFET which seems like it would give a much higher degree of control. I also found a similar design using a car starter battery instead of capacitors which seemed even more interesting.

I don’t have any spare car batteries, instead I’ll use some high power LiPo batteries. I have a pack of 4 Turnigy 6S 20C 5Ah batteris that I could connect in parallell. This will result in a 6s4p 20C 20Ah pack capable of delivering  ~20 V 400 A continuous. It will not have any problem delivering enough current for battery tab welding in short ~10 ms pulses.

The main focus of the build was to use as much parts from my junk-bin as possible.

Electrodes

The electrodes are built om 10 mm copper rods sharpened in one end and threaded with an M10 thread in the other. On the threaded end a 25 mm² welding cable are connected. To set off the welding pulse I have placed a small button on the top of one electrode.

Electrode
Left hand electrode, a sharpened 10 mm copper rod
Trigger
Right hand electrode with trigger placed for thumb activation

Electronics

To switch the current I found six FDP8440 MOSFETs rated at 40 V with a very low RDSon of 2.2 mΩ. If the welding current reach 1200 A they will handle 200 A each resulting in ~90W losses. This will easily be handled for a few hundredths of a second every 10 s or so. Especially since they are mounted on a thick copper busbar.

The control circuit semi-temporarily built on a Veroboard
The control circuit semi-temporarily built on a Veroboard

The mosfets will be controlled by a Microchip TC4421 from a 8-bit PIC microcontroller. Haven’t used a 8-bit PIC in ages, nowdays i prefer ARM Cortex-M processors, mainly the STM32 and LPC series. Since I’m building this on a veroboard I needed a DIP-casing so I decided to use an ancient PIC16F648A from the junkbin. This processor was perfect for a quick job like this, extremely simple keeping the datasheet reeding to a minimum

Spot welder schematic
Spot welder schematic

It has an internal 4 MHz 1% oscillator which will work fine for this application since there are no asynchronous communication, and 1% precision of the pulse timing is more than enough, no need for an external crystal oscillator. The reset-pin can be turned off with the config bits and all I/O-pins on Port B have internal pull-ups saving me a few resistors.

To program the processor I used Microchip MPLAB X IDE, XC8 compiler, and a PICkit 2 programmer. I’ve never used MPLAB X before, but it worked rather well. This is the application firmware, perhaps a little bit overdone, but why not?

The pulse length is currently hard coded in the application, it’s easy enough to update. If needed i will later add a switch with a few presets. The microcontroller has no A/D-converter, otherwise a potentiometer for setting this would have been nice.

A 6 S LiPo used as a power source discharging in a 3,3 ohm power resistor.
A 6 S LiPo used as a power source discharging in a 3,3 ohm power resistor.

There is a lot to read about pulse welding online, essentially the first pulse is to break any oxide layers and the second performs most of the welding. I have set pulse 2 to 10 ms, and pulse 1 to 1,25 ms which works fine for 8 x 0,18 mm Nickel strips.

I haven’t received the nickel strips I ordered yet, so my first test subject was some pieces of box cutter blades. It worked perfectly, but perhaps I need to shorten the pulses a little with the much thinner nickel strips.

Top side of welded knife blades
Top side of welded knife blades
Bottom side of welded knife blades
Bottom side of welded knife blades

Future plans

I will use this to build a few batteries, if the design works well, I’ll probably make a new PCB with a display, rotary encoder and a more modern processor.

Battery bag for my E-Bike

Last weekend we borrowed a sewing machine to make new curtains for the apartment. When I was sewing the curtains I realized that It wouldn’t be very difficult to make a custom battery bag for my e-bike. I would like a bag that I could mount in the frame triangle and have room for 4 Turnigy 6S 5Ah batteries. Doing some measurements, calculations and drawing I came up with this design

Battery bag drawing
An outline of the battery bag, the red triangle is the frame, the blue rectangles are batteries and the gray rectangle is the controller mounted on the frame.

I went to the fabric store and found a black nylon fabric that had a PVC layer on one side. This should be fairly water resistant and I plan to spray it with some textile waterproofing spray as well. I was recommended to use a thread for furniture which is much stronger than ordinary thread as well. A couple of hours thinking, cutting, and sewing later:

Battery bag
I use some Depron in the bottom, and some foam in the two corners to protect the batteries and fill out the bag.
Zipper
The zipper has a bit of fabric folding over it for water protection
Hole for cable
The hole for the cable is also waterproof since the side of the bag overlaps ~10 cm where the cable comes out.
Cable
I'm using the cable I made for the E-Puch. This cable is for two turnigy batteries in series and two in paralell with a 60A fuse. The LEGO part is just for size reference.
Packed
Everything fits nicely inside the bag

The bag fits perfect on the bike!

Battery bag on bike
Battery bag on bike
Battery bag in frame
Battery bag in frame

Pleas write a comment if you think I should make some kind of drawing and description on how to make a bag like this.

Have somebody seen my magic smoke?

A little while since the last post, this is maybe old information if you have read my posts on Endless Sphere or the Swedish Electronics Forum. We played around for the whole weekend with the moped until the motor got enough. My guess is that several hard accelerations during a short period of time heated the stator enough for the insulation to melt.

The black insides of a BLDC motor
The black insides of a BLDC motor

Not pretty! I’m afraid I’ll have to torment my hands with another rewind. A member on SEF is good enough to donate a large roll of 1,5 x 2,5 mm flat copper wire to me which I will use for the rewind. I have three different actions to prevent this from happening again.

  • Increase the gear ratio. Less torque on the motor means less current.
  • Increase kv, one less turn of copper wire will increase kv to match the higher gear ration and reduce the resistance. It will also leave more room for air to flow through the motor
  • Forced cooling, I’ll put a fan in one end of the motor to force more air through.

I’ve also ordered a spare motor from china. The 80-100 is very hard to get nowdays, but I found a 80-85 motor with the same mounting profile and axle. But i’ll keep a close watch on the stock of the 80-100 motor.

First testrun of the E-Puch

Today I’ve made the first test-run of the E-Puch. As I’ve written about before it is an old ICE moped that I’ve removed the engine and replaced with an electric BLDC outrunner.

Today, me and my brother threw everything together for a quick testrun just to see that everything works, and try out the performance.

E-Puch ready for testrun
E-Puch ready for testrun

I will soon write a post about the motor controller which I ordered from a guy named Lyen on the Endless Sphere forum. It is currently set to limit battery current around 40 A, but I think I could increase the current limit by 50% without any modifications. Which would give 50% more torque.

Controller temporarily mounted to the frame
Controller temporarily mounted to the frame

The motor is mounted on two 5 mm aluminum sheets that are bolted in the original motor holes in the frame.

Motor and motor mount
Motor and motor mount, I think I'll remove the axle on this side.

Except for the motor and motor sprocket the drivetrain is original.

Original chain with 10 tooth front sprocket and 43 tooth rear sprocket
Original chain with 10 tooth front sprocket and 43 tooth rear sprocket

I use 4 bricks of 6S 5 Ah Turnigy 20C batteries mounted in 12S2P configuration. For now these are in a plastic box on the rear end of the moped.

Temporary battery box
Temporary battery box

And at last a video of my father trying the moped.

Modifying the Turnigy 80-100 Brushless Outrunner – Part 3

Continuing on: Modifying the Turnigy 80-100 Brushless Outrunner – Part 2

As I’ve written before I had problems getting the Turnigy motor to run in sensored mode using the modified cheap-o eBay controller. Just to se if It’s the controller that is the problem I’ve tried the motor with my e-bike controller.

SUCCESS!

It works perfect! Turns slow and have lots of starting torque. I didn’t try more than 15%-20% throttle and the battery was empty in my current meter so I could’t measure the current. I will try full throttle and measure the current as soon as I’ve got a new battery.

The motor looks much neater with the internal sensors than the external I think I’ll paint it black to match the black moped when I’ve epoxied the stator and not going to take it apart again.

Turnigy 80-100 with internal sensors
The motor looks much better with the sensors mounted internally

Compared to the externally mounted sensors

Sensors mounted in bracket
Sensors mounted in bracket

Modifying the Turnigy 80-100 Brushless Outrunner – Part 2

Continuing on: Modifying the Turnigy 80-100 Brushless Outrunner – Part 1

This is a picture of the rewound stator. As described un the previous post the stator is now wound for ~90 rpm/V using double 1.5 mm copper wire. To hold the windings in place I use some dabs of low temperature heat glue. This will most certainly melt if I would put 3 kW of power through the motor, but I will replace the heat glue with high-temp epoxy when I know that everything works.

Rewound stator
The stator has been rewound with double strands of 1.5 mm copper . The heat glue is just to hold the windings in place while testing. Before using the motor under heavy load, the heat glue will be replaced by epoxy.

The motor is wound as an Distributed LRK (DLRK) and terminated in Y-mode. Using the notation from the picture below, S1, S2 and S3 are connected to the motor controller and E1, E2 and E3 are soldered together inside the motor.

DLRK
The DLRK winding scheme. I've connected E1, E2 and E3 together and use S1, S2 and S3 as phase wires for a Y-termination. The sensors are mounted between 1 & 2, 5 & 6 and 9 & 10.

In the previous post I used ATS177 sensord mounted in a bracket outside the motor. This didn’t work very well with the modified controller. This itme I will try SS441A hall sensors, which are more expensive but thats the sensor that is usually recommended on the Endless Sphere Forum. I will also try to mount the sensors inside the motor which I hope will  be more robust and better looking. The sensors are mounted between slot 1 & 2, 5 & 6 and 9 & 10. Which gives them 120° spacing. To hold them in place before applying epoxy I use the same low-temp heat glue and a little kapton tape.

Sensor in stator slot
The sensors is mounted between two teeth of the same phase on the motor, all three sensors are 120° apart. To hold them in place I applied a small dab of hot glue and some kapton tape (the brownish tape in the image)

When I tried this setup with the modified controller it still didn’t run in sensored mode which leads me to suspect that there may be something wrong with this controller. I didn’t have time to do any thorough investigations why but my next step will be to inspect the sensor signals on the oscilloscope and try the motor on my other controller which doesn’t run at all without sensors.

Continue to: Modifying the Turnigy 80-100 Brushless Outrunner – Part 3

Replace phase wires on Nine Continent 2809 hub motor

The original phase wires (wires between the motor and controller) on my E-bike are way to thin for the currents they are handling. When I got the motor was equipped with 2 m long 1,5 mm² cables. In low-speed-high-torque situations for example steep hills or starts from a standstill the currents in the phase cable can be several times the battery current. My controller limits the battery current to 27 A but the phase current could sometimes approach 100 A. Doing some calculations with the resistivity ρ=1.68•10-8 Ωm giving the original cables a resistance of

[latex]
\frac{1.68\cdot 10^{-8}}{1.5\cdot 10^{-6}} = 0.0112 \: \Omega/m
[/latex]

Judging by the color I’m not really sure that the original cables are made of copper. They could just as well be made of some other metal which would result in even higher resistance. With the 2 m cables the current path to/from the motor is 4 m and the resistance (excluding the motor resistance) is about

[latex]
0.0112 \cdot 4 = 0.0448 \: \Omega
[/latex]

This may seem pretty low but when constantly running 100 A through this cable the voltage drop on the cables will be ~4,5 V and the losses will be about 450W. This would of course instantly cook the cables and luckily enough the current to the motor is not constant and this current levels will only appear for short periods of time at very low speeds.

Anyways, I decided to replace these cables for the thickest I could fit into the axle where the cables are fed into the motor, as well as shortening these cables as much as possible. What I’ve read is that 12 AWG cables (3.31 mm²) is the thickest you could get through the axle without stripping the insulation and adding something thinner. The original cables have a PTFE insulation which I think is a good idea since PTFE cables generally have thin insulation and is very resistant to heat and mechanical wear. I ordered a couple of meters of 12 AWG PTFE cable from Apex Jr which was tho only place I could find that sold this dimension of wires online in small quantities. This cables are definitely made of tin plated copper which can be seen on the cut surfaces.

Comparison of original and new phase wires
Comparison of original and new phase wires

Doing the same calculations with the new shorter and thicker cables

[latex]
\frac{1.68 \cdot 10^{-8}}{3.31 \cdot 10^{-6}} \cdot 1 = 0.005 \: \Omega
[/latex]

This will result in a voltage drop of 0.5 V and 50 W losses at 100A which is much more manageable. I guess this will give me some additional efficiency but its probably unnecessary with the current performance of my controller. Later this summer there will probably be a post about re-programming current limits and eventually upgrading the MOSFETs of my controller.

Taking the motor apart was easy, I first removed the side cover on the cable-side by removing the nine hex screws and then used a knife to cut the glue and pry the cover off. Before I did this I made a mark on both the cover and the hub so I can put it back exactly the same way. I’m not sure what tolerances are used when manufacturing these but I don’t want to risk a wobbly wheel.

Inside the 9C 2807
This is what the motor looked like when one of the covers was removed.

Getting the wires through the axle was hard work and took me more than an hour, the method that worked for me was to put a thin wire through and the used it to pull through the phase and hall wires all at once. It helped a lot to grease the wires with soap to get them through. I kept the original hall sensor wires.

Wires through the axle
Wires through the axle

Fried connector


Fried Connector
The contacts inside this Anderson SB50 connector vaporized the first time I connected it to the controller

When I connected the modified e-bike controller for the first time a little accident happened. The Anderson SB50 connectors I use for my bike are great since they are polar and you cannot connect the battery in reverse polarity. Of course you have to put the positive and negative terminal in on the right side of the connector housing first. I missed that with the result that i connected the controller in reverse.

Since the MOSFETs conduct from drain to source through the body diode this was practically short circuiting the battery and resulted in a big spark. It was a good thing that I had a 30 A fuse on the battery lead otherwise the connector would probably lock much worse than on the picture above. The controller survived as well, probably thanks to the fuse, otherwise i think $50 worth of MOSFETs would have released the magic smoke.

Increasing the power of cheap eBay BLDC-controller

After installing sensors in the Turnigy 80-100 motor I needed a high current sensored BLDC controller. Since I’ve decided to use a 12 S LiPo battery the maximum voltage of the newly charged battery is 50,4 V with a nominal voltage of 44,4 V. Most high power e-bike controllers are designed to operate on >72 V and are quite large.

When i find the time I will build my own controller but for now, I want to modify a small 48 V 350 W controller, that I bought for $25 from eBay, into something that is a lot more powerful. The key to increase power handling capability is to decrease the heat losses under high power. As a side effect, more of the energy in the battery will be used to move the bike and less to heat the controller.

the modification is done in a couple of steps described below.

Replace transistors

The controller originally contained six STP75NF75 MOSFET which can handle a voltage of 75 V and (according to the datasheet) 75 A. The typical resistance when turned on is 10 mΩ which is quite high. Realistically I think six of these is capable of handling ~15 A continuously with decent cooling. I’m not even sure if they are genuine and 48 V 350 W will be ~7 A  so the original controller isn’t really pushing them.

Components
Close up shot of controller motherboard. You could see that I've replaced the MOSFETs with IRFB3006 and that a STM8 processor powers the controller. SOMETHING WENT TERRIBLY WRONG WITH THIS IMAGE! I WILL FIX THIS.

Instead i will use six IRFB3006 which can handle 60 V and up to 195 A (again, according to the datasheet). The silicon could actually handle up to 270 A but the wire bonds between the silicon and the case limits this to 195 A. The typical on-resistnance on these are 2 mΩ, five times lower than the original FETs! Another popular transistor to use when modding e-bike controllers is the IRFB4110 which is capable of handling 100 V but not as much current as the IRFB3006.

STP75NF75 Datasheet
IRFB3006 Datasheet

 

Controller
The controller

Beef up the PCB traces and wiring

The original high current PCB traces of the controller had some extra solder on them to increase the current capabilities. To increase this even further i added 3×1.5 mm copper wire to these traces. Compared to copper, solder is a pretty bad conductor so this will decrease losses and heating under high currents considerably.

Upgraded power traces
The PCB traces carrying high current are upgraded with 3 x 1.5 mm copper wire.

There was one problem with this, copper and PCB laminate have different Coefficients of Linear Thermal Expansion, a view from the side reveals that the board got a little curved when soldering. I hope this doesn’t break anything.

Curved PCB
The copper wires shrink when they cool down after soldering 🙁

The wimpy phase and battery wires on the original controller is replaced with 6 mm² wire instead to handle he increased current. And a lot of the special function wires on the controller are removed. I only need the throttle and brake inputs.

Modify the current shunt

When I ordered this controller I was pretty sure that it were based on the Infineon XC846 ship as most china-made e-bike controllers are. These controllers can have the current limit and many other properties changed in software by connecting your computer ti the controller. Instead this controller is based on a STM8 microcontroller, maybe this is programmable but I haven’t found any information on how.

Instead of programming I can increase the current limit by decreasing the resistance of the current shunt. The processor measures the voltage drop across a short bit of wire with a known resistance to determine how much current the motor uses. If I for example decrease the resistance of this wire to half, the current will be twice of what the processor thinks.

Current Shunt
The ordinary current shunt (the curved silver wire) are paralleled with a thicker and shorter copper wire to decrease resistance.

Today I recorded two videos running the motor. The first one is just running the motor in sensorless mode. I actually got it running once in sensored mode but as soon as I started adjusting the sensor angle the controller fell back into sensorless mode. The throttle in this video is a tired 10k trimpot hence the uneven throttle signal.

I also made a small load test just holding the motor. In this video the motor is run on the lowest speed possible in sensorless mode. The battery used in this clip had a voltage of 46 V. Since the currentmeter maxes out at 5,5 A the load power I created is somewhere around 250 W