Upload
tranthien
View
216
Download
1
Embed Size (px)
Citation preview
APPLICATION NOTE
S3F84A5 Electric Bike Controller System
January 2010
Revision 1.10
Confidential Proprietary of Samsung Electronics Co., Ltd
Copyright © 2010 Samsung Electronics, Inc. All Rights Reserved
Important Notice
The information in this publication has been carefully checked and is believed to be entirely accurate at the time of publication. Samsung assumes no responsibility, however, for possible errors or omissions, or for any consequences resulting from the use of the information contained herein.
Samsung reserves the right to make changes in its products or product specifications with the intent to improve function or design at any time and without notice and is not required to update this documentation to reflect such changes.
This publication does not convey to a purchaser of semiconductor devices described herein any license under the patent rights of Samsung or others.
Samsung makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does Samsung assume any liability arising out of the application or use of any product or circuit and specifically disclaims any and all liability, including without limitation any consequential or incidental damages.
"Typical" parameters can and do vary in different applications. All operating parameters, including "Typicals" must be validated for each customer application by the customer's technical experts.
Samsung products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, for other applications intended to support or sustain life, or for any other application in which the failure of the Samsung product could create a situation where personal injury or death may occur.
Should the Buyer purchase or use a Samsung product for any such unintended or unauthorized application, the Buyer shall indemnify and hold Samsung and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, expenses, and reasonable attorney fees arising out of, either directly or indirectly, any claim of personal injury or death that may be associated with such unintended or unauthorized use, even if such claim alleges that Samsung was negligent regarding the design or manufacture of said product.
S3F84A5 Electric Bike Controller System Application Note, Revision 1.10
Copyright 2010 Samsung Electronics Co., Ltd.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electric or mechanical, by photocopying, recording, or otherwise, without the prior written consent of Samsung Electronics.
Samsung Electronics Co., Ltd. San #24 Nongseo-Dong, Giheung-Gu Yongin-City, Gyeonggi-Do, Korea 446-711
TEL : (82)-(031)-209-4356 FAX : (82)-(031)-209-3262
Home Page: http://www.samsungsemi.com
Printed in the Republic of Korea
Revision History
Revision No. Date Description Author(s)
0 - Initial draft
1.10 Jan. 20, 2010
Table of Contents
1 Electric Bike Controller System...................................................................9
2 Overview of Electric Bikes .........................................................................10
2.1 General System Block Diagram of e-bike..................................................................................................11 2.2 Overview of 3-Phase BLDC Motor.............................................................................................................11
2.2.1 BLDC Motor ........................................................................................................................................11 2.2.2 Stator ..................................................................................................................................................12 2.2.3 Rotor ...................................................................................................................................................12
2.3 Key Electrical Characteristics of e-bike Controller.....................................................................................13
3 Overview of S3F84A5 Microcontroller.......................................................14
4 Reference Design with S3F84A5................................................................16
4.1 System diagram of S3F84A5.....................................................................................................................16 4.2 Main Blocks in Reference Design..............................................................................................................18
4.2.1 Power Supply......................................................................................................................................18 4.2.2 Battery Voltage Detect........................................................................................................................18 4.2.3 Handlebar Voltage Detect ..................................................................................................................19 4.2.4 System Feedback Current Detect ......................................................................................................19 4.2.5 Over-current Protection ......................................................................................................................20 4.2.6 Brake Mechanism...............................................................................................................................21 4.2.7 Hall Sensor Position Detect................................................................................................................21 4.2.8 Power MOSFET and Driver................................................................................................................22 4.2.9 Other Functions ..................................................................................................................................26 4.2.10 Debugger Socket ..............................................................................................................................27 4.2.11 Program Interface.............................................................................................................................27
5 Software Description ..................................................................................28
5.1 Overview of the Software Used in e-bike Controller Reference Design....................................................28 5.2 Software Flow ............................................................................................................................................30
5.2.1 Main flow.............................................................................................................................................30 5.2.2 Subroutine flow...................................................................................................................................31
5.2.2.1 Battery Voltage Detect ..............................................................................................................31 5.2.2.2 Handlebar Voltage Detect .........................................................................................................32 5.2.2.3 System Feedback Current Detect.............................................................................................33 5.2.2.4 Under-voltage Protection ..........................................................................................................34 5.2.2.5 Over-current Protection.............................................................................................................35 5.2.2.6 Brake Mechanism .....................................................................................................................36 5.2.2.7 Constant Speed Control............................................................................................................37 5.2.2.8 Speed Loop Control ..................................................................................................................38 5.2.2.9 Current Loop Control.................................................................................................................39
5.2.3 PWM Control ......................................................................................................................................40 5.2.3.1 A. Start PWM ............................................................................................................................40 5.2.3.2 B. Initialization PWM .................................................................................................................41 5.2.3.3 C. Resume PWM ......................................................................................................................41 5.2.3.4 D. Stop PWM ............................................................................................................................42
5.2.4 Interrupt Service Routine....................................................................................................................42 5.2.4.1 A. External INT0 (Over-current Protection) ISR........................................................................42 5.2.4.2 B. External INT1 (Brake Mechanism) ISR ................................................................................43 5.2.4.3 C. External INT2 ~ 4 (Phase A/B/C Change) ISR.....................................................................44 5.2.4.4 D. Timer 0 Match Interrupt (Speed Counting) ISR....................................................................45
6 Appendix I: Schematic Diagram of reference design ..............................46
7 Appendix II: Demo System .........................................................................47
8 Appendix III: Source Code..........................................................................51
List of Figures
Figure Title Page Number Number Figure 2-1 Bicycle Style and Scooter Style Electric Bikes ...................................................................................10 Figure 2-2 General System Diagram of e-bike.....................................................................................................11 Figure 2-3 BLDC Motor Mechanical Structure .....................................................................................................12 Figure 3-1 S3F84A5 Pin Assignment (28-SOP/SSOP Package) ........................................................................15 Figure 3-2 S3F84A5 Pin Assignment (32-ELP) ...................................................................................................15 Figure 4-1 E-bike Controller System Diagram .......................................................................................................16 Figure 4-2 Power Supply......................................................................................................................................18 Figure 4-3 Battery Voltage Detect Circuit.............................................................................................................19 Figure 4-4 Handlebar Voltage Detect and Speed Limited Circuit ........................................................................19 Figure 4-5 System Feedback Current Detect Circuit ...........................................................................................20 Figure 4-6 System Over-current Protection Circuit ..............................................................................................20 Figure 4-7 Brake Mechanism Waveform (P1.1)...................................................................................................21 Figure 4-8 Brake mechanism Circuit....................................................................................................................21 Figure 4-9 Hall Sensor Position Detect and Velocity Meter Circuit......................................................................21 Figure 4-10 Hall Sensor Position Waveform Diagram .........................................................................................22 Figure 4-11 Power MOSFET and Integrated Driver Circuit .................................................................................25 Figure 4-12 Other Function Input Selection Circuit ..............................................................................................26 Figure 4-13 On-board Debugger Socket..............................................................................................................27 Figure 4-14 Program Interface .............................................................................................................................27 Figure 5-1 Main Flow............................................................................................................................................30 Figure 5-2 Battery Voltage Detect Subroutine Flow.............................................................................................31 Figure 5-3 Handlebar Voltage Detect Subroutine Flow .......................................................................................32 Figure 5-4 System Feedback Current Detect Subroutine Flow ...........................................................................33 Figure 5-5 Battery Under-voltage Protection Subroutine Flow ............................................................................34 Figure 5-6 System Over-current Protection Subroutine Flow ..............................................................................35 Figure 5-7 Brake Mechanism Subroutine Flow....................................................................................................36 Figure 5-8 Constant Speed Control Subroutine Flow ..........................................................................................37 Figure 5-9 Speed Loop Control Subroutine Flow.................................................................................................38 Figure 5-10 Current Loop Control Subroutine Flow .............................................................................................39 Figure 5-11 Start PWM Control Subroutine Flow.................................................................................................40 Figure 5-12 Initialization PWM Control Subroutine Flow .....................................................................................41 Figure 5-13 Resume PWM Control Subroutine Flow...........................................................................................41 Figure 5-14 Stop PWM Control Subroutine Flow.................................................................................................42 Figure 5-15 External INT0 (Over-current Protection) Interrupt Service Routine Flow .........................................42 Figure 5-16 External INT1 (Brake Mechanism) Interrupt Service Routine Flow..................................................43 Figure 5-17 External INT2 ~ 4 (Phase A/B/C Change) Interrupt Service Routine Flow ......................................44 Figure 5-18 Timer 0 Match (Speed Counting) Interrupt Service Routine Flow....................................................45 Figure 6-1 Schematic Diagram of E-bike Controller Reference Design ..............................................................46
Figure 7-1 E-bike Controller Reference Design Demo System ...........................................................................47 Figure 7-2 E-bike Controller Reference Design Control Board............................................................................48 Figure 7-3 E-bike Controller Hall Sensor Position Real Waveform Diagram (Full Speed) ..................................49 Figure 7-4 E-bike Controller 3-Phases Real Waveform Diagram (Full Speed) ...................................................49 Figure 7-5 E-bike Controller Hall Sensor Position Real Waveform Diagram (Low Speed) .................................50 Figure 7-6 E-bike Controller 3-Phases Real Waveform Diagram (Low Speed)...................................................50
List of Tables
Table Title Page Number Number Table 4-1 The Pins Assignment of E-bike Controller Solution based on S3F84A5.............................................17 Table 4-2 Sequence of Forward Rotating ............................................................................................................22 Table 4-3 Sequence of Reverse Rotating ............................................................................................................23 Table 4-4 P2PWMOUT Register Configuration during Non-synchronous Rectification Mode ............................23 Table 4-5 P2PWMOUT Register Configuration in Non-synchronous Rectification Mode ...................................24 Table 4-6 Other Functions in E-bike Reference Design ......................................................................................26 Table 5-1 Routine lists of e-bike Controller Reference Design Software.............................................................28
S3F84A5_APPLICATION NOTE_REV1.10 1 ELECTRIC BIKE CONTROLLER SYSTEM
Samsung Confidential 9
1 ELECTRIC BIKE CONTROLLER SYSTEM
This chapter describes Samsung’s S3F84A5 microcontroller that is designed for electric bike (e-bike) controller system, including its hardware design and software process. It also provides the test system and signal output waveforms for reference.
Electric bike is a kind of green, energy-saving means of transport in China. It includes several components such as frame, host motor, controller, and battery. The controller in e-bikes is composed of current-limiting circuit, Hall location detection circuit, MOSFET full bridge circuit, and microcontroller.
S3F84A5_APPLICATION NOTE_REV1.10 2 OVERVIEW OF ELECTRIC BIKES
2 OVERVIEW OF ELECTRIC BIKES
Electric bikes are light electric vehicles (LEVs) used for convenient local transportation in China. Designed for one-person capacity, these pedal-driven e-bikes include two wheels – one at the front and other at the rear – attached by a frame. These e-bikes are available in two variants, namely, bicycle style and scooter style. The bicycle style e-bikes are supplemented by electrical power from a storage battery. On the other hand, the low-speed scooter style e-bikes are propelled by electricity. Figure 2-1 shows a typical bicycle-style and scooter-style e-bike.
Figure 2-1 Bicycle Style and Scooter Style Electric Bikes
The main components of e-bike include hub motor, controller, and valve-regulated lead-acid (VRLA) battery. Typically, bicycle-style e-bikes have 36V battery and 180-250W motors. On the other hand, scooter-style e-bikes have 48V batteries and 350-500W motors.
NOTE: e-bikes should not exceed 20km/hr limit (based on a regulation in China), but many e-bikes (especially scooter-style) can travel at speeds in excess of this limit. Some can even go up to 40km/hr.
Samsung Confidential 10
S3F84A5_APPLICATION NOTE_REV1.10 2 OVERVIEW OF ELECTRIC BIKES
2.1 GENERAL SYSTEM BLOCK DIAGRAM OF E-BIKE
Figure 2-2 shows the general system block diagram of e-bike controller. The e-bike controller consists of current limit circuit, Hall rotor position detection circuit, power MOSFET full bridge circuit, and microcontroller.
Power MOSFETBridge Driver BLDC
Motor
PowerMOSFET
Hall Rotor SensorPosition Detection
Microcontroller
CurrentLimited Circuit
Figure 2-2 General System Diagram of e-bike
The microcontroller processes feedback from the sensor to control the Power MOSFET driver that supplies the 3-phase Brushless Direct Current (BLDC) motor. At the same time, the speed of the BLDC motor is derived from the sensor signals and is used to provide velocity feedback for the closed speed loop.
2.2 OVERVIEW OF 3-PHASE BLDC MOTOR
2.2.1 BLDC MOTOR
Brushless Direct Current (BLDC) motor is a type of synchronous motor, where magnetic fields generated by both stator and rotate have the same frequency.
The BLDC motor has a longer life since no brushes are needed. Apart from that, it has a high starting torque, high no-load speed and small energy losses.
BLDC motor can be configured in 1-phase, 2-phase and 3-phase. 3-phase motors are the most popular among all the configurations and are widely used in e-bikes.
The structure of BLDC motor is divided into two parts:
Moving part called the rotor, represented by permanent magnet
Fixed part called the stator, represented by phase windings of magnetic circuit
Samsung Confidential 11
S3F84A5_APPLICATION NOTE_REV1.10 2 OVERVIEW OF ELECTRIC BIKES
2.2.2 STATOR
The stator of a BLDC motor consists of stacked steel laminations with windings placed in the slots that are axially cut along the inner periphery. Traditionally, the stator resembles to an induction motor; however, the windings are distributed in a different manner.
Most BLDC motors have three stator windings connected in star fashion. Each of these windings is constructed with numerous coils that are interconnected to form a winding. One or more coils are placed in the slots and they are interconnected to make a winding. Each of these windings is distributed over the stator periphery to form an even number of poles.
2.2.3 ROTOR
The rotor is made of permanent magnet and can vary from two to eight pole pairs with alternate North (N) and South (S) poles.
Figure 2-3 BLDC Motor Mechanical Structure
Unlike a brushed DC motor, BLDC motor can be controlled electronically. To rotate the BLDC motor, the stator windings should be energized in a special sequence. It is important to know the rotor position in order to understand which winding will be energized next. Rotor position is sensed using Hall Effect sensors that are embedded in the stator.
Most BLDC motors have three Hall sensors embedded in the stator on the non-driving end of the motor.
Whenever the rotor magnetic poles pass near the Hall sensors, they generate a high or low signal, which indicates that N or S pole is passing near the sensors. Based on the combination of these Hall Sensor signals, the exact sequence of commutation can be determined.
Samsung Confidential 12
S3F84A5_APPLICATION NOTE_REV1.10 2 OVERVIEW OF ELECTRIC BIKES
Samsung Confidential 13
2.3 KEY ELECTRICAL CHARACTERISTICS OF E-BIKE CONTROLLER
The key electrical characteristics of e-bike controller include:
Rated Voltage: 24V/36V/48V DC (Lead Acid Battery)
Rated Power: 240W ~ 500W
Motor Speed: 0 ~ 40 km/h variable-speed by handlebar
Speed Restriction: Maximum 20km/h (by Jumper)
Battery Under-voltage Protection: 31.5 0.5V/41.5 0.5V
When the voltage of 36V battery drops to 31.5V, or when the voltage of 48V battery drops to 41.5V, motor should be disconnected from the power supply in order to increase the battery life. After that, the motor will stop until the power supply voltage is above 33V for +36V battery or 44V for +48V battery. Note that the recover voltage level is higher than that of under-voltage protection.
System Over-current Protection: 15 1A
When the feedback current going through the Power MOSFETs exceeds 15A, the motor should be shut down immediately. Restart happens when the current recovers to its normal value.
1:1 Strengthener
While riding the e-bike, the motor should supply motor-driven power assistance at the same speed to make the ride easier.
Auto-cruising
When the handlebar is held at a certain position for more than 8 seconds, the microcontroller will enter into auto-cruising mode. In this mode, e-bike will keep running at its current speed even if you let go of the handlebar. The Auto-cruising mode can be released if you turn the handlebar again or when the brake is applied.
Other functions of e-bike controller include three speed, guard key, self-check, and Electric-ABS.
S3F84A5_APPLICATION NOTE_REV1.10 3 OVERVIEW OF S3F84A5 MICROCONTROLLER
Samsung Confidential 14
3 OVERVIEW OF S3F84A5 MICROCONTROLLER
The S3F84A5 single-chip CMOS microcontrollers are fabricated using the highly advanced CMOS process technology based on Samsung’s latest CPU architecture. It is ideal for use in a wide range of home applications and motor controller (especially for e-bike and other BLDC Motor applications).
The key features of S3F84A5 include:
SAM8 RC CPU core
400-byte general-purpose registers (RAM)
16K-byte full flash embedded ROM
Up to 10MHz main clock
Internal RC oscillator: 5% (typical) at full range of voltage and temperature
Four configurable I/O ports (total 24 pins)
17 interrupt sources with 17 vectors and 8 interrupt levels
One watchdog timer function (Basic Timer Overflow)
One 8-bit basic timer for oscillation stabilization
Two 8-bit timer/counter with time interval, PWM, and Capture mode (Timer B with interval and “8+2” bit PWM mode)
One 16-bit timer/counter with three operating modes: Interval timer, Capture, and PWM modes
10-bit resolution ADC with eight input channels, integrated sample and hold circuit, event trigger to start A/D converter conversion, and interrupt on ADC conversion complete.
8-bit PWM module, six output channels with two compare units, complementary or independent of output modes for each group, edge and center aligned waveform modes, programmable dead-time control for complementary mode, and three interrupt sources (one overflow and two match).
One asynchronous UART
Four low voltage reset (LVR) level: 2.3V/3.0V/3.9V
28-SOP package, 28-SSOP package, and 32-ELP package available
S3F84A5_APPLICATION NOTE_REV1.10 3 OVERVIEW OF S3F84A5 MICROCONTROLLER
VSS
(Vpp) TESTRxD/P0.0TxD/P0.1
nRESET/P0.2AVREF
INT0/ADC0/P1.0INT1/ADC1/P1.1
ADC2/P1.2ADC3/P1.3ADC4/P1.4ADC5/P1.5 P1.6/ADC6
P1.7/ADC7
123456789
1011121314 15
16
VDDP3.2/INT4 (SCLK)P3.1/INT3(SDAT)P3.0/INT2P2.7/T0OUT/PWM3AP2.6/T0CAP/PWM3BP2.5/TBOUTP2.4/T0CK/PWM2AP2.3/PWM2BP2.2/TACAPP2.1/TACK/PWM1AP2.0/TAOUT/PWM1B
282726252423222120191817
XOUT/P3.3XIN/P3.4
S3F84A5
(Top View)
28-SOP28-SSOP
Figure 3-1 S3F84A5 Pin Assignment (28-SOP/SSOP Package)
(Vp
p)T
ES
T
RxD
/P0.
0
1 2 3 4 5 6 7 8
(SD
AT
)IN
T3
/P3
.1
(SC
LK)I
NT
4/P
3.2
VD
D
VSS
Xo
ut/
P3
.3
Xin
/P3.
4
P1.1/ADC1/INT1
15
14
13
12
11
10
9 P0.1/TxD
P0.2/nRESET
AVREF
P1.0/ADC0/INT0
P1.2/ADC2
P1.3/ADC3
NC24
23
22 21 20
19
18
17
P1
.5/A
DC
5
P1.
6/A
DC
6
P1
.7/A
DC
7
P2
.0/T
AO
UT
/PW
M1B
P2
.1/T
AC
K/P
WM
1A
P2
.2/T
AC
AP
NC
P1
.4/A
DC
4
TBOUT/P2.5
PWM3B/T0CAP/P2.6
PWM3A/T0OUT/P2.7
INT2/P3.0
NC
NC
PWM2A/T0CK/P2.4
PWM2B/P2.3 25
26
27
28
29
30
31
32
16
S3F84A5
(Top View)
32-ELP
Figure 3-2 S3F84A5 Pin Assignment (32-ELP)
Samsung Confidential 15
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
4 REFERENCE DESIGN WITH S3F84A5
4.1 SYSTEM DIAGRAM OF S3F84A5
Samsung Confidential 16
Figure 4-1 shows the e-bike Controller system diagram when S3F84A5 is used for BLDC motor control.
BLDC
Motor
PowerBridgePWM
PWM 3APWM 3BPWM 2APWM 2BPWM 1APWM 1B
Phase APhase BPhase C
AMP
HandlebarVol.
Battery Vol .
FeedbackCur.
Ext. INT Ref.
Over-current
CMP
Hall AHall BHall C
Three Speed
Guard Key
1:1 Strengthener
Constant Speed
Self-check
EABS
60o/120o
SystemStatus Disp.
I/O
Brake
CPU
OSC/RST LVR
S3F84A5
Optional
ROMTimer
ADC
RAM
I/O
Figure 4-1 E-bike Controller System Diagram
The e-bike controller system includes:
Three external interrupts are used for getting position information from Hall sensors while one is used for brake mechanism.
One timer is used for counting the Hall interrupts in a fixed time to get speed information.
Three ADC channels are used for detecting battery voltage, handlebar voltage, and system feedback current.
PWM output directly controls the power bridge. Different duty cycle results in different vehicle speeds.
Remaining I/O can be used as advanced function input pins or system status indicating pins.
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
Samsung Confidential 17
Table 4-1 The Pins Assignment of E-bike Controller Solution based on S3F84A5
Pin No. Pin Name Pin Setting Function
1 VSS - Ground
2 XOUT/P3.3 Output @ XOUT Or Input @ P3.3
Ext. OSC output pin or Electrical ABS enable pin
3 XIN/P3.4 Input @ XIN Or Input @ P3.4
Ext. OSC output pin or Self-check enable pin
4 TEST - Test signal input pin
5 P0.0 Output Indicator (LED) for 1:1strengthener enable
6 P0.1 Output Indicator (LED) for Auto-cruise enable/disable. In other words, when you enable auto-cruise, the LED will be turned ON. The LED will be turned OFF when auto-cruise is disabled.
7 nRESET/P0.2 Output @ nRESET Or Input @ P0.2
Reset input Hall sensor 60/120 degree selection pin
8 AVREF - Reference voltage input of ADC
9 INT0/P1.0 Int. input (falling edge) System over-current protection pin
10 INT1/P1.1 Int. input (falling edge) Brake mechanism pin
11 ADC2/P1.2 ADC input System feedback current detection pin
12 ADC3/P1.3 ADC input Handlebar voltage detection pin
13 ADC4/P1.4 ADC input Battery voltage detection pin
14 P1.5 Input Auto-cruise enable pin
15 P1.6 Input Guard-key input pin
16 P1.7 Input Three speed button
17 PWM1B/P2.0 PWM / IO output Phase C low bridge control pin
18 PWM1A/P2.1 PWM / IO output Phase C high bridge control pin
19 TACAP/P2.2 Input (Capture) 1:1 strengthener input pin
20 PWM2B/P2.3 PWM / IO output Phase B low bridge control pin
21 PWM2A/P2.4 PWM / IO output Phase B high bridge control pin
22 TBOUT/P2.5 Output Self-check enable indicating LED
23 PWM3B/P2.0 PWM / IO output Phase A low bridge control pin
24 PWM3A/P2.1 PWM / IO output Phase A high bridge control pin
25 INT2/P3.0 Hall sensor C position detection pin
26 INT3/P3.1 Hall sensor B position detection pin
27 INT4/P3.2
Int. input (falling or rising edge changed at ISR)
Hall sensor A position detection pin
28 VDD - Power
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
4.2 MAIN BLOCKS IN REFERENCE DESIGN
The reference design can be divided into following main blocks: power supply, microcontroller, battery voltage detect, handlebar voltage detect, system feedback current detect, battery under-voltage protection, system over-current protection, brake mechanism, Hall sensor position detect, power MOSFET and driver.
4.2.1 POWER SUPPLY
There are three power levels in e-bike system. All are oriented from a +48V/+36V battery.
+48V/+36V can drive the power MOSFET directly.
+15V specifies the power supply of MOSFET driver ICs in power bridge.
+5V specifies the power supply of microcontroller and other devices.
S1 led (red) on the board indicates the power status.
+ C3
220uF/50V
VIN3
ADJ1
VOUT2
U1
LM317/CYL
INPUT1
OUTPUT3
GN
D2
7805
U2
7805
C7
104
D+1
J6
CON1
R2243 ohm
R14
330 ohm/2WR3330 ohm
S1LED
C8
104
+15V VDD
1
J5
CON1
R12.7 Kohm
+48V/+36V
+C1
47uF/50V
C6
104
+ C11
1000uF/65V
+ C24
100uF/50V
Figure 4-2 Power Supply
4.2.2 BATTERY VOLTAGE DETECT
Figure 4-3 shows the battery voltage detect circuit. The battery has two electrodes – positive and negative. In case of right polarity, diode D5 is turned on and it supplies the normal power. On the other hand, in case of wrong polarity, diode D5 is on the reverse voltage and it does not turn on. It can protect other devices in system including the MCU ADC input.
If ADC result is lower than a preset value, under voltage protection can be done. The battery in e-bike contains lead-acid. The voltage discharge cannot be too low; otherwise, it will cause permanent damage to the battery. ADC should detect this voltage during normal operation. If the battery voltage is less than a certain preset value, MCU will go into Under Voltage Protection mode.
Samsung Confidential 18
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
D51N4001
R46
10 Kohm
R48
10 Kohm
R47
2 KohmC17
104
D+
P1.4/ADC4
Figure 4-3 Battery Voltage Detect Circuit
4.2.3 HANDLEBAR VOLTAGE DETECT
Jumper S4 is used for speed limitation. When S4 is on connected, R61 is connected in parallel with R59, which makes the ADC input voltage much lower than the time S4 is off.
Samsung Confidential 19
P1.3/ADC3C22
104
C23
104
R61
20 Kohm
R60
1 Kohm
R592.49 Kohm
12
S4
CON2
123
S3
CON3
HL_VVDD
VDD
GND
Figure 4-4 Handlebar Voltage Detect and Speed Limited Circuit
4.2.4 SYSTEM FEEDBACK CURRENT DETECT
As shown in the figure, one LM358 op-amp is used for the measurement of system feedback current. Gain control resistors (R16, R17) guarantee the ADC input voltage within the range of 0 to +5V.
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
Samsung Confidential 20
3
21
84
-
+
U9A
LM358
R17
1 Kohm
R16
10 Kohm
C10
102
P1.2/ADC2
R181 Kohm
Feedback CurrentVfb
VDD
Figure 4-5 System Feedback Current Detect Circuit
4.2.5 OVER-CURRENT PROTECTION
The controller can judge over-current using two kinds of “outside” conditions:
First condition: The feedback current abruptly rises up to an unexpected value. This could be caused by MOSFET short or motor rotation blockage.
Second condition: The current is above a preset safe value (usually 50A), which is set for the system safety.
The former condition is realized by an external comparator (see Figure 4-6). On the other hand, the latter condition is realized by feedback current detection.
5
67
84
-
+
U9B
LM358R7
1 Kohm
R610 Kohm
R4
10 Kohm
R51 Kohm
VDD
C9
104
VDD
P1.0/INT0
VDD
VfbFeedback Current
Figure 4-6 System Over-current Protection Circuit
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
4.2.6 BRAKE MECHANISM
In this reference design, brake mechanism can support both high level and low level brake signals. As shown in
Samsung Confidential 21
Figure 4-7, whatever the brake signal is, P1.1 will have the following waveform.
No brake signal No brake signal
Brake
Figure 4-7 Brake Mechanism Waveform (P1.1)
R44
10 Kohm
VDD
R42
2 Kohm
1234
U18
CON4
Brake_Low
BK-L
Brake_High
R43
10 Kohm
VDD
D4
IN4148
C19 330 ohm
C18
104
BK-H
Q29013
Figure 4-8 Brake mechanism Circuit
4.2.7 HALL SENSOR POSITION DETECT
The synchronization between the rotor and rotating field requires knowledge of the rotor position. The BLDC motor used in this application has 3-hall sensors.
The hall sensor position detection circuit and velocity meter circuit is shown in Figure 4-9.
VDD
Q19013
R4149.9 Kohm
VDD
12
S2
CON2
H2GND
R4020 Kohm
VDD
R33 150 ohm
H2
R4910 Kohm
R50 330 ohm123456
U17
CON6
H3
R5110 Kohm
VMR5310 Kohm
R52 330 ohmR54 330 ohm
P3.2/INT4 H1P3.1/INT3P3.0/INT2
C12
104
C13
104
C14
104
Figure 4-9 Hall Sensor Position Detect and Velocity Meter Circuit
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
The output signal flow of sensors, which describes the electrical rotor position, is shown in
Samsung Confidential 22
Figure 4-10.
Eight possible signal combinations can be used as three sensors’ output. Two of these combinations are not valid for position detection and are usually caused by an open or short sensor line. Other six combinations will be detected by external interrupts both at the rising and falling edge.
1800 360 540 720
1 Electrical Cycle 1 Electrical Cycle
Hall
Sensor A
Hall
Sensor B
Hall
Sensor C
1 2 3 4 5 6 1 2 3 4 5 6 1 ......
Figure 4-10 Hall Sensor Position Waveform Diagram
4.2.8 POWER MOSFET AND DRIVER
Table 4-2 Sequence of Forward Rotating
Hall Sensor Input Active MOSFET Phase Current Sequence #
A B C H-Bridge L-Bridge A B C
1 0 0 1 C B Off DC- DC+
2 1 0 1 A B DC+ DC- Off
3 1 0 0 A C DC+ Off Dc-
4 1 1 0 B C Off DC+ DC-
5 0 1 0 B A DC- Dc+ Off
6 0 1 1 C A DC- Off DC+
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
Samsung Confidential 23
Table 4-3 Sequence of Reverse Rotating
Hall Sensor Input Active MOSFET Phase Current Sequence #
A B C H-Bridge L-Bridge A B C
1 0 0 1 B C Off DC+ DC-
2 0 1 1 A C DC+ Off DC-
3 0 1 0 A B DC+ DC- Off
4 1 1 0 C B Off DC- DC+
5 1 0 0 C A DC- Off DC+
6 1 0 1 B A DC- DC+ Off
The freewheeling function can be realized in two ways.
First is the non-synchronous rectification, where current is freewheeled by body-diode of the complementary MOSFET.
Second is synchronous rectification, where current is freewheeled directly by the complementary MOSFET.
In this reference design, non-synchronous rectification is implemented. Since the PWM module in S3F84A5 can realize dead time control, synchronous rectification can also be supported.
In non-synchronous rectification, there is no need to control the complementary MOSFET of the MOSFET driven by PWM signal. Thus, only two MOSFETs are in action at one time. The difference is one is driven by PWM signal for speed control, while the other is driven by full duty cycle PWM. (The effect is the same as a normal IO. It is just a trick for better synchronization between the active high and low bridge. Once the compare data is set for PWM module, all the PWM outputs have the same start point even if there is instruction delay when implemented by IOs).
Table 4-4 P2PWMOUT Register Configuration during Non-synchronous Rectification Mode
When the BLDC Motor is Forward Rotating
Hall Sensor Input P2PWMOUT Register Configuration Sequence #
A B C Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 HEX
1 0 0 1 0 0 x 0 1 x 1 0 2EH
2 1 0 1 1 0 x 0 1 x 0 0 ACH
3 1 0 0 1 0 x 0 0 x 0 1 A5H
4 1 1 0 0 0 x 1 0 x 0 1 35H
5 0 1 0 0 1 x 1 0 x 0 0 74H
6 0 1 1 0 1 x 0 0 x 1 0 66H
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
Samsung Confidential 24
Table 4-5 P2PWMOUT Register Configuration in Non-synchronous Rectification Mode
When the BLDC Motor is Backward Rotating
Hall Sensor Input P2PWMOUT Register Configuration Sequence #
A B C Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 HEX
1 0 0 1 0 0 x 1 0 x 0 1 35H
2 0 1 1 1 0 x 0 0 x 0 1 A5H
3 0 1 0 1 0 x 0 1 x 0 0 ACH
4 1 1 0 0 0 x 0 1 x 1 0 2EH
5 1 0 0 0 1 x 0 0 x 1 0 66H
6 1 0 1 0 1 x 1 0 x 0 0 74H
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
Samsung Confidential 25
1
J2
CON1
U375NF75
U475NF75
U
D+
U
R15
0.01 ohm
V
1
J3
CON1
P2.6/PWM3B
Vcc1
HIN2
LIN3
COM4
LO5Vs6HO7VB8
U10
IR2101
P2.7/PWM3A
D1
US1G
W
+15V
U575NF75
U675NF75
V
D+
P2.3/PWM2B
Vcc1
HIN2
LIN3
COM4
LO5Vs6HO7VB8
U11
IR2101
P2.4/PWM2A
D2
US1G
+15V
R10 33 ohm
R11 33 ohm
R21
330 ohmR22
330 ohm
+C2
3.3uF/25VPWM3A
PWM3B
U775NF75
U875NF75
D+
P2.0/PWM1B
Vcc1
HIN2
LIN3
COM4
LO5Vs6HO7VB8
U12
IR2101
P2.1/PWM1A
D3
US1G
PWM2A
+15V
R12 33 ohm
R13 33 ohm
R25
330 ohmR26
330 ohm
PWM2B
W
1
J1
CON1
R19
330 ohmR8 33 ohm
R9 33 ohm
PWM1A
+C4
3.3uF/25V
Vfb
R20
330 ohm
+C5
3.3uF/25V
PWM1B
Figure 4-11 Power MOSFET and Integrated Driver Circuit
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
4.2.9 OTHER FUNCTIONS
Table 4-6 Other Functions in E-bike Reference Design
No. E-bike Advanced Functions MCU I/O Note
1 Constant Speed Enable P1.5 Normal I/O
2 Guard Key P1.6 Normal I/O or IR receiving
3 Three Speed Button P1.7 Normal I/O or ADC input
4 1:1 Strengthener P2.2 Normal I/O or Capture input
5 Hall 60/120 degree Selection (Optional) P0.2 Shared with nRESET pin
6 E-ABS Enable (Optional) P3.3 Shared with XOUT pin
7 Self-check Enable (Optional) P3.4 Shared with XIN pin
Samsung Confidential 26
VDD
SEL_CK
60_120
THR_SD
R39330 ohm
Hall 60/120 degree
G_KEY
R3810 Kohm
R2810 Kohm
R2310 Kohm
R27330 ohm
Three Speed
R3010 KohmR29330 ohm
Gard-Key
R3210 KohmR31330 ohm
Constant Speed
P1.7
P1.6
R3410 KohmR35330 ohm
EABS
CST_SD
R3610 KohmR37330 ohm
Self-check
P1.5
XOUT/P3.3
XINT/P3.4
RST/P0.2
1_1ST P2.2R24330 ohm
1:1 Strengthener
E_ABS
E_ABS
60_1201_1ST
SEL_CK
THR_SDG_KEYCST_SD
1 23 45 67 89 10
11 1213 14
J4
CON14A
Figure 4-12 Other Function Input Selection Circuit
S3F84A5_APPLICATION NOTE_REV1.10 4 REFERENCE DESIGN WITH S3F84A5
4.2.10 DEBUGGER SOCKET
Samsung Confidential 27
Vss1
Xout/P3.32
Xin/P3.43
(Vpp)TEST4
RxD/P0.05
TxD/P0.16
nRESET/P0.27
AVref8
INT0/ADC0/P1.09
INT1/ADC1/P1.110
ADC2/P1.211
ADC3/P1.312
ADC4/P1.413
ADC5/P1.514
P1.6/ADC615P1.7/ADC716P2.0/TAOUT/PWM1B17P2.1/TACK/PWM1A18P2.2/TACAP19P2.3/PWM2B20P2.4/T0CK/PWM2A21P2.5/TBOUT22P2.6/T0CAP/PWM3B23P2.7/T0OUT/PWM3A24P3.0/INT225P3.1/INT3(SDAT)26P3.2/INT4(SCLK)27Vdd28
S3F84A5
28-SOP
U13
S3F84A5_28SOP
XOUT/P3.3GND
VPPXINT/P3.4
P0.0P0.1RST/P0.2AVREFP1.0/INT0P1.1/INT1P1.2/ADC2P1.3/ADC3P1.4/ADC4P1.5 P1.6
P1.7P2.0/PWM1BP2.1/PWM1AP2.2P2.3/PWM2BP2.4/PWM2AP2.5P2.6/PWM3BP2.7/PWM3AP3.0/INT2P3.1/INT3P3.2/INT4VDD
Figure 4-13 On-board Debugger Socket
4.2.11 PROGRAM INTERFACE
P3.1/INT3P3.2/INT4VDDGNDVPP
123456
U14
CON6
RST/P0.2
Figure 4-14 Program Interface
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
Samsung Confidential 28
5 SOFTWARE DESCRIPTION
5.1 OVERVIEW OF THE SOFTWARE USED IN E-BIKE CONTROLLER REFERENCE DESIGN
This section describes the software used in the e-bike controller reference design. The software is written in C language.
The software includes five parts, namely, head-files, variable definition, main, subroutine, and interrupt service subroutine. The source code is included in the Table 5-1.
Table 5-1 Routine lists of e-bike Controller Reference Design Software
No. Routine Name Description Note
1 Main(void) Main loop. Main routine
2 MCU_INIT(void) System registers and I/O initialization.
3 RAM_INIT(void) RAM initialization.
4 VARIABLE_INIT(void) System variables (buffers and flags) initialization.
5 BATVOL_DETECT(void) Battery voltage detection.
6 HANDVOL_DETECT(void) Handlebar voltage detection.
7 SYSCUR_DETECT(void) System feedback current detection.
8 BRAKE_PROTECT(void) Brake mechanism.
9 UNDERVOL_PROTECT(void) Battery under-voltage protection.
10 OVERCURRENT_PROTECT(void) System over-current protection.
11 SPEED_LOOP(void) Speed loop control.
12 CURRENT_LOOP(void) Current loop control.
13 START_PWM(void) Start PWM output by current motor position
14 INIT_PWM(void) PWM output initialization.
15 RESUME_PWM(void) Resume PWM output.
16 STOP_PWM(void) Stop PWM output.
17 DELAY_MS(unsigned int nms) Delay in microseconds.
Subroutine
18 INT0_ISR(void) Over-current interrupt protection.
19 INT1_ISR(void) Brake interrupt service.
20 INT2_ISR(void) Hall sensor A interrupt service.
21 INT3_ISR(void) Hall sensor B interrupt service.
22 INT4_ISR(void) Hall sensor C interrupt service.
Interrupt Service Subroutine
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
Samsung Confidential 29
No. Routine Name Description Note
23 T0_MAC_ISR(void) Timer 0 match interrupt service.
24 ADC_END_ISR(void) ADC conversion complete interrupt service.
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2 SOFTWARE FLOW
5.2.1 MAIN FLOW St
art
Init
ializ
e I/
O P
ort
Reg
iste
rs
Cle
ar B
asic
Tim
er
Cou
nter
& D
ivid
er
Init
iali
ze S
yste
m R
eg.s
(I
MR
, IPR
, BT
CO
N,
CL
KC
ON
, SPL
)
Init
ializ
e U
ser
Var
iabl
e
Dis
able
Glo
bal I
nter
rupt
Con
figu
re T
imer
0
Ope
ratio
n M
ode
(fxx
/8,
inte
rval
0.0
5s, e
nabl
e m
atch
int.)
Del
ay 1
00 m
icro
seco
nd
Ena
ble
Wat
ch-d
og
Cal
l Bat
tery
Vol
tage
D
etec
t
Bat
tery
U
nder
-vol
tage
?
Syst
em
Ove
r-cu
rren
t ?
Bra
ke ?
Cal
l Sys
tem
Cur
rent
D
etec
t
Syst
em C
urre
nt
is N
orm
al ?
Cal
l Han
dleb
ar V
olta
ge
Det
ect
Cal
cula
te P
WM
Dut
y
Cal
cula
ted
Val
ue >
Cur
rent
V
alue
?
Cal
l Han
dleb
ar V
olta
ge
Det
ect
Cal
cula
te U
ser-
set S
peed
Use
r-se
t Spe
ed>
C
urre
nt S
peed
?
STO
P P
WM
Del
ay 5
0 m
s
STO
P P
WM
Del
ay 5
0 m
s
Dec
reas
e PW
M D
uty
Cyc
le
Del
ay 5
0 m
s
Dec
reas
e PW
M D
uty
Cyc
le
Dec
reas
e PW
M D
uty
Cyc
le
Incr
ease
PW
M D
uty
Cyc
le
Incr
ease
Spe
ed
Dec
reas
e Sp
eed
Ext
. IN
T2
(Pha
se A
) IS
RE
xt. I
NT
4 (P
hase
C)
ISR
Ext
. IN
T3
(Pha
se B
) IS
R
Spe
ed C
ount
ing
Und
er-V
olta
ge
Pro
tect
ion
Ove
r-cu
rren
t P
rote
ctio
n Bra
ke
Pro
tect
ion
Cu
rren
t L
oop
Spe
ed L
oop
Ena
ble
Glo
bal I
nter
rupt
Init
ializ
atio
n
Y Y Y
N N N
Y
N N
Y
N
Y
Figure 5-1 Main Flow
NOTE: In Figure 5-1, functions are simplified. Therefore, they may not be the same as what is described in the subroutine flow.
Samsung Confidential 30
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2 SUBROUTINE FLOW
5.2.2.1 Battery Voltage Detect
Start
Init. R0, R1(Sum of Bat. Voltage)
nBatVol = (R0,R1) /4
ADC4 Conv. Complete?(EOC==1?)
Set Under-voltage Flag
Add ADDATAH value to R0,R1
(Sum of Bat. Voltage)
Clr Under-voltage Flag
End
N
Y
NSample Time ==4 ?
N
Y
Init. R2 ( ADC Sample Time )
nBatVol > LowBatVol ?
(31.5V @ Vbat=36V)
nBatVol < NorBatVol ?
(33V @ Vbat=36V)
Start ADC4 Conversion
Y
Y
N
Configure ADC4 Operation Mode
Figure 5-2 Battery Voltage Detect Subroutine Flow
Samsung Confidential 31
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.2 Handlebar Voltage Detect
Start
Init. R0, R1(Sum of Handlebar
Voltage)
nHandVol = (R0,R1) /4
ADC3 Conv. Complete?(EOC==1?)
Clear Handlebar ON Flag
Add ADDATAH value to R0,R1
(Sum of Handlebar Voltage)
End
N
Y
NSample Time ==4 ?
N
Y
Init. R2 ( ADC Sample Time )
nHandVol < Handlebar OFF
Vol. (1.05V) Start ADC3 Conversion
Y
Y
N
Configure ADC3 Operation Mode
nHandVol < Handlebar ON
Vol. (1.1V)
Handlebar is ON last time?
Set Handlebar ON Flag
nHandVol < Max. Handlebar Vol Value (4.5)?
Load Max. Handlebar Vol. Value to nHandVol
Load Init. Value to Port 2 Register
Load Init. Value to P2PWMOUT Register(Disable PWM Output)
Clear Phase Change Enable Flag
Call Resume PWM
Set Phase Change Enable Flag
N
Y
Brake is released ?
Y
N
Y
N
Figure 5-3 Handlebar Voltage Detect Subroutine Flow
Samsung Confidential 32
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.3 System Feedback Current Detect
Start
Init. R0,R1(Sum of System Current)
ADC2 Conv. Complete?
(nADCConvEndFlag != 0 ?)
Add ADDATAH value to batvol_sum
N
Y
NSample Time ==4 ?
Init. R2 ( ADC Sample Time )
Y
Conf. ADC2 Oper.Mode (PWM A group match
int. trigger)
Enable PWM A Group Match Interrupt
Clear nADCConvEndFlag
(ADC Conv. End Flag)
nSysCur = (R0, R1) /4
Load Init. Value to Port 2
Clr Over-current Flag
End
N
YnSysCur < Over-current ?
(16A)
Disable PWM Output
Stop PWM Counter
Clear Phase Change Enable Flag, Handlebar
ON Flag
Set Over-current Flag
Disable PWM A Group Match InterruptPWM Counter is
running ?Start ADC2 Conversion
Figure 5-4 System Feedback Current Detect Subroutine Flow
Samsung Confidential 33
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.4 Under-voltage Protection
Start
Clear Phase Change Enable Flag
End
CallBattery Voltage Detect
Battery Under-voltage ?
CallStop PWM
Clear Basic Timer Counter & Divider
Delay 50 microsecond
CallBattery Voltage Detect
Battery Under-voltage ?
CallHandlebar Voltage
Detect
Handlebar Voltage is ON ?
CallResume PWM
Set Phase Change Enable Flag
N
Y
Y
N
N
Y
Optional : those codes are included in Handlebar Voltage Detection subroutine
Clear Handlebar ON Flag
Delay 1 second
Figure 5-5 Battery Under-voltage Protection Subroutine Flow
Samsung Confidential 34
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.5 Over-current Protection
Start
Clear Phase Change Enable Flag
End
System Over-current ?
CallStop PWM
Clear Basic Timer Counter & Divider
Delay 50 microsecond
CallSystem Current Detect
System Current > Limited
Current ? (10A)
CallHandlebar Voltage
Detect
Handlebar Voltage is ON ?
CallResume PWM
Set Phase Change Enable Flag
N
Y
Y
N
N
Y
Ext. Over-current
Protection P1.0 keep LOW ?
N
Y
Clear System Over-current Flag
Clear Handlebar ON Flag
Optional : this code is included in System Current Detection subroutine
Optional : those codes are included in Handlebar Voltage Detection subroutine
Delay 2 seconds
Figure 5-6 System Over-current Protection Subroutine Flow
Samsung Confidential 35
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.6 Brake Mechanism
Start
Clear Phase Change Enable Flag
End
System Over-current ?
CallStop PWM
Clear Basic Timer Counter & Divider
Delay 50 microsecond
CallSystem Current Detect
System Current > Limited
Current ? (10A)
CallHandlebar Voltage
Detect
Handlebar Voltage is ON ?
CallResume PWM
Set Phase Change Enable Flag
N
Y
Y
N
N
Y
Ext. Over-current
Protection P1.0 keep LOW ?
N
Y
Clear System Over-current Flag
Figure 5-7 Brake Mechanism Subroutine Flow
Samsung Confidential 36
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.7 Constant Speed Control
Start
Load Min. Duty Cycle Value (33H) to R3
End
N
Load User-set Constant Speed Value to R7
Decrease R3 by One PWM Duty Step
Y
Load Current PWM Duty Value to R3
R7 (User-set Speed) >=
Current Speed ?
R3 > 33H ?(20% Duty
Cycle)
R7 (User-set Speed) ==
Current Speed ?
R3 < 252 ?
Load Max. Duty Cycle Value (0FFH) to R3
Add One PWM Duty Step to R3
Load R3 to Current PWM Duty Value
Calculate PWM B Group Duty Cycle Value
with 2us dead-time
Update PWM A&B Group Compare Data
Registers
N
Y
Y
N
N
Y
Figure 5-8 Constant Speed Control Subroutine Flow
Samsung Confidential 37
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.8 Speed Loop Control
Start
Load Handlebar Voltage Value to R8, R9
End
Load Max. Speed (Limited) Value to User-
set Constant Speed
Y
Call Handlebar Voltage Detect
Handlebar is ON ?
Current Speed < Max. Speed (Limited)?
Call Constant Speed Control
Y
N
N
Current Speed > Min. Speed?
Load Min. Speed Value to User-set Constant
Speed
Calculate User-set Speed Value = handlebar vol. *
0.794 – 10.68
User-set Speed < Current Speed ?
User-set Speed < 80% * Max.
Speed ?
Current Speed > 60% * Max.
Speed ?
Load Quick Value (9) to PWM Duty Step Value
User-set Speed > 30% * Max.
Speed ?
Current Speed < 50% * Max.
Speed ?
Load Nor. Value (2) to PWM Duty Step Value
Load Nor. Value (2) to PWM Duty Step Value
Y
Y
N
N
N
N
Y
Y
N
N
Y
Y
Speed Limited (Optional)
Figure 5-9 Speed Loop Control Subroutine Flow
Samsung Confidential 38
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.2.9 Current Loop Control
Start
Load Handlebar Voltage Value to R8, R9
End
Call System Current Detect
System is Over-current ?
System Current <12A (Limited)
Load R3 to Current PWM Duty
Y
N
Handlebar is ON ?
Calculate PWM Duty Value = handlebar vol. *
1.17 – 8.79
Current PWM Duty Value >= Calculate PWM
Duty Value?
Current PWM Duty Value <
252 ?
Load Max. PWM Duty Value (0FFH) to R3
Add One PWM Duty Step to R3
N
Y
YCall Handlebar Voltage
Detect
Load Current PWM Duty Value to R3
Current PWM Duty Value == Calculate PWM
Duty Value?
Decrease R3 with One PWM Duty Step
R3 >= 33 ?
Load Min. PWM Duty Value (33H) to R3
Calculate PWM B Group Duty with 2us
dead-time
Update PWM A&B Group Compare Date
Registers
Load Current PWM Duty Value to R3
Y
N
N
Y
N
N
Y
Y
N
Figure 5-10 Current Loop Control Subroutine Flow
Samsung Confidential 39
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.3 PWM CONTROL
5.2.3.1 A. Start PWM
Start PWMStart
Disable PWM Interrupt
Load Current PWM Duty Value to R3
Calculate PWM B Group Duty Value with
2us dead-time
Update PWM A&B Group Compare Date
Registers
Configure PWM Operation Mode (center-aligned, fxx/1, A Non-inverted, B Inverted)
Read P3 (Hall Sensor Position
Information )
Look up from Motor Position Table
Update Port 2 Value
Look up from Motor Position Table
Update P2PWMOUT Value
Start PWMEnd
Figure 5-11 Start PWM Control Subroutine Flow
Samsung Confidential 40
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.3.2 B. Initialization PWM
Initialize PWMStart
Load init. value (20%) to Current PWM Duty
Init. Port 2 Value
Init. P2PWMOUT Value(Disable PWM Output)
Call Start PWM
Initialize PWMEnd
Figure 5-12 Initialization PWM Control Subroutine Flow
5.2.3.3 C. Resume PWM
N
Y
N
Y
Resume PWMStart
Load Current Speed Value to R10,R11
Current Speed =< 10% * Max.
Speed ?
Current Speed >= 90% * Max.
Speed ?
nPWMDuty = (R10,R11) * 0.66
Load 33H (20%) to Current PWM Duty
Value
Load 0CCH (80%) to Current PWM Duty
Value
Call Start PWM
Resume PWMEnd
Figure 5-13 Resume PWM Control Subroutine Flow
Samsung Confidential 41
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.3.4 D. Stop PWM
Stop PWMStart
Load Init. Value to Port 2 Register
Load Init. Value to P2PWMOUT Register(Disable PWM Output)
Stop PWM Counter
Stop PWMEnd
Figure 5-14 Stop PWM Control Subroutine Flow
5.2.4 INTERRUPT SERVICE ROUTINE
5.2.4.1 A. External INT0 (Over-current Protection) ISR
Ext. INT0 ISRStart
Load Init. Value to Port 2 Register
Load Init. Value to P2PWMOUT Register(Disable PWM Output)
Stop PWM Counter
Clear Phase Change Enable Flag
Set System Over-current Flag
Ext. INT0 ISRReturn
Clear Ext. INT0 Pending Bit
Figure 5-15 External INT0 (Over-current Protection) Interrupt Service Routine Flow
Samsung Confidential 42
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.4.2 B. External INT1 (Brake Mechanism) ISR
Ext. INT1 ISRStart
Clear Ext. INT1 Pending Bit
Delay 0.8 micro-sencond
P1.1(Brake) keep LOW ?
Set Brake Flag
Ext. INT1 ISRReturn
Y
N
Figure 5-16 External INT1 (Brake Mechanism) Interrupt Service Routine Flow
Samsung Confidential 43
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.4.3 C. External INT2 ~ 4 (Phase A/B/C Change) ISR
Ext. INTx (x=2,3,4) ISRStart
Clear Ext. INTx Pending Bit (x=2,3,4)
Disable IRQ6 (Ext. INT2 ~ INT4)
Phase Change Enable ?
Read P3 (Hall Sensor Position
Information )
Look up from Motor Position Table
Update Port 2 Value
Look up from Motor Position Table
Update P2PWMOUT Value
Enable IRQ6 (Ext. INT2 ~ INT4)
Update Speed Counter
Re-configure P3CONL to change INT edge
(Falling/Rising)
Clear Ext. INTx Pending Bit (x=2,3,4)
Ext. INTx (x=2,3,4) ISR
Return
N
Y
Figure 5-17 External INT2 ~ 4 (Phase A/B/C Change) Interrupt Service Routine Flow
Samsung Confidential 44
S3F84A5_APPLICATION NOTE_REV1.10 5 SOFTWARE DESCRIPTION
5.2.4.4 D. Timer 0 Match Interrupt (Speed Counting) ISR
Timer 0 Match ISRStart
Timer 0 Match ISRReturn
Clear Timer 0 Match Interrupt Pending Bit
Clear Timer Piece Counter
Y
Update Timer Piece Counter
Timer Piece Counter < 4 ?(0.2 second)
Load Speed Counter Value to Current Speed
Value
Clear Speed Counter
N
Figure 5-18 Timer 0 Match (Speed Counting) Interrupt Service Routine Flow
Samsung Confidential 45
S3F84A5_APPLICATION NOTE_REV1.10 6 APPENDIX I: SCHEMATIC DIAGRAM OF REFERENCE DESIGN
6 APPENDIX I: SCHEMATIC DIAGRAM OF REFERENCE DESIGN
Figure 6-1 Schematic Diagram of E-bike Controller Reference Design
Double click to open
Samsung Confidential 46
Figure 6-1 in Adobe Reader.
S3F84A5_APPLICATION NOTE_REV1.10 7 APPENDIX II: DEMO SYSTEM
7 APPENDIX II: DEMO SYSTEM
Target Board
BLDC MotorControl Board
Power Supply
Samsung Confidential 47
Brake Handlebar
Figure 7-1 E-bike Controller Reference Design Demo System
+24V DC power is supplied to the control board.
Target board is used to simulate and debug software.
Control board contains MCU, detection circuits (battery voltage, handlebar, feedback current, and hall sensor position), protection circuits (battery under-voltage and over-current), brake mechanism, power MOSFET, and driver. BLDC motor is a 3-phase +24V DC brushless motor.
Handlebar is used to control motor speed while brake is used to decrease speed and stop the motor.
Figure 7-1 and Figure 7-2 show the demo system. Figure 7-2, Figure 7-3, Figure 7-4, and Figure 7-5 show the hall sensor positions and 3-phase waveform when motor is operating at full speed and low speed.
S3F84A5_APPLICATION NOTE_REV1.10 7 APPENDIX II: DEMO SYSTEM
Figure 7-2 E-bike Controller Reference Design Control Board
Samsung Confidential 48
S3F84A5_APPLICATION NOTE_REV1.10 7 APPENDIX II: DEMO SYSTEM
Figure 7-3 E-bike Controller Hall Sensor Position Real Waveform Diagram (Full Speed)
Figure 7-4 E-bike Controller 3-Phases Real Waveform Diagram (Full Speed)
Samsung Confidential 49
S3F84A5_APPLICATION NOTE_REV1.10 7 APPENDIX II: DEMO SYSTEM
Figure 7-5 E-bike Controller Hall Sensor Position Real Waveform Diagram (Low Speed)
Figure 7-6 E-bike Controller 3-Phases Real Waveform Diagram (Low Speed)
Samsung Confidential 50
S3F84A5_APPLICATION NOTE_REV1.10 8 APPENDIX III: SOURCE CODE
8 APPENDIX III: SOURCE CODE
Appendix III SW.doc
Samsung Confidential 51