1

Benjamin Gutierrez Alan Casallas 6.101 Final Project Report May 16, 2019

Electric Bike with Regenerative Braking

1. Abstract [by Ben Gutierrez]

An analog control system that controls the speed of a brushless DC motor on an electric bicycle and harnesses the energy during the braking process was built. To drive the BLDC motor on the bicycle, a closed-loop feedback control circuit was used. This consisted of a three phase inverter circuit, an amplifier circuit, and a commutation circuit to generate the waveforms needed to commutate and spin the motor. A feedback circuit was constructed to drive the motor at a requested angular velocity. Additionally, a regenerative braking circuit was implemented, which generated a high enough voltage to charge a battery from power delivered by the motor when the brake was applied to the bicycle wheels.

2. Introduction [by Ben Gutierrez] We designed and built a speed controller and a regenerative braking circuit for use in an electric bicycle (Figure 1). We used a brushless DC (BLDC) motor because of its advantages over brushed DC motors, including higher torque to power ratios, increased reliability, longer lifetimes, and reduced noise and electromagnetic interference.

The speed controller was designed to operate from a 7V battery. The battery voltage was boosted by a boost converter to the range of 15-30V. The boosted voltage was then sent into a regulated buck converter to supply a consistent 12V voltage source. A closed loop speed controller circuit was constructed to control the speed of the motor. It took an input from a tachometer circuit, and compared it to a reference voltage to generate a control output. A logic circuit was responsible for the commutation of the BLDC motor as well as outputting a variable frequency square wave to supply speed information to the tachometer circuit. A 6 MOSFET power amplifier circuit was responsible for supplying the amplified signals from the logic circuit into the coils of the BLDC motor. Finally, a regenerative energy boost converter circuit boosted a low voltage of 0-5V from the motor to a 20-40V DC voltage to be used to charge a battery. 2

Figure 1: A system overview of the major components ​

3. Design

3.1 Battery [by Ben Gutierrez]

Figure 2: Lithium Ion Batteries connected to a breadboard prototype of the boost converter. ​

The batteries (Figure 2) used for this project were two 3.6V lithium ion batteries rated for 2100 mAh each. The speed controller was designed to operate from a 7.2V battery. We chose this voltage range for safety and for power. This voltage was low enough to prevent excessive damage to our circuit in case something went wrong, but high enough to allow our speed controller to operate at currents that can be handled by low cost power MOSFETs.

3

3.2 Boost Converter [by Ben Gutierrez]

Figure 3: The boost converter switched by a 555 timer. For component values, see table 3 of ​ the appendix.

An unregulated boost converter (Figure 3) was used to boost the voltage from the battery to a high enough voltage so it could be regulated by a buck converter. The boost converter output voltage range was chosen to be 15-30V. This voltage range was achieved by using a 20% duty cycle. The reason this voltage range was so large is because as the load of the output increases, the voltage output decreases. However, this voltage output did not have to be regulated because regulated buck converter following this circuit was responsible for the voltage regulation.

The boost converter was designed so it could be operated from a 4.5V or higher voltage source. This voltage rating is based off the minimum supply voltage of a 555 timer. The interesting part of this circuit is that the 555 timer logic circuit and BJT gate driver is powered off of the output voltage rail. At startup the output voltage rail is 7.2V which is the battery voltage. However, when the 555 timer begins to output a square wave, the output voltage rail swings up higher until the output voltage is balanced by the load. As the output voltage increases, the gate to source threshold raises to the power mosfet, and to compensate the gate voltage increases.

4

3.3 Regulated Buck Converter [by Ben Gutierrez]

Figure 4: The regulated buck converter. For component values, see table 4 of the appendix. ​

The regulated buck converter (Figure 4) was responsible for providing a constant 12V DC power source to the rest of the circuit. This circuit was implemented with efficiency in mind. Since the circuit is operated off of a battery, a linear regulator would not be efficient.

The regulated buck converter used a closed loop PI controller to regulate the voltage. The controller gains were set experimentally by changing resistor and capacitor values. The regulated buck converter was powered using a linear amplifier, which was the largest source of inefficiency in this circuit.

5

The triangle wave generator was designed to output a 53 kHz triangle wave with a peak to peak voltage of 12V centered at 6V. Rtriangle and Ctriangle determined the frequency of ​ ​ ​ ​ the output triangle wave using the following formula:

f = 1 triangle 4×Rtriangle×Ctriangle

The differential amplifier was responsible for generating an error voltage by comparing

½ Vbuck and comparing that to 6V. The error voltage was centered about the virtual ​ ​ ground of 6V. The error voltage was positive if Vbuck was greater than the reference ​ ​ voltage, and vice versa. The reference voltage and the virtual ground both happened to be 6V, but this does not have to be the case. If a different regulated Vbuck is desired, the ​ ​ reference voltage can be changed.

The compensator was responsible for taking in an error voltage and outputting a control voltage. The compensator was Proportional-Integral controller with a proportional gain 6 of 10 and an integral gain of 6.7×10 .​ The high integral gain helps increase stability by ​ adding a pole far into the left side quadrant of the pole zero plot. The high integral gain also reduces steady state error on the order of hundreds of nanoseconds. The gains were determined from the following transfer function: R V control = − p2 − 1 × 1 V error Rp1 s Rp1CI

The control voltage was then compared to a triangle wave using a PWM signal whose duty cycle is proportional to the control voltage. The PWM output voltage is pulled up to

Vbuck using Rpullup. ​ ​ ​ ​

The PWM voltage was fed into a shoot through delay circuit in order to prevent both the high side and low side MOSFETs from being on at the same time. The shoot through delay circuit inverts the high side signal and adds a delay to each rising edge. The low side signal simply has a delay added to each falling edge. Since the lower and upper thresholds of the schmitt triggers are ⅓ and ⅔ of the supply voltage Vbuck, the shoot ​ ​ through delay is approximately:

tdelay = Rdelay × Cdelay.

The inverted and non inverted signal are then sent into a gate driver to be amplified to a higher current drive input for the gates of the switching MOSFETs. The IRF540

MOSFETs were chosen because of their low RDS(ON) of 0.077Ω and relatively low gate ​ ​ charge Qg of 72 nC. For a load of 1 A, an input voltage of 24V, and a gate drive current ​ ​ 6 of 1A, the continuous power loss was calculated to be 57mW, and the switching power loss was calculated to be 92mW.

The MOSFETs continuous power loss was calculated as follows: 2 P continuous = RDS(ON) × I load

The MOSFETs power loss was calculated as follows: Q P = V × I × f × g switching in load SW Ig

The amplified PWM through the MOSFETS was then passed into the inductor and capacitor of the buck stage. The inductor current ripple was calculated to be 1.1A, and the output voltage ripple was calculated to be 3mV. The output voltage from the buck stage was a fed back into differential amplifier of the feedback loop to be regulated. The output voltage from this stage was used to power the rest of the circuit.

The inductor current ripple was calculated as follows: (V −V ) in,max out V out Iripple = × f sw×Lbuck V in

The voltage ripple was calculated as follows:

Iripple V ripple = 8×f sw×Cbuck

3.4 Tachometer [by Alan Casallas and Ben Gutierrez]

Figure 5: Tachometer Circuit ​

7

The purpose of the tachometer circuit was to provide a DC voltage proportional to the motor speed. Essentially the circuit would take a variable frequency input and would output a DC voltage proportional to the frequency input. The valid range of the circuit was in between 0 Hz and 140 Hz.

As described in the Logic Circuits section, the three Hall sensor readings were used to create a single signal that changed between high and low readings every time the motor state changed. This created a square wave whose frequency was proportional to the speed of the motor. However, to compare the desired speed to the actual speed, we needed to convert the square wave into a DC signal whose voltage level was proportional to speed.

Thus, we used the tachometer circuit shown in Figure 5. This circuit accepts a variable frequency square wave as input and outputs a fixed-frequency variable duty cycle wave whose duty cycle is proportional to the input wave frequency. Then, by low-pass filtering the output, we obtained a DC signal whose voltage was roughly proportional to the instantaneous speed of the motor.

This method produced only an approximation of the instantaneous speed of the motor, because it was based on smoothing out a discrete signal that only updated when the motor changed states. However, we found that motor iterated through all 6 states after ⅙ of a rotation, meaning that the states changed 36 times for each rotation of the wheel. We were satisfied with the instantaneous speed approximation that this provided and felt it would work well towards the response time of our speed controller.

8

3.5 Speed Controller [by Ben Gutierrez]

Figure 6: Speed controller circuit. For component values, see table 5 of the appendix. ​

The speed controller (Figure 6) was responsible for controlling the speed of the motor. The speed controller operates similar to the regulated buck converter using the same proportional integral control. The triangle wave generator, differential amplifier, compensator, and comparator serve similar purposes but have different values which can be seen in Table 2 of the Appendix.

A differential amplifier compared a tachometer signal to a reference voltage generated across a potentiometer. The error signal was centered about the virtual ground of 6V. The virtual ground was generated by placing a 10K resistor and a 6V resistor in series powered from Vbuck. ​ ​

The error signal was then passed into a compensator which was responsible for generating a control voltage for a given error voltage. The proportional gain was 1, and the integral gain was 1000. The gains for the speed controller compensator were much lower for the speed controller than the gains for the buck converter because there is 9 delay in the tachometer circuit. If the gains are too high, the speed controller could become unstable. For example, the compensator could overdrive the motor too much during the delay period and then after the delay, the compensator may underdrive the motor even more to compensate overdriving the motor.

The control voltage from the compensator was then compared with a triangle wave whose frequency was 500 Hz. The result was a PWM signal whose duty cycle was proportional to the control output. This frequency was chosen to be low enough to reduce switching losses across the six MOSFETS in the power amplifier but fast enough to be faster than the fastest commutation switching time. The PWM signal was pulled at 5V using a Rpullup. The 5V voltage source was generated from a LM7805 ​ ​ powered from Vbuck. The PWM signal was then outputted into the logic circuit for the ​ ​ motor commutator.

3.6 Motor Commutation [by Alan Casallas]

One method of driving a Brushless DC (BLDC) Motor is to supply a current through two of the motor’s three leads depending on the position of the motor. There are six such unique positions, or states, of the motor. If, for a given state, current is run through the correct two leads, the motor will continue to run smoothly. The state of a BLDC motor can be determined by the output of a hall sensor that detects magnetic fields inside the motor.

To control which leads are powered in a given state, we used an array of six IRF1407 MOSFETs. For each state, two MOSFETs are turned on in such a way that current will flow in through one motor lead and out through another lead. Of course, it is vital not to allow two MOSFETs in the same column turn on at the same time, which would lead to a shoot-through situation. This six-MOSFET circuit is referred to as the commutator circuit. The drains of three MOSFETs are connected to the input voltage; these three MOSFETs are the ‘High’ MOSFETs. The sources of the three other MOSFETs are connected to ground; these are the ‘Low’ MOSFETs.

10

Figure 7: Commutation Circuit schematic ​

The acceleration of the motor is a function of the voltage supplied. To vary the voltage and control the speed of the motor, one option would be to control the voltage being supplied to the commutation circuit. Another option, however, is to supply a constant voltage to the commutation circuit and instead throttle the High MOSFETs with a high-frequency PWM wave. This will cause the MOSFET circuit to switch between a configuration where current is supplied to the motor, as seen in Figure 8(a) below, and a configuration where the motor is not powered, as seen in Figure 8(b). If the PWM frequency is high enough, the inertia of the motor will cause the behavior of the motor to act as if a constant voltage of value V*D is being supplied to the voltage, where V is the voltage supplied to the commutator circuit and D is the duty cycle of the PWM signal.

Figure 8: Commutator Circuits for a particular motor state. (a) Current paths when MOSFET ​ B_low is closed. (b) Current paths when all MOSFETs are open. Image Source: [1] 11

To open and close the IRF1407 MOSFETs we used IR2125 MOSFET drivers. The drivers were necessary because the MOSFETs gates require a high burst of current to change state quickly so as to overcome gate capacitance. We connected each driver as shown in Figure 9.

Figure 9 IR2125 MOSFET Driver Schematic. The IR2125 can accept a 5V signal, which our ​ logic circuit provides, and will output a burst of 3A to switch the state of the IRF1407 MOSFETs.

3.7 Logic Circuits [by Alan Casallas]

Hall C Hall B Hall A

State 1 ON ON OFF

State 2 ON OFF OFF

State 3 ON OFF ON

State 4 OFF OFF ON

State 5 OFF ON ON

State 6 OFF ON OFF Table 1: The Hall Sensor outputs.

The motor’s Hall sensors has five pins. Two pins are for the input power at 5V. The other three pins are the output of the hall sensor. The outputs are boolean -- they are either 5V or 0V. The three pins must be connected to a pull-up resistor to output the correct signal.

12

Each combination of hall sensor states corresponds to a unique state that requires a unique pair of MOSFETs to be turned on in the commutator for the motor to turn. The states, in order, are shown in Table 1 above. To select which two MOSFETs to turn on for a given state, we used an SN74LS138N chip. This is a multiplexer that accepts a three-digit binary input (i.e. ‘000’, ‘001’, ‘010’, etc.) and turns off one of its 8 output pins corresponding to the value of the binary input.

Initially, we made an error in the states we anticipated to see from the Hall Sensor. We mistakenly thought the hall sensor would output the binary numbers 1-6 in order. To process this output pattern, we built the logic circuit shown in Figure 10, which would take the states 1-6 and turn on the corresponding pair of MOSFETs.

Figure 10: The logic circuit. The Hall sensor outputs are on the left. They are then processed by the ​ ​ SN74LS128N chip and the array of logic gates.

Note that the first column of logic gates after the SN74LS128N chip outputs the pair of MOSFETs should be turned on. Two of the six logic gates will be turned on for every motor state. The second column of logic gates performs an AND operation of the High and Low logic gate signals with incoming PWM signals. During normal motor operation, the High PWM signal has a duty cycle proportional to the desired speed of the motor, and the Low PWM signal operates at 100% duty cycle.

However, as mentioned before, we soon discovered that the above logic circuit was incorrect because the hall sensor does not output the binary numbers 1-6 in order. Rather, as seen in Table 1, the output numbers are 1,3,2,6,4,5. Because of the error, the motor was not rotating smoothly. Rather than destroy the circuit we had created, we decided to create a ‘logic correction circuit’ that would take in the inputs of the hall 13 sensor and output the binary numbers 1-6 in order. In effect, we were taking inputs A,B,C and correcting them to A’,B’,C’. Table 2 shows the subsequent logic relations that we derived.

A’ = Cˉ Bˉ A or Cˉ BAˉ or CBˉ Aˉ

B’ = Cˉ B or CBˉ A

C’ = C Table 2: The logic of the logic correction circuit. ​

After implementing the above logic table, the circuit turned on the correct pairs of MOSFETs for every motor state, and the motor started rotating smoothly.

The other task of the logic circuit was to encode the speed of the motor for the speed controller circuit. For maximum resolution, we implemented a circuit that would switch between a high and low signal every time the motor switched states. We did this by recognizing that the Hall sensor alternates between having two sensors high or one sensor high during each state. Thus, we implemented a circuit equivalent to AB or AC or BC , which resulted in a signal that changed from low to high and vice versa every time a state changed. This signal served as an input to the speed controller circuit.

3.8 Motor Regeneration [by Alan Casallas]

We also wanted to experiment with regenerating the system battery when the motor was slowed down. This essentially involved two processes: 1) directing current out of the motor and 2) supplying that current into the battery in a safe level.

Lithium Ion batteries are most efficiently charged by following the current-voltage profile shown in Figure 11. The voltage values shown are for a standard 4.1V Lithium Ion cell. First, it is assumed the cell has not been allowed to discharge below 3V, which would imply an unsafe level of discharge that would require an especially low current level to climb out of. When the battery cell is between 3V and 4.1V, the maximum safe current can be applied continuously until the battery reaches its nominal voltage. Once that voltage is reached, the battery can continue to be charged, but cannot continue to take the constant current previously supplied. Instead, the battery should be provided its 14 constant nominal voltage, and it will draw an exponentially decreasing current as it continues to charge. Once it is drawing 10% of the maximum current, charging can be stopped.

Figure 11: Lithium-Ion Battery Recharge Cycle. ​ Image source: [2]

The system battery we decided to use for our ebike was a 48.8 V battery consisting of 12 lithium ion cells. The battery contains an internal Battery Management System (BMS) that redistributed incoming current among all 12 cells during charging to keep them safely balanced. Thus, while designing our battery charging circuits, we only needed to concern ourselves with the power and ground leads of the entire battery unit, and not the status of the 12 individual cells.

(a) (b) 15

Figure 12: Regenerative Braking Circuits for a particular motor state. (a) Current paths when ​ MOSFET B_low is closed. (b) Current paths when all MOSFETs are open. Image Source: [1]

The most effective method of directing current from the motor into the battery is by shutting off all six commutation MOSFETs. As seen in Figure 12(b), this will cause the current to travel through the flyback of the MOSFETs and into the battery. The IRF1407 MOSFETs we were using contained internal diodes that are rated to conduct 130A continuously, just as the drain to source path is. Thus, we were not concerned about blowing the MOSFETs by forcing the currents to conduct through the flyback diodes.

For the in-lab presentation, due to safety concerns, we did not actually recharge the battery, but rather connected the output of the commutator to a dummy load meant to represent the battery. When ‘braking’ the bicycle, we shut down all six MOSFETs and placed a boost converter at the output of the commutator. The design of the boost converter was identical to the boost converter that boosted the voltage from the battery into the voltage regulation circuits. Most notably, its switching IC, a 555 timer, was powered by the output of the boost converter. Thus, the regenerative energy circuits can run independently of the battery. This allows us to electrically isolate the and regenerative energy circuits, and also avoided the need for a separate battery.

To demonstrate our circuit, we manually turned the bicycle wheel while the dummy load was connected and the battery was completely disconnected. An oscilloscope reading showed that with moderate manual turning of the wheel, the boost converter was able to output 30 volts, more than enough to charge the small 7V battery that we used for our demonstration. To charge the larger 48V battery we intend to use for the final product, we would need to boost to a higher voltage, which we could do with a higher duty cycle on the boost converter.

One question was how the output of the boost converter would charge the battery without exceeding the maximum safe current. This was solved by placing a resistor and a fuse in series with the output of the boost converter which allowed the output of the boost converter to charge the battery while ensuring the maximum safe current was not exceeded, as shown in Figure 13.

16

Figure 13: Simple Battery re-charging circuit, where the voltage source on the left represents ​ the output of the boost converter.

The resistor would be designed to limit the current that could be supplied to the battery. For example, say we must not supply more than 3A to the battery (as is the case for the larger battery). Furthermore, say we are clamping the boost converter voltage to be a maximum of 48 V using a zener . Then, we would choose a resistor value of (48V-30V)/3A=6 ohms, since we are assuming the battery will not be discharged to a value of less than 30V.

Note that using this simple battery charging, once the battery voltage rises to 48V, no current would flow into the battery since the boost converter is clamped at 48V. Thus, the battery would not completely charge, since the battery must draw current at a constant 48V for some time to finish charging. Thus, although the above circuit is safe, it will not completely charge the battery.

Furthermore, it is not necessary to have a separate boost converter as we did in the project we built. As seen in Figure 8, the motor can be represented as a voltage source and inductor, and the paths the current take from the motor to battery involve diodes and MOSFETs. Thus, if a PWM signal is applied to one of the LOW MOSFETs to switch between the circuit shown in Figure 8a and the circuit shown in Figure 8b, we have effectively created a boost converter, and are only missing a capacitor between the output of the commutator and the battery. Thus, further work for our project could involve using the commutation MOSFETs to create a boosting effect on the output voltage of the motor.

The most efficient battery charging circuit would involve a circuit that supplied a constant current into the battery when it is below is nominal voltage, and then provides a constant voltage when it has reached its nominal voltage. The circuit shown in FIGURE 14 is such a circuit. Future work on the electric bicycle can include implementing this circuit. Since this circuit is capable of charging the battery fully, we 17 need to implement a feedback component that would track the current being drawn by the battery and shut down supply of current when the battery current draw falls below a certain threshold (for the larger battery, such a threshold would be 0.3 A).

Figure 14: Proposed Constant Current and Constant Voltage Circuit ​ Image source: [3] ​

4. Results [by Alan Casallas]

The forward drive functionality of our system was demonstrated in a live demonstration (figure 18, figure 19) in which a BLDC-driven wheel attached to a bicycle frame was driven continuously when we connected the lithium ion batteries to the circuit. Furthermore, we controlled the speed of the wheel using a potentiometer. To demonstrate the behavior of our feedback control circuit, we connected two signals to an oscilloscope: 1) the ‘desired speed’ input voltage coming from the potentiometer and 2) the ‘actual speed’ output voltage coming from the tachometer. As shown in Figure 15, when we turned the potentiometer, the motor speed lagged behind the desired speed for a brief instant before the motor speed changed and matched the desired speed.

18

(a) (b) Figure 15: (a) Voltage signals representing desired (green) and actual (yellow) speed. This ​ image was taken instantly after changing the potentiometer that controlled the speed controller input. (b) After less than a second, the desired speed successfully tracked the actual speed.

Due to safety concerns, we did not directly charge the batteries with the motor to demonstrate regeneration. Rather, we connected a dummy load resistor across the output of the regeneration boost converter and measured the voltage produced with an oscilloscope. As shown in Figure 16, when we manually turned the wheel, the output of the commutator signal was a DC voltage at about 2V. The boost converter increased this to 30V, which would be more than enough to charge the 7V batteries.

Figure 16: While manually turning the motor wheel, the input to the boost converter (green) ​ reached 2V, while the output (yellow) reached 30V.

19

Figure 18: 1000W BLDC motor that was driven that was used in this project ​ 20

Figure 19: Physical implementation of circuit spread out across table along with the bike that ​ was used.

21

5. Conclusion [by Alan Casallas]

We were successful in achieving our expected goals and creating a prototype ready for improvement and future work. We were satisfied with the response and performance of our speed controller and demonstrated it responding to our input in a live demo. We were also satisfied with the fact that the logic circuit used logic gates rather than a microcontroller. The use of gates allows for faster switching of states than a microcontroller would achieve, thus switching to the correct MOSFET configuration faster and improving motor energy efficiency.

Furthermore, we were pleased to see DC voltage produced from the motor and across the dummy load. This offered a proof of concept for energy regeneration. If we decided to include regeneration in our actual electric bicycle product, we will use a mechanical switch to switch between the forward drive and regeneration circuits, as well as a fuse to ensure electrical safety when charging the circuit.

Our next steps will be to introduce a more powerful, 48V 2000W battery to drive the bicycle and recreate the circuit as compact PCB boards. Our intention will be to create a fully functional electric bicycle for our use and experimentation.

6. Acknowledgements [by Benjamin Gutierrez and Alan Casallas] The authors would like to thank Gim Hom for his excellent teaching over the course of the semester. The authors would also like to thank Jimmy Tran and Henry Love for their help in the lab. Last but not least, the authors would like to thank Clair Travis for providing dinners while working on the project.

7. References 1. “REGENERATIVE BRAKING IN AN ELECTRIC VEHICLE”, Cody et. al., University of South Australia

2. “ A Designer's Guide to Lithium (Li-ion) Battery Charging” https://www.digikey.com/en/articles/techzone/2016/sep/a-designer-guide-fast-lithium-ion- battery-charging

3. “How to Design a Simple Constant Current/Constant Voltage Buck Converter” http://www.ti.com/lit/an/snva829/snva829.pdf

22

8. Appendix

Component or Signal Value

R 10Ω ​gate ​ L 250uH ​boost C 1000uF ​buost V 7.2V ​battery V 15V-30V ​boost Table 3: Component and signal values for regulated boost converter ​

Component or Signal Value

R 1K ​triangle C 0.47nF ​triangle R 1K ​p1 R 10K ​p2 C 0.15nF ​I R 10K ​pullup R 1K ​delay C 1nF ​delay C 1uF ​boot R 10Ω ​gate ​ L 100uH ​buck C 1000uF ​buck V 15-30V ​boost V 12V ​linear V 12V ​buck Table 4: Component and signal values for regulated buck converter ​

23

Component or Signal Value

R 5000K ​triangle C 0.1uF ​triangle R 10K ​p1 R 10K ​p2 C 1.5nF ​I R 10K ​pullup V 12V ​buck Table 5: Component and signal values for speed controller ​