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 :
FAX :
(82)-(031)-209-4356
(82)-(031)-209-3262
Home Page: http://www.samsungsemi.com
Printed in the Republic of Korea
Revision History
Revision No.
Date
0
1.10
Description
- Initial draft
Jan. 20, 2010
Author(s)
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
Number
Title
Page
Number
Figure 2-1
Figure 2-2
Figure 2-3
Bicycle Style and Scooter Style Electric Bikes ...................................................................................10
General System Diagram of e-bike.....................................................................................................11
BLDC Motor Mechanical Structure .....................................................................................................12
Figure 3-1
Figure 3-2
S3F84A5 Pin Assignment (28-SOP/SSOP Package) ........................................................................15
S3F84A5 Pin Assignment (32-ELP) ...................................................................................................15
Figure 4-1
Figure 4-2
Figure 4-3
Figure 4-4
Figure 4-5
Figure 4-6
Figure 4-7
Figure 4-8
Figure 4-9
Figure 4-10
Figure 4-11
Figure 4-12
Figure 4-13
Figure 4-14
E-bike Controller System Diagram .......................................................................................................16
Power Supply......................................................................................................................................18
Battery Voltage Detect Circuit.............................................................................................................19
Handlebar Voltage Detect and Speed Limited Circuit ........................................................................19
System Feedback Current Detect Circuit ...........................................................................................20
System Over-current Protection Circuit ..............................................................................................20
Brake Mechanism Waveform (P1.1)...................................................................................................21
Brake mechanism Circuit....................................................................................................................21
Hall Sensor Position Detect and Velocity Meter Circuit......................................................................21
Hall Sensor Position Waveform Diagram .........................................................................................22
Power MOSFET and Integrated Driver Circuit .................................................................................25
Other Function Input Selection Circuit..............................................................................................26
On-board Debugger Socket..............................................................................................................27
Program Interface .............................................................................................................................27
Figure 5-1
Figure 5-2
Figure 5-3
Figure 5-4
Figure 5-5
Figure 5-6
Figure 5-7
Figure 5-8
Figure 5-9
Figure 5-10
Figure 5-11
Figure 5-12
Figure 5-13
Figure 5-14
Figure 5-15
Figure 5-16
Figure 5-17
Figure 5-18
Main Flow............................................................................................................................................30
Battery Voltage Detect Subroutine Flow.............................................................................................31
Handlebar Voltage Detect Subroutine Flow .......................................................................................32
System Feedback Current Detect Subroutine Flow ...........................................................................33
Battery Under-voltage Protection Subroutine Flow ............................................................................34
System Over-current Protection Subroutine Flow ..............................................................................35
Brake Mechanism Subroutine Flow....................................................................................................36
Constant Speed Control Subroutine Flow ..........................................................................................37
Speed Loop Control Subroutine Flow.................................................................................................38
Current Loop Control Subroutine Flow .............................................................................................39
Start PWM Control Subroutine Flow.................................................................................................40
Initialization PWM Control Subroutine Flow .....................................................................................41
Resume PWM Control Subroutine Flow...........................................................................................41
Stop PWM Control Subroutine Flow.................................................................................................42
External INT0 (Over-current Protection) Interrupt Service Routine Flow .........................................42
External INT1 (Brake Mechanism) Interrupt Service Routine Flow..................................................43
External INT2 ~ 4 (Phase A/B/C Change) Interrupt Service Routine Flow ......................................44
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
Figure 7-2
Figure 7-3
Figure 7-4
Figure 7-5
Figure 7-6
E-bike Controller Reference Design Demo System ...........................................................................47
E-bike Controller Reference Design Control Board............................................................................48
E-bike Controller Hall Sensor Position Real Waveform Diagram (Full Speed) ..................................49
E-bike Controller 3-Phases Real Waveform Diagram (Full Speed) ...................................................49
E-bike Controller Hall Sensor Position Real Waveform Diagram (Low Speed) .................................50
E-bike Controller 3-Phases Real Waveform Diagram (Low Speed)...................................................50
List of Tables
Table
Number
Title
Page
Number
Table 4-1
Table 4-2
Table 4-3
Table 4-4
Table 4-5
Table 4-6
The Pins Assignment of E-bike Controller Solution based on S3F84A5 .............................................17
Sequence of Forward Rotating ............................................................................................................22
Sequence of Reverse Rotating ............................................................................................................23
P2PWMOUT Register Configuration during Non-synchronous Rectification Mode ............................23
P2PWMOUT Register Configuration in Non-synchronous Rectification Mode ...................................24
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
1 ELECTRIC BIKE CONTROLLER SYSTEM
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.
Samsung Confidential
9
S3F84A5_APPLICATION NOTE_REV1.10
2
2 OVERVIEW OF ELECTRIC BIKES
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 lowspeed 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 MOSFET
Bridge Driver
Power
MOSFET
Current
Limited Circuit
BLDC
Motor
Hall Rotor Sensor
Position Detection
Microcontroller
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 3phase 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
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.
Samsung Confidential
13
S3F84A5_APPLICATION NOTE_REV1.10
3
3 OVERVIEW OF S3F84A5 MICROCONTROLLER
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
Samsung Confidential
14
S3F84A5_APPLICATION NOTE_REV1.10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
S3F84A5
(Top View)
28-SOP
28-SSOP
PWM2A/T0CK/P2.4
26
TBOUT/P2.5
27
PWM3B/T0CAP/P2.6
P1.7/ADC7
P1.6/ADC6
P1.5/ADC5
20
19
18
28
(Top View)
32-ELP
P1.4/ADC4
P2.0/TAOUT/PWM1B
21
S3F84A5
17
P2.1/TACK/PWM1A
22
25
P2.2/TACAP
24
PWM2B/P2.3
VDD
P3.2/INT4 (SCLK)
P3.1/INT3(SDAT)
P3.0/INT2
P2.7/T0OUT/PWM3A
P2.6/T0CAP/PWM3B
P2.5/TBOUT
P2.4/T0CK/PWM2A
P2.3/PWM2B
P2.2/TACAP
P2.1/TACK/PWM1A
P2.0/TAOUT/PWM1B
P1.7/ADC7
P1.6/ADC6
S3F84A5 Pin Assignment (28-SOP/SSOP Package)
NC
Figure 3-1
28
27
26
25
24
23
22
21
20
19
18
17
16
15
23
VSS
XOUT/P3.3
XIN/P3.4
(Vpp) TEST
RxD/P0.0
TxD/P0.1
nRESET/P0.2
AVREF
INT0/ADC0/P1.0
INT1/ADC1/P1.1
ADC2/P1.2
ADC3/P1.3
ADC4/P1.4
ADC5/P1.5
3 OVERVIEW OF S3F84A5 MICROCONTROLLER
16
NC
15
P1.3/ADC3
14
P1.2/ADC2
13
P1.1/ADC1/INT1
12
P1.0/ADC0/INT0
8
RxD/P0.0
(SDAT)INT3/P3.1
Figure 3-2
7
9
(Vpp)TEST
32
6
NC
Xin/P3.4
P0.2/nRESET
5
10
Xout/P3.3
31
4
NC
VSS
AVREF
3
11
VDD
30
2
INT2/P3.0
(SCLK)INT4/P3.2
29
1
PWM3A/T0OUT/P2.7
P0.1/TxD
S3F84A5 Pin Assignment (32-ELP)
Samsung Confidential
15
S3F84A5_APPLICATION NOTE_REV1.10
4
4 REFERENCE DESIGN WITH S3F84A5
REFERENCE DESIGN WITH S3F84A5
4.1 SYSTEM DIAGRAM OF S3F84A5
Figure 4-1 shows the e-bike Controller system diagram when S3F84A5 is used for BLDC motor control.
Constant Speed
OSC/RST
LVR
Guard Key
Three Speed
S3F84A5
PWM
1:1 Strengthener
I/O
CPU
EABS
PWM 3A
PWM 3B
PWM 2A
PWM 2B
PWM 1A
PWM 1B
Phase A
Phase B
Phase C
BLDC
Motor
Feedback
Cur.
Self-check
RAM
60o/120o
Power
Bridge
AMP
Timer
ROM
ADC
Optional
I/O
Handlebar
Vol.
Ext. INT
Battery Vol .
Ref .
CMP
Over-current
System
Status Disp.
Hall A
Hall B
Hall C
Brake
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.
Samsung Confidential
16
S3F84A5_APPLICATION NOTE_REV1.10
Table 4-1
4 REFERENCE DESIGN WITH S3F84A5
The Pins Assignment of E-bike Controller Solution based on S3F84A5
Pin No.
Pin Name
1
VSS
2
Pin Setting
Function
-
Ground
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
Int. input (falling or rising
edge changed at ISR)
27
INT4/P3.2
28
VDD
Hall sensor B position detection pin
Hall sensor A position detection pin
-
Power
Samsung Confidential
17
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 overcurrent 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.
+48V/+36V
U1
R14
1
330 ohm/2W
CON1
+ C11
J5
C1
+
VIN
VOUT
2
1
ADJ
+ C3
C6
C7
220uF/50V 104
47uF/50V
VDD
INPUT OUTPUT
780
5
LM317/CYL
1000uF/65V
1
U2
+15V
3
1
GND
D+
104
CON1
7805
2
J6
R2
243 ohm
3
+ C24
100uF/50V
C8
R3
330 ohm
104
S1
LED
R1
2.7 Kohm
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
D+
D5
1N4001
R46
10 Kohm
R48
10 Kohm
P1.4/ADC4
R47
C17
2 Kohm
104
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.
S4
2
1
CON2
VDD
C23
R59
2.49 Kohm
104
S3
R60
P1.3/ADC3
C22
R61
104
1 Kohm
HL_V 1
VDD 2
GND 3
20 Kohm
CON3
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.
Samsung Confidential
19
S3F84A5_APPLICATION NOTE_REV1.10
4 REFERENCE DESIGN WITH S3F84A5
Vfb
Feedback Current
VDD
8
P1.2/ADC2
3
+
1
2
LM358
4
C10
R18
1 Kohm
U9A
102
R17
R16
10 Kohm
Figure 4-5
1 Kohm
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.
Vfb
VDD
4
8
LM358
6
+
10 Kohm
7
R5
1 Kohm
U9B
-
R4
P1.0/INT0
Feedback Current
VDD
5
R6
10 Kohm
R7
VDD
C9
1 Kohm
104
Figure 4-6
System Over-current Protection Circuit
Samsung Confidential
20
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
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)
VDD
Brake_Low
D4
U18
R44
VDD
10 Kohm
1
BK-L 2
BK-H 3
4
IN4148
C19 330 ohm
R43
C18
Q2
9013
R42 10 Kohm
104
CON4
Brake_High
2 Kohm
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
R40
20 Kohm
S2
1
2
CON2
VDD
R33 150 ohm
VM
49.9 Kohm
Q1
9013
R41
R49
10 Kohm
R51
10 Kohm
R53
10 Kohm
U17
P3.2/INT4 R50
P3.1/INT3 R52
P3.0/INT2 R54
VDD
H1
H2
H3
GND
330 ohm
330 ohm
330 ohm
H2
1
2
3
4
5
6
CON6
Figure 4-9
C12
C13
C14
104
104
104
Hall Sensor Position Detect and Velocity Meter Circuit
Samsung Confidential
21
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 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.
1 Electrical Cycle
0
...
1 Electrical Cycle
180
1
2
3
360
4
5
6
540
1
2
3
720
4
5
6
1
...
Hall
Sensor A
Hall
Sensor B
Hall
Sensor C
Figure 4-10
Hall Sensor Position Waveform Diagram
4.2.8 POWER MOSFET AND DRIVER
Table 4-2
Sequence #
Hall Sensor Input
Sequence of Forward Rotating
Active MOSFET
Phase Current
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+
Samsung Confidential
22
S3F84A5_APPLICATION NOTE_REV1.10
4 REFERENCE DESIGN WITH S3F84A5
Table 4-3
Sequence of Reverse Rotating
Hall Sensor Input
Sequence #
Active MOSFET
Phase Current
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
Sequence #
Hall Sensor Input
P2PWMOUT Register Configuration
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
Samsung Confidential
23
S3F84A5_APPLICATION NOTE_REV1.10
Table 4-5
4 REFERENCE DESIGN WITH S3F84A5
P2PWMOUT Register Configuration in Non-synchronous Rectification Mode
When the BLDC Motor is Backward Rotating
Sequence #
Hall Sensor Input
P2PWMOUT Register Configuration
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
Samsung Confidential
24
S3F84A5_APPLICATION NOTE_REV1.10
4 REFERENCE DESIGN WITH S3F84A5
+15V
D1
D+
C2
US1G
R19
PWM3A
U10
P2.7/PWM3A
1
2
3
4
330 ohm
R20
PWM3B
P2.6/PWM3B
Vcc
HIN
LIN
COM
U3
75NF75
+
VB
HO
Vs
LO
U
8
7
6
5
R8
33 ohm
R9
33 ohm
1
U
CON1
U4
75NF75
IR2101
330 ohm
+15V
J1
3.3uF/25V
D2
D+
C4
US1G
R21
PWM2A
U11
P2.4/PWM2A
1
2
3
4
330 ohm
R22
PWM2B
P2.3/PWM2B
Vcc
HIN
LIN
COM
U5
75NF75
+
J2
3.3uF/25V
VB
HO
Vs
LO
V
8
7
6
5
R10
33 ohm
R11
33 ohm
1
V
CON1
U6
75NF75
IR2101
330 ohm
Vfb
+15V
D3
D+
R15
C5
US1G
R25
PWM1A
P2.1/PWM1A
330 ohm
R26
PWM1B
1
2
3
4
P2.0/PWM1B
Vcc
HIN
LIN
COM
U7
75NF75
+
U12
3.3uF/25V
VB
HO
Vs
LO
8
7
6
5
W
R12
1
33 ohm
W
R13
CON1
33 ohm
IR2101
330 ohm
Figure 4-11
0.01 ohm
J3
U8
75NF75
Power MOSFET and Integrated Driver Circuit
Samsung Confidential
25
S3F84A5_APPLICATION NOTE_REV1.10
4 REFERENCE DESIGN WITH S3F84A5
4.2.9 OTHER FUNCTIONS
Table 4-6
No.
Other Functions in E-bike Reference Design
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
VDD
1:1 Strengthener
Three Speed
Gard-Key
Constant Speed
EABS
Self-check
Hall 60/120 degree
1_1ST
R23
10 Kohm
R24
330 ohm
P2.2
THR_SD
R28
10 Kohm
R27
330 ohm
P1.7
G_KEY
R30
10 Kohm
R29
330 ohm
P1.6
CST_SD
R32
10 Kohm
R31
330 ohm
P1.5
E_ABS
R34
10 Kohm
R35
330 ohm
SEL_CK
R36
10 Kohm
R37
330 ohm
XINT/P3.4
60_120
R38
10 Kohm
R39
330 ohm
RST/P0.2
Figure 4-12
XOUT/P3.3
J4
E_ABS 1
SEL_CK 3
60_120 5
1_1ST 7
THR_SD 9
G_KEY 11
CST_SD 13
2
4
6
8
10
12
14
CON14A
Other Function Input Selection Circuit
Samsung Confidential
26
S3F84A5_APPLICATION NOTE_REV1.10
4 REFERENCE DESIGN WITH S3F84A5
4.2.10 DEBUGGER SOCKET
U13
GND
1
XOUT/P3.32
XINT/P3.4 3
VPP
4
P0.0
5
P0.1
6
RST/P0.2 7
AVREF
8
P1.0/INT0 9
P1.1/INT1 10
P1.2/ADC211
P1.3/ADC312
P1.4/ADC413
P1.5
14
Vss
Xout/P3.3
Xin/P3.4
(Vpp)TEST
RxD/P0.0
TxD/P0.1
nRESET/P0.2
AVref
INT0/ADC0/P1.0
INT1/ADC1/P1.1
ADC2/P1.2
ADC3/P1.3
ADC4/P1.4
ADC5/P1.5
Vdd
P3.2/INT4(SCLK)
P3.1/INT3(SDAT)
P3.0/INT2
P2.7/T0OUT/PWM3A
P2.6/T0CAP/PWM3B
P2.5/TBOUT
S3F84A5
P2.4/T0CK/PWM2A
P2.3/PWM2B
28-SOP
P2.2/TACAP
P2.1/TACK/PWM1A
P2.0/TAOUT/PWM1B
P1.7/ADC7
P1.6/ADC6
28
27
26
25
24
23
22
21
20
19
18
17
16
15
VDD
P3.2/INT4
P3.1/INT3
P3.0/INT2
P2.7/PWM3A
P2.6/PWM3B
P2.5
P2.4/PWM2A
P2.3/PWM2B
P2.2
P2.1/PWM1A
P2.0/PWM1B
P1.7
P1.6
S3F84A5_28SOP
Figure 4-13
On-board Debugger Socket
4.2.11 PROGRAM INTERFACE
U14
RST/P0.2
P3.1/INT3
P3.2/INT4
VDD
GND
VPP
1
2
3
4
5
6
CON6
Figure 4-14
Program Interface
Samsung Confidential
27
S3F84A5_APPLICATION NOTE_REV1.10
5
5 SOFTWARE DESCRIPTION
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
No.
Routine lists of e-bike Controller Reference Design Software
Routine Name
Description
Note
1
Main(void)
Main loop.
Main routine
2
MCU_INIT(void)
System registers and I/O initialization.
Subroutine
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.
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.
Samsung Confidential
Interrupt
Service
Subroutine
28
S3F84A5_APPLICATION NOTE_REV1.10
No.
Routine Name
5 SOFTWARE DESCRIPTION
Description
23
T0_MAC_ISR(void)
Timer 0 match interrupt service.
24
ADC_END_ISR(void)
ADC conversion complete interrupt service.
Samsung Confidential
Note
29
Initialization
Figure 5-1
Samsung Confidential
Brake
Protection
Over-current
Protection
Enable Watch-dog
Configure Timer 0
Operation Mode (fxx/8,
interval 0.05s, enable
match int.)
Initialize User Variable
Enable Global Interrupt
Initialize I/O Port
Registers
Initialize System Reg.s
(IMR, IPR, BTCON,
CLKCON, SPL)
Disable Global Interrupt
Start
N
Brake ?
N
System
Over-current ?
N
Battery
Under-voltage ?
Call Battery Voltage
Detect
Delay 100 microsecond
Clear Basic Timer
Counter & Divider
Y
Y
Y
Decrease PWM Duty
Cycle
Delay 50 ms
STOP PWM
Delay 50 ms
STOP PWM
Delay 50 ms
Under-Voltage
Protection
N
N
Speed Loop
Increase Speed
Y
User-set Speed>
Current Speed ?
N
Calculate User-set Speed
Call Handlebar Voltage
Detect
Increase PWM Duty
Cycle
Y
Calculated
Value > Current
Value ?
Calculate PWM Duty
Call Handlebar Voltage
Detect
Y
System Current
is Normal ?
Call System Current
Detect
Decrease Speed
Speed Counting
Ext. INT2 (Phase A) ISR
Ext. INT4 (Phase C) ISR
Ext. INT3 (Phase B) ISR
Decrease PWM Duty
Cycle
Decrease PWM Duty
Cycle
Current Loop
S3F84A5_APPLICATION NOTE_REV1.10
5 SOFTWARE DESCRIPTION
5.2 SOFTWARE FLOW
5.2.1 MAIN FLOW
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.
30
S3F84A5_APPLICATION NOTE_REV1.10
5 SOFTWARE DESCRIPTION
5.2.2 SUBROUTINE FLOW
5.2.2.1 Battery Voltage Detect
Start
Configure ADC4
Operation Mode
Init. R2
( ADC Sample Time )
Init. R0, R1
(Sum of Bat. Voltage)
Start ADC4 Conversion
N
ADC4 Conv.
Complete?
(EOC==1?)
Y
Add ADDATAH value
to R0,R1
(Sum of Bat. Voltage)
Sample Time
==4 ?
N
Y
nBatVol = (R0,R1) /4
nBatVol >
LowBatVol ?
(31.5V @
Vbat=36V)
N
Y
Y
nBatVol <
NorBatVol ?
(33V @
Vbat=36V)
Set Under-voltage Flag
N
Clr Under-voltage Flag
End
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
Configure ADC3
Operation Mode
Init. R2
( ADC Sample Time )
Init. R0, R1
(Sum of Handlebar
Voltage)
nHandVol <
Handlebar OFF
Vol. (1.05V)
Start ADC3 Conversion
Y
N
N
Y
ADC3 Conv.
Complete?
(EOC==1?)
Load Init. Value to Port
2 Register
nHandVol <
Handlebar ON
Vol. (1.1V)
Load Init. Value to
P2PWMOUT Register
(Disable PWM Output)
N
Y
Add ADDATAH value
to R0,R1
(Sum of Handlebar
Voltage)
Y
Handlebar is ON
last time?
Clear Phase Change
Enable Flag
N
Sample Time
==4 ?
N
N
Clear Handlebar ON
Flag
Brake is
released ?
Y
Y
nHandVol = (R0,R1) /4
Call Resume PWM
Set Phase Change
Enable Flag
Set Handlebar ON Flag
nHandVol <
Max. Handlebar
Vol Value (4.5)?
Y
N
Load Max. Handlebar
Vol. Value to nHandVol
End
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
Conf. ADC2 Oper.Mode
(PWM A group match
int. trigger)
Init. R2
( ADC Sample Time )
Init. R0,R1
(Sum of System Current)
Enable PWM A Group
Match Interrupt
Disable PWM A Group
Match Interrupt
PWM Counter is
running ?
Start ADC2 Conversion
nSysCur = (R0, R1) /4
ADC2 Conv.
Complete?
(nADCConvEnd
Flag != 0 ?)
N
nSysCur < Overcurrent ?
(16A)
Y
Clear
nADCConvEndFlag
(ADC Conv. End Flag)
Y
N
Load Init. Value to
Port 2
Clr Over-current Flag
Add ADDATAH value
to batvol_sum
Disable PWM Output
Sample Time
==4 ?
N
Stop PWM Counter
Y
Clear Phase Change
Enable Flag, Handlebar
ON Flag
Set Over-current Flag
End
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
Call
Battery Voltage Detect
Battery Undervoltage ?
N
Y
Call
Stop PWM
Clear Phase Change
Enable Flag
Clear Handlebar ON
Flag
Clear Basic Timer
Counter & Divider
Delay 50 microsecond
Call
Battery Voltage Detect
Y
Battery Undervoltage ?
N
Delay 1 second
Call
Handlebar Voltage
Detect
Optional : those codes
are included in
Handlebar Voltage
Detection subroutine
N
Handlebar
Voltage is ON ?
Y
Call
Resume PWM
Set Phase Change
Enable Flag
End
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
System Overcurrent ?
N
Y
Call
Stop PWM
Clear Phase Change
Enable Flag
Clear Handlebar ON
Flag
Clear Basic Timer
Counter & Divider
Delay 50 microsecond
Y
Ext. Overcurrent
Protection P1.0
keep LOW ?
N
Call
System Current Detect
Optional : this code is
included in System
Current Detection
subroutine
System Current
> Limited
Current ? (10A)
Y
N
Clear System Overcurrent Flag
Delay 2 seconds
Call
Handlebar Voltage
Detect
Optional : those codes
are included in
Handlebar Voltage
Detection subroutine
N
Handlebar
Voltage is ON ?
Y
Call
Resume PWM
Set Phase Change
Enable Flag
End
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
System Overcurrent ?
N
Y
Call
Stop PWM
Clear Phase Change
Enable Flag
Clear Basic Timer
Counter & Divider
Delay 50 microsecond
Y
Ext. Overcurrent
Protection P1.0
keep LOW ?
N
Call
System Current Detect
System Current
> Limited
Current ? (10A)
Y
N
Call
Handlebar Voltage
Detect
N
Handlebar
Voltage is ON ?
Y
Call
Resume PWM
Set Phase Change
Enable Flag
Clear System Overcurrent Flag
End
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 Current PWM
Duty Value to R3
Load User-set Constant
Speed Value to R7
R7 (User-set
Speed) >=
Current Speed ?
N
Decrease R3 by One
PWM Duty Step
Y
R7 (User-set
Speed) ==
Current Speed ?
Y
N
N
R3 > 33H ?
(20% Duty
Cycle)
Y
N
R3 < 252 ?
Load Min. Duty Cycle
Value (33H) to R3
Y
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
End
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
Call Handlebar Voltage
Detect
Handlebar is
ON ?
N
Y
N
Load Max. Speed
(Limited) Value to Userset Constant Speed
Y
N
Load Min. Speed Value
to User-set Constant
Speed
Speed Limited
(Optional)
Current Speed <
Max. Speed
(Limited)?
Current Speed >
Min. Speed?
Y
Load Handlebar Voltage
Value to R8, R9
Calculate User-set Speed
Value = handlebar vol. *
0.794 – 10.68
Y
User-set Speed <
Current Speed ?
N
Y
User-set Speed >
30% * Max.
Speed ?
User-set Speed <
80% * Max.
Speed ?
N
N
Y
Current Speed <
50% * Max.
Speed ?
Current Speed >
60% * Max.
Speed ?
N
Load Nor. Value (2) to
PWM Duty Step Value
Y
Y
N
Load Quick Value (9) to
PWM Duty Step Value
Load Nor. Value (2) to
PWM Duty Step Value
Call Constant Speed
Control
End
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
Call System Current
Detect
System is Overcurrent ?
Y
N
N
System Current
<12A (Limited)
Y
Load Current PWM
Duty Value to R3
Call Handlebar Voltage
Detect
Handlebar is
ON ?
N
Y
Load Handlebar Voltage
Value to R8, R9
Calculate PWM Duty
Value = handlebar vol. *
1.17 – 8.79
Y
Current PWM
Duty Value ==
Calculate PWM
Duty Value?
Load Current PWM
Duty Value to R3
N
Y
Decrease R3 with One
PWM Duty Step
Current PWM
Duty Value >=
Calculate PWM
Duty Value?
N
R3 >= 33 ?
Y
Current PWM
Duty Value <
252 ?
N
Load Min. PWM Duty
Value (33H) to R3
N
Y
Add One PWM Duty
Step to R3
Load Max. PWM Duty
Value (0FFH) to R3
Load R3 to Current
PWM Duty
Calculate PWM B
Group Duty with 2us
dead-time
Update PWM A&B
Group Compare Date
Registers
End
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 PWM
Start
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 (centeraligned, fxx/1, A Noninverted, 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 PWM
End
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 PWM
Start
Load init. value (20%) to
Current PWM Duty
Init. Port 2 Value
Init. P2PWMOUT Value
(Disable PWM Output)
Call Start PWM
Initialize PWM
End
Figure 5-12
Initialization PWM Control Subroutine Flow
5.2.3.3 C. Resume PWM
Resume PWM
Start
Load Current Speed
Value to R10,R11
Y
Current Speed
=< 10% * Max.
Speed ?
N
Current Speed
>= 90% * Max.
Speed ?
Load 33H (20%) to
Current PWM Duty
Value
N
nPWMDuty =
(R10,R11) * 0.66
Y
Load 0CCH (80%) to
Current PWM Duty
Value
Call Start PWM
Resume PWM
End
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 PWM
Start
Load Init. Value to Port
2 Register
Load Init. Value to
P2PWMOUT Register
(Disable PWM Output)
Stop PWM Counter
Stop PWM
End
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 ISR
Start
Clear Ext. INT0 Pending
Bit
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 ISR
Return
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 ISR
Start
Clear Ext. INT1 Pending
Bit
Delay 0.8 micro-sencond
P1.1(Brake)
keep LOW ?
N
Y
Set Brake Flag
Ext. INT1 ISR
Return
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)
ISR
Start
Clear Ext. INTx Pending
Bit (x=2,3,4)
Disable IRQ6 (Ext.
INT2 ~ INT4)
N
Phase Change
Enable ?
Y
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
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 ISR
Start
Clear Timer 0 Match
Interrupt Pending Bit
Update Timer Piece
Counter
Y
Timer Piece
Counter < 4 ?
(0.2 second)
N
Load Speed Counter
Value to Current Speed
Value
Clear Timer Piece
Counter
Clear Speed Counter
Timer 0 Match ISR
Return
Figure 5-18
Timer 0 Match (Speed Counting) Interrupt Service Routine Flow
Samsung Confidential
45
S3F84A5_APPLICATION NOTE_REV1.10
6
6 APPENDIX I: SCHEMATIC DIAGRAM OF REFERENCE DESIGN
APPENDIX I: SCHEMATIC DIAGRAM OF
REFERENCE DESIGN
Figure 6-1
Schematic Diagram of E-bike Controller Reference Design
Double click to open Figure 6-1 in Adobe Reader.
Samsung Confidential
46
S3F84A5_APPLICATION NOTE_REV1.10
7
7 APPENDIX II: DEMO SYSTEM
APPENDIX II: DEMO SYSTEM
Power Supply
BLDC Motor
Control Board
Handlebar
Brake
Target Board
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.
Samsung Confidential
47
S3F84A5_APPLICATION NOTE_REV1.10
Figure 7-2
7 APPENDIX II: DEMO SYSTEM
E-bike Controller Reference Design Control Board
Samsung Confidential
48
S3F84A5_APPLICATION NOTE_REV1.10
Figure 7-3
7 APPENDIX II: DEMO SYSTEM
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
Figure 7-5
7 APPENDIX II: DEMO SYSTEM
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
8 APPENDIX III: SOURCE CODE
APPENDIX III: SOURCE CODE
Appendix III
SW.doc
Samsung Confidential
51
Study collections