an0260
TRANSCRIPT
-
8/13/2019 AN0260
1/18 AN026004-0413 Page 1 of 18
AbstractThis 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 ZilogsZ8FMC16100 MCU and associated circuitry to implement motoring control, regenerative
braking, and fault protection.
The source code file associated with this application note, AN0260-SC01.zip , is availablefor download on zilog.com. This source code has been tested with version 5.0.0 of ZDS IIfor Z8 Encore! XP MCUs. Subsequent releases of ZDS II may require you to modify thecode supplied with this application note.
FeaturesThe 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.
DiscussionThe Z8FMC16100 MCU features a flexible Pulse Width Modulation (PWM) module withthree complementary pairs or six independent PWM outputs supporting dead-band opera-tion and fault protection trip input. These features provide multiphase control capabilityfor 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 operationalamplifier 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 a16-bit timer provide a Hall-effect sensor interface.
A full-duplex 9-bit UART provides serial, asynchronous communication and supports anoption for the Local Interconnect Network (LIN) serial communications protocol. The
Note:
Application Note
AN026004-0413
Electric Bike BLDC Hub MotorControl Using the Z8FMC16100MCU
http://www.zilog.com/docs/appnotes/an0260-sc01.ziphttp://www.zilog.com/docs/appnotes/an0260-sc01.zip -
8/13/2019 AN0260
2/18
AN026004-0413 Page 2 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
LIN bus is a cost-efficient single Master, multiple Slave organization that supports speedup to 20 kbps.
The Z8FMC16100 MCU has a rich set of peripherals and other features such as: additional16-bit timer with capture/compare/PWM capability, SPI, and I 2C Master/ Slave for serialcommunication, and an internal precision oscillator.
The single-pin debugger and programming interface simplifies code development andallows easy in-circuit programming.
A block diagram of the Z8FMC16100 MCU is shown in Figure 1 .
Figur e 1. Z8FMC16100 MCU Block Diagram
Braking and Regenerative ChargingIn this e-bike application, the Z8FMC16100 MCUs PWM registers are configured tooperate in a complementary PWM mode when applied to an inverter bridge that consistsof six MOSFETs. This complementary PWM mode allows for greater control of the e-
bikes braking and regenerative charging process. The BLDC motor will effectively run ineither a motoring mode or a generative mode .
Generative Mode is achieved when the the applied operating voltage is less than theBEMF voltage produced by the rotating motor. Motoring Mode is achieved when theapplied voltage is equal to or greater than the BEMF voltage produced by the rotatingmotor. Varying the applied operating voltage can be accomplished by changing the dutycycle for each phase in the inverter bridge.
For quicker braking, the lower MOSFET devices of the inverter bridge are turned on whilethe upper MOSFETs are turned off, thereby quickly producing a negative current (i.e., anegative torque) to stop the motor. To gain a regenerative charge, the upper MOSFETs are
12-Bit PWMModule for
Motor Control
16-Bit TimerCapture/
Compare/PWM
Operational Amplifier
Up to 16 KBFlash
20 MHzeZ8 CPU
8-Channel10-Bit ADC
512 B SRAM VBO/PORand Reset
ControlI2C, SPI, and
UART with LIN
WatchdogTimer
Single-PinDebugger
InternalPrecisionOscillator
Comparator Interrupt Controller
17 General Purpose I/O Pins
-
8/13/2019 AN0260
3/18
AN026004-0413 Page 3 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
turned on to allow current flow back to the battery, while the lower MOSFETs are turnedoff.
Hardware ArchitectureIn 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 musttherefore 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 Highor 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 hallsensors, the voltages to the motor's three phases are switched.
The advantage of Hall sensor-based commutation is that the control algorithm is simpleand easy to understand. Hall sensor-based commutation can also be used to run the motorat very low speeds. The disadvantages are that its implementation requires both separateHall sensors inside the motor housing and additional hardware for sensor interface.
Sensorl ess Commutation. In the sensorless commutation technique, the back-EMFinduced in the idle phase is used to determine the moment of commutation. When theinduced idle-phase back-EMF equals one-half of the DC bus voltage, commutation iscomplete.
The advantage of sensorless commutation is that it makes the hardware design simpler. Nosensors 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 islow, it does not support low motor speeds.
When a BLDC motor application requires high torque, when the motor is running at lowspeed, 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. Sinusoidalvoltage provides a smooth motor rotation and fewer ripples.
Trapezoidal. DC voltage is applied to two phases at a time, and the third phase remainsidle. Trapezoidal voltage is less complex to implement. The idle phase is generating theBEMF from the rotating magnet that passes the unenergized idle phase and provides theBEMF zero-crossing data.
How Hall Sensor Commutation Works
To better understand how Hall sensor commutation works, let's look at how it's imple-mented with a two-pole motor. Six different commutation states are required to turn therotor one revolution. The motors commutation states are shown in Figure 2 .
-
8/13/2019 AN0260
4/18
-
8/13/2019 AN0260
5/18
AN026004-0413 Page 5 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
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.
Additionally, the application uses a 3-amp High Rupturing Capacity (HRC) fuse.
Table 1. Relationship Between Hall Sensor Output and Phase Switch ing
State Hall A Hall B Hall C Phase B Phase C Phase A
1 0 1 1 0 +V DC V DC2 0 0 1 +V DC 0 V DC3 1 0 1 +V DC VDC 0
4 0 1 0 0 V DC +VDC5 1 1 0 V DC 0 +V DC6 1 0 0 V DC +VDC 0
Table 2. Motor Rating for Electri c Bike BLDC Motor Contro l Appl ication
Type of Motor Linix BLDC
Power Rating 30 W
Speed 3200 RPM
Number of poles 6
Voltage 24 V
-
8/13/2019 AN0260
6/18
AN026004-0413 Page 6 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
Using the Z8FMC16100 MCU in an Electric Bike BLDC MotorController
Figure 3 offers a visual overview of the electric bike BLDC motor controller. For moredetails about hardware connections, see Appendix A. Schematics on page 12 .
Hardware ArchitectureThe design involves running the BLDC motor in a closed loop or an open loop, with speedas set by a potentiometer. As shown in the architecture diagram, the design generatesPWM voltage via the Z8FMC16100 MCUs 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 thesensors (commutation). Hall sensor interrupts capture timer ticks every sixty degrees to
Figure 3. Electric Bike BLDC Motor Controll er Block Diagram
-
8/13/2019 AN0260
7/18
AN026004-0413 Page 7 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
measure the rotor speed of the motor. Other peripheral functions can be used to protect thesystem in case of overload, undervoltage, and overtemperature.
The hardware is described in the following sections.
Three-Phase Bridge MOSFET
The three-phase bridge MOSFET consists of six MOSFETs connected in bridge fashionused to drive the three phases of the BLDC motor. The DC bus is maintained at 24 V,which is same as voltage rating of BLDC motor. A separate Hi-Lo gate driver is used foreach high- and low-side MOSFET phase pair, making the hardware design simpler androbust. The high-side MOSFET is driven by charging the bootstrap capacitor.
The DC bus voltage is monitored by reducing it to suitable value using a potential divider.The DC bus current is monitored by putting a shunt in the DC return path. An NTC-typetemperature sensor is mounted on MOSFET heat sink, providing analog voltage output
proportional to temperature.
PWM Module
The Z8FMC16100 MCU contains a six-channel, 12-bit PWM module configured in thisapplication 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 bridgeMOSFET 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 themotor 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 serviceroutine 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. Inthis 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 switchedOFF).
Speed Measurement
The Hall sensor outputs are connected to to ports PB0, PB1 and PB2. One out of three Hallsensors is used to capture the Timer0 ticks, which represent the actual Hall period forclosed loop calculations.
-
8/13/2019 AN0260
8/18
AN026004-0413 Page 8 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
Closed Loop Speed Contro l
Closed-loop speed control is implemented using a PI loop, which works by reducing theerror between the speed set by the potentiometer and actual motor speed. The output ofthis PI loop changes the duty cycle of the PWM module, thereby changing the averagevoltage to the motor, and ultimately changing the power input. The PI loop adjusts thespeed at the same rate as the Hall frequency from one of three Hall sensors. In this applica-tion, Open Loop operation is selected in the software by default because any rider of the e-
bike will control the speed of the bike.
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 aretimed by Timer0 interrupt.
Over-Current Hardware Protection
The Z8FMC16100 MCU has a built-in comparator that is used to shut down the PWM forover-current protection. When the current exceeds the set threshold, a PWM ComparatorFault is generated to turn OFF the PWM Module.
Software ImplementationDuring 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 asGPIO 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
-
8/13/2019 AN0260
9/18
AN026004-0413 Page 9 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
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 andaverage these values, update the LED indicator status, and update the read parameters onthe UART.
For a visual representation of the application, see Appendix B. Flowcharts on page 17 .
Testing/Demonstrating the ApplicationThis section presents a list of the equipment used and procedures observed to test this e-
bike application.
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 12 positions on J4, J5, and J6 b. Shunt J2 and J3
2. Set the R7 potentiometer on MC MDS Board (99C0987; contained in theZ8FMC16100 Series Motor Control Development Kit) to the middle position to startthe motor.
3. Connect the following wires from the motor to the 3-Phase Motor Control ApplicationBoard (contained in the Z8FMC16100 Series Motor Control Development Kit but notshown in the schematic).
-
8/13/2019 AN0260
10/18
AN026004-0413 Page 10 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
a. Connect the heavy-gauge blue wire to Motor Phase A (P1) b. Connect the heavy-gauge green wire to Motor Phase B (P2)
c. Connect the heavy-gauge white wire to Motor Phase C (P3)
4. Connect the following wires from the motor to the MC MDS Board (contained in theZ8FMC16100 Series Motor Control Development Kit but not shown in the sche-matic).a. Connect the Hall Sensor-C light gauge blue wire to PB2 at J1 pin 6 with additional
added 680 pF ceramic capacitor to GND. b. Connect the Hall Sensor-B light gauge green wire to PB1 at J1 pin 4 with addi-
tional added 680 pF ceramic capacitor to GND.
c. Connect the Hall Sensor-A light gauge white wire to PB0 at J1 pin 2 with addi-tional added 680 pF ceramic capacitor to GND.
d. Connect the light gauge black wire (Sensor Power Ground) to GND at TP1.e. Connect the light gauge red wire (Sensor Power V CC ) to V CC (3.3V) at TP2.
5. Connect the oscilloscope across the motor terminals.
6. Connect the motor control board to the 24 V power supply.
7. Build the code on ZDS II v5.0.0 and download the code through USB smart cable.
8. Measure the performance of motor at different loads, for each speed setting of the potentiometer.
9. Record the readings and carry out the process for each step in the test sequence.
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 ImplementationThe application discussed in this document covers the motoring and regenerative brakingfeatures for a BLDC hub motor used in an electric bike. Further improvements can bemade 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
-
8/13/2019 AN0260
11/18
AN026004-0413 Page 11 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
Utilizing LIN/UART communication to create a dashboard display of measured parameters (speed, Battery voltage, Current, and Fault conditions)
ReferencesThe 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 A pplication Note (AN0228)
http://www.zilog.com/docs/um0128.pdfhttp://www.zilog.com/docs/um0128.pdfhttp://www.zilog.com/docs/z8encoremc/ps0246.pdfhttp://www.zilog.com/docs/z8encoremc/ps0246.pdfhttp://www.zilog.com/docs/z8/appnotes/pid_motor_control.pdfhttp://www.zilog.com/docs/z8/appnotes/pid_motor_control.pdfhttp://www.zilog.com/docs/z8encorexp/appnotes/an0223.pdfhttp://www.zilog.com/docs/z8encorexp/appnotes/an0223.pdfhttp://www.zilog.com/docs/appnotes/an0226.pdfhttp://www.zilog.com/docs/appnotes/an0226.pdfhttp://www.zilog.com/docs/appnotes/an0226.pdfhttp://www.zilog.com/docs/z8encorexp/appnotes/an0228.pdfhttp://www.zilog.com/docs/z8encorexp/appnotes/an0228.pdfhttp://www.zilog.com/docs/z8encorexp/appnotes/an0228.pdfhttp://www.zilog.com/docs/appnotes/an0226.pdfhttp://www.zilog.com/docs/z8encorexp/appnotes/an0223.pdfhttp://www.zilog.com/docs/z8/appnotes/pid_motor_control.pdfhttp://www.zilog.com/docs/um0128.pdfhttp://www.zilog.com/docs/z8encoremc/ps0246.pdf -
8/13/2019 AN0260
12/18
AN026004-0413
Electric Bike BLDC Hub Moto r Contr ol
Appendix A. SchematicsFigures 4 through 8 show schematic representations of each of the applications key blocks.
Figure 4. Electric Bike BLDC Motor Controll er Appli cation Schematic, #1 of 5
3 PHASE POWER STAGE
HEATSINK TEMP SENSOR
B A
96C0960
3 PHASE MOTOR CONTROL APPL
A
Title
r ebmuNtnemucoDeziS
V+
B _ ES AHP A _ ES AHP PHASE_B ES AHPB _ ES AHP
GATE_AH
LB _ ET AGL A _ ET AG
GATE_BHGATE_CH
GATE_CL
+BUS+BUS+BUS+BUS+BUS+BUS+BUS+BUS+BUS+BUSSUB+CDV+ +BUS+BUS+BUS+BUS+BUS+BUS+BUS+BUS+BUS
GND
TH
C
C
TH
C2
0.1uF 50V
Q3
IRFZ48
F1
5A FUSE
Q4
IRFZ48
+ C4
3300uF 50V
R510.00k
R4NTC 10k
R2 10.0k
P2
+ C5
3300uF 50V
P1
Q1
IRFZ48
Q2
IRFZ48
P5
R6150k
P4
C1
0.1uF 50V
R10.100 OHM
R3 10.0k
-
8/13/2019 AN0260
13/18
AN026004-0413
Electric Bike BLDC Hub Moto r Contr ol
Figure 5. Electric Bike BLDC Motor Controll er Appli cation Schematic, #2 of 5
GATE DRIVE
BEMF DIVIDERS
12V SUPPLY
96C
3 PHASE MOTOR CONTROL APPL
A
Wednesda June 08 2005
Title
r ebmuNtnemucoDeziS
:etaD
AL
AH
BL
BH
CH
PHASE _A P HAS E_ B PHASE_C
VAVA VBVBVBVB
CL
VCC_33V
VC
+12V
+12V
+12V
+12V
R10150k
C6
10uF
R18
C19
10uF
C11
0.1uF
R12150k R13
R2086.6k
R710.00k
U2
IR2101
1
2
3
4 5
6
7
8VCC
HIN
LIN
COM LO
VS
HO
VB
D3 BAV19
L1
10uH
R15
R14
R910.00k
C14
10uF
C20
68pF
R1110.00k
R16
U1
IR2101
1
2
3
4 5
6
7
8VCC
HIN
LIN
COM LO
VS
HO
VB
D4 BAV19
D2 BAV19
C15
0.1uFU3
IR2101
1
2
3
4 5
6
7
8VCC
HIN
LIN
COM LO
VS
HO
VB
U4
TPS61041
1
2
3
4
5 SW
GND
FB
EN
VIN
R8150k
D1 BAV19
C18
10uF
C7
0.1uF
R17
C10
10uF
R1910.0k
-
8/13/2019 AN0260
14/18
AN026004-0413
Electric Bike BLDC Hub Moto r Contr ol
Figure 6. Electric Bike BLDC Motor Controll er Appli cation Schematic, #3 of 5
EC AFRETNIREWOPDESUNU
BH
BL
VCC_33V
A A
VCC_33V
VCC_33V
VC
C
T
VA
V+
CH
CS-
VC
JP1
HEADER 30x2/SM
24681012141618202224262830323436384042444648505254565860
13579
11131517192123252729313335373941434547495153555759
JP2
HEADER 30x2/SM
24681012141618202224262830323436384042444648505254565860
13579
11131517192123252729313335373941434547495153555759
-
8/13/2019 AN0260
15/18
AN026004-0413
Electric Bike BLDC Hub Moto r Contr ol
Figure 7. Electric Bike BLDC Motor Controll er Appli cation Schematic, #4 of 5
RUN/ST OP
DIRECT ION
Connect ion between AG ND and GNDshould be done as clo se as po ssibleto the pin 5, AGND.Connection between AVCC and VCC_33Vshould be done as clo se as po ssibleto the pin 4, AVCC.
SPEED
LOCAL/ MDS
ANA4 PA0_OPINN
ANA2_M ANA0_M
PWM2H ANA6
PWM1H
PW M1L
PA2_CINP
PA4_RXDPA6_CTS
VC-RES
VCC
PA1_OP_CN
ANA0 ANA1 ANA2
GND
PA3_TXDE
PA6_CTS
VREF
ANA2_M
ANA1
ANA0
ANA0_M
ANA1_M
ANA2
PA0_OPINN
P A 2_ C I N P
P A 4_ R X D
P W M 2 L
P A 5_ T X D
PWM0H
P W M 2 H
A N A 5
XIN
PA3_TXDE
-RESET
D B G
PC0_T0O UT
- R E S E T
ANA6
P W M 1 L
P B 3_ A N A 3_ O P O U T
A N A 7
P A 6_ C T S
P C 0_ T 0 O U T
VCC_33V
PWM1H
AGND AVCC
VCC_33V
GND
A N A 6
XOUT
PW M0L
P A 7_ C O U
T
A N A 4
DBG
PA5 _TXDPA4_RXD
PA6_CTS
-RESET
VCC_33V
VCC_33V
VCC_33V
S1
SW SPDT
R9 49.9K
J6HEADER 3
1 2 3
C22
100pF
C4
22pF
R10 100
C17
0.01
C23
0.1uF
C20
0.01
R7 5K
1
3
2
R12 10K
R60
D1
RED
2 1
R14
10K
C5
22pF
R241KC18
0.01
C24
0.1uF
R13 10K
R15
10K
Y1
20MHz
1
2
31
2
3
J1
HEADER 5X2
2 4 6 8 1 0
1 3 5 7 9
S2
SW SPDT
C19
0.01
J4HEADER 3
1 2 3
C25
0.1uF
D2
LED YEL
2 1
U1Z8FMC16110_32
12345678
9
2 8
1 1 1 2 1 3 1 4 1 5 1 6
1718192021222324
2 5 2 6 2 7 2 9 3 0 3 1 3 2
1 0
PB2/ANA2/T0IN2PB1/ANA1/T0IN1PB0/ANA0/T0IN0
AVDD AGND
VREFPA0/OPINN
PA1/OPINP/CINN
P A 2 / C I N P
P B 7 / A N A 7
R E S E T / F A U L T 0
D B G
P C 0 / T 0 O U T
P W M 2 L
P W M 2 H
P W M 1 L
PWM1HPWM0LPWM0HGNDXOUTXINVDDPA3/TXDE/SCL
P A 4 / R X D
P A 5 / T X D
P A 6 / C T S / S D A
P B 6 / A N A 6
P B 5 / A N A 5
P B 4 / A N A 4 / C I N N
P B 3 / A N A 3 / O P O U T
P A 7 / F A U L T 1 / T 0 O U T / C O U T
R1 10 0
C1
0.1uF
R23 10K
C6 12pF
R5 10K
J5HEADER 3
1 2 3
R4
10K
C21
100pF
R27.5K
R8 100
C16
0.01
R312.4K
D3
LED GRN
2 1
C2
100pF
C3
1000pF
R11 10K
C26
10uF
-
8/13/2019 AN0260
16/18
AN026004-0413
Electric Bike BLDC Hub Moto r Contr ol
Figure 8. Electric Bike BLDC Motor Controll er Appli cation Schematic, #5 of 5
3.3 O K
DIS IRDA
DIS RS232
DBG
INTERF ACE
change pinout
VCC_33V
GNDVCC_33V
VCC_33V
DBG
VCC_33V
-RESET
GND
PA5_TXD
GND
VCC_5V
VCC_33
VCC_33V
PA4_RXD
GND
GND
GND
GND
GND
PA5_TXD
-RESET
PA4_RXD
PA6_CTS
DBG
VCC_33V
-DIS_IRDA
-DIS_232
R17 0
C80.1uF
C100.1uF
U4E
74LVC04/SO
11 10
1 4
7
U4A
74LVC04/SO
1 2
1 4
7
C120.1uF
J2
12
U4D
74LVC04/SO
9 8
1 4
7
P3
Header 3x2
1 23 45 6
R1810K
U4B
74LVC04/SO
3 4
1 4
7
U3SPX2815AU-3.3
3
1
2VI
G N D VO
U4F
74LVC04/SO
13 12
1 4
7
J3
12
R16
68 0
P1
PWR JACK
231
+ C13
100/10C14
0.1uF
R2110K
+ C9
100/10
U4C
74LVC04/SO
5 6
1 4
7
U2
SP32
1
2
4
5
6
13
12
15
10
20
1 9
1 8
EN
C1+
C1-
C2+
C2-
T1IN
T2IN
R1OUT
R2OUT
V
V
T1OUT
T2OUT
R1IN
R2IN
SHDN
V C C
G N D
NCNC
TP1
1 2 3 4 5
D4
LED
2
1
R2210K
TP2
1 2 3 4 5
-
8/13/2019 AN0260
17/18
AN026004-0413 Page 17 of 18
Electric Bike BLDC Hub Moto r Contr ol Usin g the Z8FMC16100 MCU Appl icati on Not e
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.
Figure 9. Electric Bike BLDC Motor Cont roll er Applicatio n Flowchart
Main()
Hall interrupt?
Capture 3 Hallsensor binary
states
Switch into next
commutation state
Hall states = 3? Timer0rollover?
Hall period =0xFFFF
Capture Timer0period and reset
Timer0
Obtain ADC resultfor set-speed used
for open/closedloop
Initialize MCUperipherals
Apply PI controlvalue to PWM
registers
Closed loopselected?
Start
Yes No
Yes No
Yes
Yes
No
No
-
8/13/2019 AN0260
18/18