Professional Documents
Culture Documents
Abstract
This application note describes a controller for a 200 W, 24 V Brushless DC (BLDC)
motor used to power an e-bike (i.e., electric bicycle). The design uses Zilog’s
Z8FMC16100 MCU and associated circuitry to implement motoring control, regenerative
braking, and fault protection.
Note: The source code file associated with this application note, AN0260-SC01.zip, is available
for download on zilog.com. This source code has been tested with version 5.0.0 of ZDS II
for Z8 Encore! XP MCUs. Subsequent releases of ZDS II may require you to modify the
code supplied with this application note.
Features
The main features of this high-torque motor control application include:
• Hall sensor commutation
• Motor speed measurement
• Potentiometer-adjustable motor speed
• Open-loop or closed-loop speed control for precise speed regulation
• Protection logic for over-voltage, over-current, and thermal protection.
Discussion
The Z8FMC16100 MCU features a flexible Pulse Width Modulation (PWM) module with
three complementary pairs or six independent PWM outputs supporting dead-band opera-
tion and fault protection trip input. These features provide multiphase control capability
for a variety of motor types and ensure safe operation of the motor by providing pulse-by-
pulse or latched fast shutdown of the PWM pins during fault condition.
The Z8FMC16100 MCU features up to eight single-ended channels of 10-bit analog-to-
digital conversion (ADC), with a sample and hold circuit. It also features one operational
amplifier for current sampling and one comparator for over-current limiting or shutdown.
A high-speed ADC enables voltage and current sensing, while dual-edge interrupts and a
16-bit timer provide a Hall-effect sensor interface.
A full-duplex 9-bit UART provides serial, asynchronous communication and supports an
option for the Local Interconnect Network (LIN) serial communications protocol. The
AN026004-0413 Page 1 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
LIN bus is a cost-efficient single Master, multiple Slave organization that supports speed
up to 20 kbps.
The Z8FMC16100 MCU has a rich set of peripherals and other features such as: additional
16-bit timer with capture/compare/PWM capability, SPI, and I2C Master/ Slave for serial
communication, and an internal precision oscillator.
The single-pin debugger and programming interface simplifies code development and
allows easy in-circuit programming.
A block diagram of the Z8FMC16100 MCU is shown in Figure 1.
Up to 16 KB 8-Channel
Flash 10-Bit ADC
20 MHz
512 B SRAM
eZ8 CPU VBO/POR
2
I C, SPI, and and Reset
UART with LIN Control
Internal
Watchdog Single-Pin
Precision
Timer Debugger
Oscillator
AN026004-0413 Page 2 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
turned on to allow current flow back to the battery, while the lower MOSFETs are turned
off.
Hardware Architecture
In a Brushed DC motor, commutation is controlled by brush position. In a BLDC motor,
however, commutation is controlled by the supporting circuitry. The rotor's position must
therefore be fed back to the supporting circuitry to enable proper commutation.
Two different techniques can be used to determine rotor position:
Hall Sensor-Based Commutation. In the Hall sensor technique, three Hall sensors are
placed inside the motor, spaced 120 degrees apart. Each Hall sensor provides either a High
or Low output based on the polarity of magnetic pole close to it. Rotor position is deter-
mined by analyzing the outputs of all three Hall sensors. Based on the output from hall
sensors, the voltages to the motor's three phases are switched.
The advantage of Hall sensor-based commutation is that the control algorithm is simple
and easy to understand. Hall sensor-based commutation can also be used to run the motor
at very low speeds. The disadvantages are that its implementation requires both separate
Hall sensors inside the motor housing and additional hardware for sensor interface.
Sensorless Commutation. In the sensorless commutation technique, the back-EMF
induced in the idle phase is used to determine the moment of commutation. When the
induced idle-phase back-EMF equals one-half of the DC bus voltage, commutation is
complete.
The advantage of sensorless commutation is that it makes the hardware design simpler. No
sensors or associated interface circuitry are required. The disadvantages are that it requires
a relatively complex control algorithm and, when the magnitude of induced back-EMF is
low, it does not support low motor speeds.
When a BLDC motor application requires high torque, when the motor is running at low
speed, or when the motor is moving from a standstill, the Hall sensor commutation tech-
nique is an appropriate choice. A motor used in an electric bicycle application, for exam-
ple, requires high initial torque and is a perfect application for Hall sensor commutation.
Furthermore, two voltage application techniques can be applied, based on the configura-
tion of the supply-to-motor windings:
Sinusoidal. Sinusoidal voltage is continuously applied to the three phases. Sinusoidal
voltage provides a smooth motor rotation and fewer ripples.
Trapezoidal. DC voltage is applied to two phases at a time, and the third phase remains
idle. Trapezoidal voltage is less complex to implement. The idle phase is generating the
BEMF from the rotating magnet that passes the unenergized idle phase and provides the
BEMF zero-crossing data.
AN026004-0413 Page 3 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
AN026004-0413 Page 4 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Table 1 indicates the relationship between the Hall sensor output and phase switching opera-
tions shown in Figure 2.
Table 2 lists the rating of the motor used to develop this application.
Table 2. Motor Rating for Electric Bike BLDC Motor Control Application
Additionally, the application uses a 3-amp High Rupturing Capacity (HRC) fuse.
AN026004-0413 Page 5 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
:&-# 6 $#
07-(
07-,
0H
!
0ROTECTION 07-(
0HASE 0H
"
,OGIC 07- 07-, -/3&%4
0H
#
"RIDGE
07-(
07-,
(EAT 3INK 4EMP
0) $# "US 6OLT 6REF
!$# $# "US #URRENT
3PEED #OMMAND
#OMMUTATION
(ALL 3ENSOR
!
,OGIC
0ORT
" (ALL 3ENSOR
" 3IGNAL
(ALL 3ENSOR
# #ONDITIONING
3PEED
4IMER
#ALC
Hardware Architecture
The design involves running the BLDC motor in a closed loop or an open loop, with speed
as set by a potentiometer. As shown in the architecture diagram, the design generates
PWM voltage via the Z8FMC16100 MCU’s PWM module to run the BLDC motor.
After the motor is running, the states of the three Hall sensors change based on the rotor
position. Voltage to each of the three motor phases is switched based on the state of the
sensors (commutation). Hall sensor interrupts capture timer ticks every sixty degrees to
AN026004-0413 Page 6 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
measure the rotor speed of the motor. Other peripheral functions can be used to protect the
system in case of overload, undervoltage, and overtemperature.
The hardware is described in the following sections.
PWM Module
The Z8FMC16100 MCU contains a six-channel, 12-bit PWM module configured in this
application to run in Complementary Mode. The switching frequency is set to 20 KHz.
The output on the PWM outputs is controlled according to the inputs from the Hall sen-
sors.
The inputs from the Hall sensors determine the sequence in which the three-phase bridge
MOSFET is switched. The Duty cycle of the PWM is directly proportional to the acceler-
ator potentiometer input. The change in the duty cycle controls the current through the
motor winding, thereby controlling motor torque.
Commutation Logic
The Hall sensors are connected to ports PB0, PB1 and PB2 on the Z8FMC16100 MCU.
An interrupt is generated when the input state on any pin changes. An interrupt service
routine checks the state of all three pins and accordingly switches the voltage for the three
phases of the motor.
Trapezoidal commutation is used for this application to make implementation simple. In
this process of commutation, any two phases are connected across the DC bus by switch-
ing the top MOSFET of one phase and bottom MOSFET of another phase ON. The third
phase is left un-energized (both top and bottom MOSFET of that phase are switched
OFF).
Speed Measurement
The Hall sensor outputs are connected to to ports PB0, PB1 and PB2. One out of three Hall
sensors is used to capture the Timer0 ticks, which represent the actual Hall period for
closed loop calculations.
AN026004-0413 Page 7 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Protection Logic
The ADC module periodically checks DC bus voltage, DC bus current, and heat sink tem-
perature. If these values go beyond the set limits, the motor is shut down. These checks are
timed by Timer0 interrupt.
Software Implementation
During implementation of the software, the following actions are performed:
Initialization. Hardware modules are initialized for the following functions:
• Switch from internal to external oscillator for system operation
• Enable alternate function on respective pins for ADC, Comparator, UART, PA6 as
GPIO configured to drive LED
• Configure Timer0 to run in Continuous Mode to capture the Hall period timing
• Configure the comparator to shut down the PWM module when an overcurrent results
• Enable the Op Amp to measure the DC bus current flowing to the motor
• Configure the ADC to read analog values such as DC bus voltage, current, temperature,
and acceleration potentiometer (only one channel at a time)
• Configure the PWM module for the individual mode of operation with a 20 kHz switch-
ing frequency, control output depending on the values in the PWMOUT Register, and
drive the PWMOUT as defaulted to a low off state at Power-On Reset and at any Reset
• Configure the Reset/Fault0 pin functions as a Fault0 function
• Write-protect Flash memory
• Enable Open Loop operation (shown in the main.h file)
• Hardware control of the application, with the UART disabled
AN026004-0413 Page 8 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Interrupt. The Port B interrupt controls commutation. The Hall sensor output is read on
pins PB0:2, the software performs its filtering operation, and the switching sequence of
the MOSFET is determined. The PWM timer interrupt is used to time periodically occur-
ring tasks and for the background loop to read analog values from different channels and
average these values, update the LED indicator status, and update the read parameters on
the UART.
For a visual representation of the application, see Appendix B. Flowcharts on page 17.
Equipment Used
Testing for this application was conducted using the following equipment:
• Z8FMC16100 Series Motor Control Development Kit
• Tektronix digital oscilloscope
• Fluke multimeter
• 30 W BLDC motor
• 24 V 7 Ah battery
• Tektronix power supply
System Configuration
The system requirements on your PC are as follows:
• Windows 7 OS
• ZDS II version 5.0.0 installed
• Optically isolated USB smart cable for program download and debugging
Procedure
Observe the following steps to test the BLDC motor:
1. On the Zilog MC MDS Board, configure the following jumpers:
a. Shunt the 1–2 positions on J4, J5, and J6
b. Shunt J2 and J3
2. Set the R7 potentiometer on MC MDS Board (99C0987; contained in the
Z8FMC16100 Series Motor Control Development Kit) to the middle position to start
the motor.
3. Connect the following wires from the motor to the 3-Phase Motor Control Application
Board (contained in the Z8FMC16100 Series Motor Control Development Kit but not
shown in the schematic).
AN026004-0413 Page 9 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Test Results
Laboratory performance test of BLDC motor is as follows:
1. Minimum motor speed: 800 RPM
2. Maximum motor speed: 3200 RPM
3. Power consumption: 6 W at 3200 RPM (no load)
4. Regenerative Current at 200 RPM: 350 mA
Future Implementation
The application discussed in this document covers the motoring and regenerative braking
features for a BLDC hub motor used in an electric bike. Further improvements can be
made to the design by adding the following features:
• Controlled charging of SLA batteries by plugging to the AC Mains adaptor
• Implementing ‘Torque-boost’ functionality (through a push-switch), which will give a
boost to motor performance
AN026004-0413 Page 10 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
References
The following supporting documents are available free for download from the Zilog web-
site.
• eZ8 CPU User Manual (UM0128)
• Z8FMC16100 Series Product Specification (PS0246)
• PID Motor Control with the Z8PE003 Application Note (AN0030)
• Z8 Encore!-Based SLA Battery Charger Application Note (AN0223)
• Sensorless Brushless DC Motor Control with Z8 Encore! MC Microcontrollers
(AN0226)
• Z8 Encore! XP-Based BLDC Fan Control Application Note (AN0228)
AN026004-0413 Page 11 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Appendix A. Schematics
Figures 4 through 8 show schematic representations of each of the application’s key blocks.
P4 F1
+VDC +BUS
+BUS
5A FUSE
Q1 Q3
GATE_AH GATE_BH Q5
GATE_CH
IRFZ48 IRFZ48
IRFZ48
P1 P2 P3
PHASE_A PHASE_B
PHASE_B PHASE_C
R6 A C1 B C2 C C3
150k
+ C4 + C5 0.1uF 50V 0.1uF 50V 0.1uF 50V
V+
R2 10.0k CS+
R5 R1
10.00k 0.100 OHM
P5 R3 10.0k CS-
GND
R4
NTC 10k
Title
3 PHASE MOTOR CONTROL APPLICATION BOARD
AN026004-0413 Page 12 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
GATE DRIVE
D1 BAV19
BEMF DIVIDERS +12V
C6 C7 C8 C9
IR2101
R7 R9 R11
10.00k 10.00k 10.00k +12V D2 BAV19
VCC_33V IR2101
D3 BAV19
12V SUPPLY +12V
C14 C15 C16 C17
L1
D4 BAV19 +12V 10uF 0.1uF 0.1uF 10uF
U3
10uH 1 8
VCC VB
CH 2 7 R17 22.1 GATE_CH
C18 C19 HIN HO
C20 CL 3 6 PHASE_C
U4 R20 LIN VS
10uF 1 86.6k 10uF 4 5 R18 22.1 GATE_CL
SW 68pF COM LO
5 VIN
3 IR2101
FB
4 EN
2 R19
GND 10.0k Title
TPS61041 3 PHASE MOTOR CONTROL APPLICATION BOARD
AN026004-0413 Page 13 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
1 2 VA 1 2 VB
VC
3 4 3 4 CS+
5 6 CS- 5 6
7 8 V+ 7 8 TH
9 10 VCC_33V 9 10
11 12 11 12
13 14 CH 13 14 CL
15 16 15 16
17 18 BH 17 18 AH
19 20 19 20 AL
21 22 BL 21 22
23 24 23 24
25 26 25 26
27 28 27 28
29 30 29 30
31 32 31 32
33 34 33 34
35 36 35 36
37 38 37 38
39 40 39 40
41 42 41 42
43 44 43 44
45 46 45 46
47 48 47 48
49 50 49 50
51 52 51 52
53 54 53 54
55 56 VCC_33V 55 56
57 58 57 58
59 60 VCC_33V 59 60
AN026004-0413 Page 14 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
VCC_33V
R1
connector 2
100 D1 JP2
2 1
ANA0_M 1 2 ANA1_M
ANA2_M 3 4 PA1_OP_CN
RED -RESET PA0_OPINN PB3_ANA3_OPOUT
5 6
-RESET
PA2_CINP
DBG ANA4 ANA5
PA7_COUT
7 8
VCC_33V 9 10 GND
DBG
PC0_T0OUT
ANA6 11 12 ANA7
PWM2H
PWM2H PWM2L
PWM1L
PWM2L
13 14
PA2_CINP 15 16 VREF
PWM1H 17 18 PWM0H
GND 19 20 PWM0L
U1 PWM1L 21 22
Z8FMC16110_32 PC0_T0OUT
16
15
14
13
12
11
10
23 24
9
25 26 NC
C1 27 28
PC0/T0OUT
PA7/FAULT1/T0OUT/COUT
PA2/CINP
PWM1L
PWM2L
DBG
RESET/FAULT0
PWM2H
NC NC
R2 R3 NC 29 30 GND
R4 C2 7.5K 12.4K 0.1uF 31 32 NC
NC
PA6_CTS 33 34 PA7_COUT
10K 100pF PA4_RXD 35 36 PA5_TXD
NC 37 38 NC
GND 39 40 NC
C16 C17 NC 41 42 NC
PWM1H 17 8 PA1_OP_CN 43 44
PWM1H PA1/OPINP/CINN NC NC
0.01 0.01 PWM0L 18 7 PA0_OPINN PA3_TXDE 45 46
PWM0H PWM0L PA0/OPINN R5 10K GND
19 PWM0H VREF 6 47 48
GND 20 5 AGND NC 49 50
XOUT GND AGND AVCC -DIS_232
21 XOUT AVDD 4 NC 51 52 -DIS_IRDA
XIN 22 3 ANA0 R6 -RESET 53 54 NC
XIN PB0/ANA0/T0IN0
3
VCC_33V 23 2 ANA1 0 VCC_33V 55 56 GND
PA3_TXDE VDD PB1/ANA1/T0IN1 ANA2 C26 R7 5K
24 PA3/TXDE/SCL PB2/ANA2/T0IN2 1 NC 57 58 NC
PB3/ANA3/OPOUT PA6_CTS VCC_33V 59 60 NC
Y1 VCC_33V C20 10uF ANA6
2
PB4/ANA4/CINN
1 3
PA6/CTS/SDA
1
22pF
22pF 20MHz GND
2
25
26
27
28
29
30
31
32
1 2
to the pin 5, AGND. 3 4
Connection between AVCC and VCC_33V 5 6
R8
PA4_RXD
PA6_CTS
PA5_TXD
100 D2 7 8
ANA7
ANA6
ANA4
2 1
should be done as close as possible GND 9 10 VCC_33V
to the pin 4, AVCC. 11 12
LED YEL 13 14
R9 49.9K GND VCC_33V
PA4_RXD 15 16
PA5_TXD 17 18
PA6_CTS 19 20
C6 12pF
21 22
23 24
25 26 GND
J4 27 28
R10
ANA5
100 D3 HEADER 3 29 30
R23 10K
2 1 31 32
VREF 33 34
LED GRN VCC_33V 35 36
37 38 VCC_33V
39 40
LOCAL/ MDS
1
2
3
41 42
VCC_33V R11 10K 43 44
C21 ANA2 ANA2_M R12 10K 45 46
J5 R13 10K 47 48
100pF HEADER 3 49 50 GND
51 52
R14 R15 C22 53 54
10K 10K GND 55 56
100pF 57 58
ANA1_M 59 60
1
2
3
PC0_T0OUT -RESET
ANA1
HEADER 30x2/SM
10
J6
2
4
6
8
HEADER 3
J1
ANA0_M
HEADER 5X2 Z8FMC16 AND MDS CONNECTORS
S1 S2
DIRECT ION C23 C24 C25
SW SPDT SW SPDT
1
2
3
1
3
5
7
9
AN026004-0413 Page 15 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
VCC_33V
P1
C7
19
2
3 C8 U2 0.1uF
1 VCC_5V 0.1uF 2 3
CONSOLE
VCC
C1+ V+ GND
PWR JACK + C9 P2
4 C1-
C10 1
0.1uF 100/10 5 C11 6
C2+ 0.1uF TXD0 2
C12 6 7 CTS0 7
0.1uF C2- V- RXD0
U3 3
SPX2815AU-3.3 8
3 2 VCC_33V PA5_TXD 13 17 4
VI VO VCC_33V PA5_TXD T1IN T1OUT
9
GND
GND 12 8 5
R16 T2IN T2OUT
+ C13 R17 0
change p inout C14 680 DB9 Female
1
PA6_CTS 15 R1OUT R1IN 16
100/10
0.1uF PA4_RXD 10 9 USER
PA4_RXD R2OUT R2IN
2
D4
1
LED 3.3 O K EN
14
GND
NC
20 SHDN NC 11
18
GND SP3222EBCA
VCC_33V
GND
R18
10K
U4A
14
74LVC04/SO
U4B -DIS_232 1 2
14
74LVC04/SO
7
3 4 J2
1 GND
2
7
DIS RS 232
U4C
14
68
330nF
R20
U5
7
2R7 5 VCC
R21 U4D 1
10K LEDA
14
U4E
PA5_TXD
14
74LVC04/SO 2 TXD
74LVC04/SO
9 8 IRDA_SD 4
-DIS_IRDA SD
11 10
PA4_RXD 3 RXD
J3
7
1 6 GND
T
7
2
ZHX1810
GND
0
DIS I RDA
U4F GND
VCC_33V
14
74LVC04/SO
13 12 R22
1
2
3
4
5
1
2
3
4
5
10K
AN026004-0413 Page 16 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Appendix B. Flowcharts
Figure 9 presents a simple flow chart of the main, timer interrupt and Port B interrupt rou-
tines for the electric bike BLDC motor controller application.
Start
Main()
Initialize MCU
peripherals
Capture 3 Hall
sensor binary Obtain ADC result
states for set-speed used
for open/closed
loop
No Yes
Hall period =
0xFFFF
No
AN026004-0413 Page 17 of 18
Electric Bike BLDC Hub Motor Control Using the Z8FMC16100 MCU
Application Note
Customer Support
To share comments, get your technical questions answered, or report issues you may be
experiencing with our products, please visit Zilog’s Technical Support page at
http://support.zilog.com.
To learn more about this product, find additional documentation, or to discover other fac-
ets about Zilog product offerings, please visit the Zilog Knowledge Base at http://
zilog.com/kb or consider participating in the Zilog Forum at http://zilog.com/forum.
This publication is subject to replacement by a later edition. To determine whether a later
edition exists, please visit the Zilog website at http://www.zilog.com.
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perform when properly used in accordance with instructions for
use provided in the labeling can be reasonably expected to result in a significant injury to the user. A
critical component is any component in a life support device or system whose failure to perform can be
reasonably expected to cause the failure of the life support device or system or to affect its safety or
effectiveness.
Document Disclaimer
©2013 Zilog, Inc. All rights reserved. Information in this publication concerning the devices, applications,
or technology described is intended to suggest possible uses and may be superseded. ZILOG, INC. DOES
NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE
INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT. ZILOG ALSO
DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED
IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED
HEREIN OR OTHERWISE. The information contained within this document has been verified according
to the general principles of electrical and mechanical engineering.
Z8 Encore! MC is a trademark or registered trademark of Zilog, Inc. All other product or service names are
the property of their respective owners.
AN026004-0413 Page 18 of 18