Design of Electric Bicycle Controller

This article introduces a sort of intelligent brushless DC motor driver and its concrete application in electric bicycle, and discusses the hardware and software design scheme of the controller, and realizes the speed control, over-current protection and battery under-voltage protection of the brushless DC motor. And the experiment result indicates that the control effect is good, and it could fulfill the application requirement of electric bicycle.


Performance characters of MCU
LPC2114 is the 16/32 bits ARM7TDMI-S CPU based on real-time simulation and follow with embedded high-speed Flash memorizer of 128/256KB.The memorizer interface with 128bits width and the special speedup structure make 32bits code run under maximum clock velocity.The application which strictly controls the code scale can reduce over 30% of code scale by 16 bits Thumb mode, and the loss of performance is very low.
The MCU has good stability, and its PWM (Pulse-Width Modulation) output function saves peripheral circuit and work time of MCU.Multiple A/D ports are integrated in the interior, which can fulfill the requirement that the system acquires many simulation signals such as rotate speed signal and current feedback signal.Abundant interrupt resource can exactly collect the phase information of motor, and realize the conversion of work mode.Multiple 32bits timers, 45 high speed GPIO and 9 marginal or level springing exterior interrupt pins will make the MCU specially be applicable in the industrial control system.

Work principle of brushless DC motor
Because of the use of mechanical brush, a series of problem such as mechanical friction, noise, electric spark and wireless interference in the traditional DC motor, and in addition, high making cost and difficult servicing also largely limits its application range.
The brushless DC motor utilizes electric commutator to replace the mechanical brush and mechanical commutator, and keeps the excellent character of brush DC motor, and eliminates the advantages of brush and commutator.Because the brushless DC motor has many advantages such as simple structure, reliable performance, high efficiency and convenient maintenance, so it is the most perfect drive motor of electric vehicle.Comparing with other motors, its main advantages include (1) good exterior character of motor, which can make the motor possess low-speed large torsion character, (2) width speed range, which can make the motor run in any rotate speed with full power, (3) high motor efficiency, and the light load will keep higher efficiency, (4) strong over-load ability, (5) good regenerated braking effect, (6) small motor volume and light weight, (7) without mechanical commutator, and high reliability, (8) the motor control system is simpler than asynchronous motors.
The brushless DC motor is usually composed by the principal part of the motor, the rotor position sensor and the power switch circuit.Figure 1 is the principle frame chart of the brushless DC motor.The Hull sensor in the figure is the rotor position sensor, and its function is to detect the position of the motor rotor, offer the position information of rotor for the electric commutator, and realize the electric commutation without touching.
The inverter of the switch circuit in the figure adopts three-phase and six-beat break-over mode, and in each moment, there are two phases to be broken over, and the other phase doesn't break over, and the winding of each phase will continually be broken over by 120 0 electric angle, and the stator winding current will change phase once in each 60 0 electric angle.The motor character circumrotates in 360 0 electric angle clockwise, and the state characters of three-route position sensor signal change from 101-100-110-010-011-001.The time that the state characters change is the time that the stator winding current will change phase.
The I/O ports of MCU could be taken as the inverter upper and lower bridge arm control ports to realize the control of phase change.The inverter adopts three-phase star structure, and it is composed by six MOSFET pipes with N channels, adopts the NAND gate to realize the hardware locked logic of upper and lower arms and ensure that the upper bridge arm and the lower bridge arm will not break over in same phase.The upper bridge arm drive is composed by voltage-ascending circuit and dynatron drive circuit.When failures occur in the system, MCU locks the three-phase upper and lower bridge arms of the inverter through the control character, and the motor will stop to run.

Hardware design of controller
The design idea includes that the system adopts three switch-type Hull sensors to be the position sensors which send the position signals of motor rotor to the I/O port of MCU.The main control chip comprehensively controls the motor according to the designed software or signals inputting from the rotor handle and the voltage and current values tested, and the MCU transmits PWM signals and control the work current of motor through the dutyfactor of PWM signals, and accordingly realize the control of speed.The system uses the inverter to realize the phase change of motor.
For the control of main control chip, three Hull components in the brushless DC motor detects the position of the rotor, and transmits this signal to the MCU to produce interrupt, and the MCU inquires the table and finds out two phases which should break over at the next moment according the Hull signals, and transmits the signal to the driver bridge of MOSFET through PWM output port, so the breaking over or shutting off of MOSFET are controlled.At the same time, MCU computes the time difference between each two continual Hull signals through the counter in the chip to obtain the rotate speed of the motor, and finds out the difference between the reference speeds obtained from the rotor handle with the rotate speed, i.e. the speed error.Implement PI modulation to the speed error and output the reference current.Obtain the actual current from sampling resistance, and implement PI modulation to the current, output PWM wave to corresponding MOSFET breaking over, and modulate the motor rotate speed through changing the dutyfactor of PWM, so the double closed loops speed modulations of speed loop and current loop are realized.
The whole controller takes the LPC2114 MCU as the control core, and it acquires various signals (such as the speed modulation signal, the phase change signal of Hull sensor, the voltage signal of the storage battery and the current signal of motor) to dispose according to enacted control mode, and outputs control signals.The signals acquired by the MCU mainly include following sorts.
(1) The signal of Hull sensor.Three-route signal can be directly connected through resistance pulling-up and capacitance filtering, and when the corresponding Hull signals changes, the motor control unit will spring the zero-pass interrupt and phase-change accident, and close and open corresponding power MOSFET through catching the register value of signal edge, and in such cycle, the system could control the connection and breaking of three-phase winding to realize the running of the motor.
(2) The Hull rotor handle signal.The rotor handle signal is a simulation voltage signal, and the rotate angle is in direct ratio to voltage.The AD sampling value of the signal corresponds with reference rotate speed, and the voltage modulation and speed modulation could be realized by modulating the chopping ratio.
(3) The current signal.The main loop current signal of motor is acquired by the sampling resistance.The current signals are amplified by the operation amplifier in the chip, and the output pin connects with AD interiorly, and it can sample the current, and it also connects with one port of the comparer in the chip, and the other port of the comparer connects with the over current reference voltage, and when the current is too higher, it will spring the over-current interrupt.The peripheral circuit in this part is simple, and it only needs resistance and capacitance to realize the current amplifying sampling and over-current protection.
(4) The input of accident.Under the loading condition, the instant pinnacle current will bring impact to the motor when the motor starts up or meets accidents, and the users of electric bicycle will feel uncomfortable.So input the voltage signal of current into the comparer, and when the pinnacle current occurs, the comparer outputs the negative pulse, and the hardware will automatically stop the PWM output, and spring the interrupt to dispose.
(5) Other signals.The brake signal is the switch signal.When braking, the high level is effective, and when MCU reads in high level, it stops PWM outputs and implements corresponding disposal.For the under-voltage signal of the storage battery, the batter voltage meets with AD in the MCU through voltage division, and the voltage is supervised by MCU.When the battery voltage is under 43V, the system gives under-voltage signals and outputs cut-off to prevent the damage of the battery because of over-discharge.

System software design
The software design is the important part of the system design, and it controls various functions with MCU together, and the software design in the system is composed by the main program and the interrupt service subprogram.The software design adopts modularization programming idea and the structured programming idea.
The main program mainly includes the part of initialization and the part of cycle main body (seen in Figure 2).Where, the part of initialization includes the initialization of system resource and the initialization of various variables.The part of cycle main body mainly includes A/D sampling rotor handle signal and the voltage of power supply, reading brake signal to disposal and double closed loop speed modulation, and the main program will first inspect the voltage of storage batter and the brake signal in every cycle, and inspect whether there is stopping signal after every speed modulation ends.The over-current control is divided into two sorts in the program.For the type 1 of over-current, the present current exceeds the rating work current, but it is smaller than the enacted type 2 of current (failure current), and here if only properly reducing the output of PWM, the loop current will be reduced, and the disposal program is in the closed loop speed modulation.For the type 2 of over-current, the present current exceeds the enacted failure current, and the hardware forbids the output of PWM, and inspects the current continually, and when the current is smaller than the rating current, the hardware will make PWM output, and this program is in the interrupt disposal of accident, and this sort of current control method could better protect the current, avoid the situation that the current increases suddenly and stop immediately, and make the whole system more comfortable and conveniently to use.The interrupt service subprogram mainly includes voltage zero-pass interrupt, phase-change interrupt and serial interrupt.The zero-pass interrupt mainly feels the change of Hull sensor signal, and offers time interval of rotor in each 60 0 electric angle to measure the speed.The hardware of phase-change interrupt springs the connection and closing of the corresponding power pipe and pre-writes the register value at next phase-change.The serial interrupt program is used to communicate with the host computer.

Notices
In the design of the electric bicycle controller, we find following problems and implement corresponding treatments to them.
(1) The confirmation of sampling time for the brushless motor controller of electric bicycle The brushless motor should exactly test the position of rotor permanent magnet, and use the electric switch to switch different winding to obtain sustainable drive.The system uses three switch Hull sensors to test the position of permanent magnet relative to the stator loop, and the controller outputs corresponding control signals to drive the electric switch to supply power to the motor according to six sorts of different signals output by three Hull sensors, which is the so-called six-step phase-change method.From the principle of motor, the phase-change must be timely, or else, it will induce out-of-step of motor, and the motor noise will increase, and the efficiency will reduce and the motor and the controller will be burned.At the maximum rotate speed, electric phase changes the phase in about every 1.2ms, and according to the actual using effect, the software should detect the change of phase-change signal in about 0.12ms of the response time, and output the phase-change drive signals.Considering the phase-change signal input to the MCU is easy to be interfered, and the influence of filtering capacitance on the line, the MCU program should continually read three times at least when reading the phase-change signal, and when three times signals are completely consistent, the value can be adopted as the true value of phase-change signal, which is the phase demodulation.After the phase change signal is acquired, we compare the vale with the last value, and if they are same, there is no phase-change, and if they are different, a corresponding drive signal should be acquired according to the value to drive the electric switch.We can use the item comparison method and the table query method to realize this process.Because the table query method is quick, so we adopt the table query method in this design.
(2) The smoothness problem of speed modulation for electric bicycle Because of the use of DC power supply, the speed of the motor should depend on modulating the voltage of the two ports of the motor to modulate, and the simple method is to use the PWM pulse width modulation to modulate the voltage of the two ports of motor.The work period of PWM should be selected according to the using environment of the motor, and too low frequency will produce high frequency noise that human ears can listen obviously and the

Figure
Figure 1.Composing of Brushless DC Motor