ETC DRM007

Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
BLDC Motor
Control Board
for Industrial
and Appliance
Applications
Designer Reference
Manual
M68HC08
Microcontrollers
DRM007/D
2/2003
MOTOROLA.COM/SEMICONDUCTORS
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
BLDC Motor Control Board
for Industrial and Appliance
Applications Reference Design
By: Jorge Zambada
Email: [email protected]
Applications Engineer — Mexico Applications Lab
Diego Garay
Email: [email protected]
Applications Engineer — Mexico Applications Lab
Maurizio Acosta
Email: [email protected]
Applications Engineer — Mexico Applications Lab
Motorola and the Stylized M Logo are registered trademarks of Motorola, Inc.
DigitalDNA is a trademark of Motorola, Inc.
This product incorporates SuperFlash® technology licensed from SST.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
© Motorola, Inc., 2003
DRM007
3
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Revision History
To provide the most up-to-date information, the revision of our
documents on the World Wide Web will be the most current. Your printed
copy may be an earlier revision. To verify you have the latest information
available, refer to:
http://motorola.com/semiconductors
Freescale Semiconductor, Inc...
The following revision history table summarizes changes contained in
this document. For your convenience, the page number designators
have been linked to the appropriate location.
Revision History
Date
Revision
Level
February, 2003
N/A
DRM007
Description
Initial release
Page
Number(s)
N/A
BLDC Motor Control Board for Industrial and Appliance Applications
4
MOTOROLA
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
List of Sections
Section 1. Introduction and Setup . . . . . . . . . . . . . . . . . . 15
Freescale Semiconductor, Inc...
Section 2. Operational Description . . . . . . . . . . . . . . . . . 37
Section 3. Schematics and Bill of Materials . . . . . . . . . . 43
Section 4. Hardware Design Considerations . . . . . . . . . 55
Section 5. Software Design Considerations . . . . . . . . . . 71
Section 6. Practical Results . . . . . . . . . . . . . . . . . . . . . . . 97
Section 7. Source Code . . . . . . . . . . . . . . . . . . . . . . . . . 103
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
List of Sections
For More Information On This Product,
Go to: www.freescale.com
DRM007
5
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Sections
DRM007
6
BLDC Motor Control Board for Industrial and Appliance Applications
List of Sections
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Table of Contents
Freescale Semiconductor, Inc...
Section 1. Introduction and Setup
1.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
1.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3
MC68HC908MR8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
1.4
MC68HC908MR8 Pulse-Width Modulator . . . . . . . . . . . . . . . . 21
1.4.1
Fault Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.4.2
PWM Output Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.4.3
PWM Counter Timebase . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.4
PWM Load Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.5
Direct Output Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.6
Deadtime Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5
Brief Overview to Brushless DC Motors . . . . . . . . . . . . . . . . . . 25
1.6
Washing Machine Application’s Overview . . . . . . . . . . . . . . . . 28
1.6.1
Movement Patterns of the Washer. . . . . . . . . . . . . . . . . . . . 28
1.6.2
Agitator Hits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.3
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.4
User’s Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.5
Control Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.6
Target Washer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.7
System Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.8
Warnings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
1.9
Setup Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.9.1
Programming Mode Setup . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.9.2
Running Mode Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
DRM007
7
Freescale Semiconductor, Inc.
Table of Contents
Section 2. Operational Description
2.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
2.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.3
Electrical Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.4
User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Freescale Semiconductor, Inc...
2.5
Connectors Pin Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.5.1
J1 — AC Jack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.5.2
J2 — 3-Phase Motor Connector. . . . . . . . . . . . . . . . . . . . . . 41
2.5.3
J3 — Single Phase Motor 1 Connector . . . . . . . . . . . . . . . . 41
2.5.4
J4 — Temperature Sensor Connector . . . . . . . . . . . . . . . . . 41
2.5.5
J5 — RS-232 Interface Connector . . . . . . . . . . . . . . . . . . . . 42
2.5.6
J6 — External 18 Vdc Source Connector. . . . . . . . . . . . . . . 42
2.5.7
J7 — Single Phase Motor 2 Connector . . . . . . . . . . . . . . . . 42
2.5.8
J8 — Motor Hall Effect Sensor Connector . . . . . . . . . . . . . . 42
Section 3. Schematics and Bill of Materials
3.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
3.2
Schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.3
Bill of Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Section 4. Hardware Design Considerations
DRM007
8
4.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
4.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.3
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56
4.4
RS-232 interface and MON08 Hardware Interface. . . . . . . . . . 58
4.5
Clock Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
4.6
Hall-Effect Sensors Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.7
LCD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
4.8
Reset Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.9
3-Phase H-Bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63
4.10
Current Feedback and Cycle-by-Cycle Limiting . . . . . . . . . . . . 64
BLDC Motor Control Board for Industrial and Appliance Applications
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Table of Contents
4.11
Voltage Feedback. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
4.12
Current and Voltage Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.13
Heat Sink Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Freescale Semiconductor, Inc...
Section 5. Software Design Considerations
5.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71
5.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.3
Controller Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.4
Speed Control Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
5.4.1
Motor Stalled Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . .79
5.5
Commutation Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.6
Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.6.1
Processes: Latest Position Capture,
Period Measuring, and Speed Calculation . . . . . . . . . . . 84
5.6.2
Process Speed Controller . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.6.3
Process MOSFET Gating Selection . . . . . . . . . . . . . . . . . . . 84
5.6.4
Process Washing Machine. . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.7
Application State Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.8
Drive State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.9
Description of Routines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1
Main(void). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.1
Stop Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.2
Waiting for Command . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.3
Displaying Actual and Reference Speed . . . . . . . . . . . . . 89
5.9.1.4
Wash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.5
Spin CW and Spin CCW . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.1.6
Fixed Reference Speed . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.2
InitPLL(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.3
InitPWMMC(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.4
InitTimerA(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.5
InitTimerB(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9.6
Byte ResolveButtons(void) . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9.7
InitMotor(Byte Commanded_Operation) . . . . . . . . . . . . . . . 91
5.9.8
TimerAOverflow_ISR(void). . . . . . . . . . . . . . . . . . . . . . . . . . 91
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
DRM007
9
Freescale Semiconductor, Inc.
Table of Contents
Freescale Semiconductor, Inc...
5.9.9
5.9.10
5.9.11
5.9.12
5.9.13
5.9.14
5.9.15
5.9.16
5.9.17
5.9.18
5.9.19
5.9.20
5.9.21
5.9.22
5.10
Signed Word 16 PIController(void). . . . . . . . . . . . . . . . . . . . 92
MotorStalledProtection(void) . . . . . . . . . . . . . . . . . . . . . . . .92
HALLA_ISR(void) and HALLB_ISR(void). . . . . . . . . . . . . . . 92
HALLC_ISR(void). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Fault1_ISR(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
NextSequence(void). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
InitLCD(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
CtrlLCD(Byte ctrl) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Ctrl8LCD(Byte ctrl) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
MovCursorLCD(Byte places, Byte dir) . . . . . . . . . . . . . . . . . 93
DataLCD(Byte data) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
StringLCD(Byte *msgLCD). . . . . . . . . . . . . . . . . . . . . . . . . . 94
WaitMs(Byte milis) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Wait40ms(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
MCU Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Section 6. Practical Results
Section 7. Source Code
7.1
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103
7.2
Include Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.2.1
MR8IO.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.2.2
START08.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.2.3
MAIN.H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.2.4
TIMER.H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.2.5
LCD.H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
7.2.6
TABLES.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
7.3
Source Code Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.3.1
START08.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.3.2
MAIN.C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
7.3.3
TIMER.C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
7.3.4
LCD.C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145
DRM007
10
BLDC Motor Control Board for Industrial and Appliance Applications
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
List of Figures
Freescale Semiconductor, Inc...
Figure
Title
1-1
1-2
1-3
1-4
1-5
1-6
1-7
1-8
MC68HC908MR8 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . 18
PWMMC Module Block Diagram . . . . . . . . . . . . . . . . . . . . . . . 22
BLDC Motor – Cross Section . . . . . . . . . . . . . . . . . . . . . . . . . . 25
BLDC Motor Commutation Signals. . . . . . . . . . . . . . . . . . . . . . 27
BLDC Motor Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
System Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Monitor Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Board Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
3-1
3-2
3-3
3-4
3-5
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45
Gate Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3-Phase H-Bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47
Current and Voltage Sense . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4-1
4-2
4-3
4-4
4-5
4-6
4-7
4-8
4-9
4-10
4-11
4-12
4-13
4-14
V_BUS Power Supply. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
15 Vdc and 5 Vdc Power Supplies . . . . . . . . . . . . . . . . . . . . . . 57
RS-232 and MON08 Interfaces . . . . . . . . . . . . . . . . . . . . . . . .58
Clock Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
Hall-Effect Sensors Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 60
LCD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
Reset Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
External Reset Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62
Phase C Output and Gate Driver . . . . . . . . . . . . . . . . . . . . . . . 63
Current Differential Amplifier. . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Current Peak Detector for Current Sensing . . . . . . . . . . . . . . . 65
Cycle-by-Cycle Current Limiter. . . . . . . . . . . . . . . . . . . . . . . . . 66
Voltage Feedback and Fault Detector . . . . . . . . . . . . . . . . . . . 67
Current and Voltage Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Page
List of Figures
For More Information On This Product,
Go to: www.freescale.com
DRM007
11
Freescale Semiconductor, Inc.
List of Figures
Freescale Semiconductor, Inc...
Figure
PI Controller Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Speed Control Algorithm Flowchart . . . . . . . . . . . . . . . . . . . . . 78
Motor Stalled Protection Flowchart. . . . . . . . . . . . . . . . . . . . . . 79
3-Phase Voltage System Applies to BLDC Motor. . . . . . . . . . . 81
Commutation Algorithm for Hall Sensors . . . . . . . . . . . . . . . . . 82
Main Data Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Software Deadtime Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Application State Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Drive State Machine and Transitions . . . . . . . . . . . . . . . . . . . . 88
6-1
6-2
6-3
Power Output versus Torque Motor Characteristic. . . . . . . . . . 97
Speed versus Torque Motor Characteristic . . . . . . . . . . . . . . . 98
Current Waveform for Two MOSFET
Commutation Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Current Waveform for Three MOSFET
Commutation Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Torque Waveform for Two MOSFET
Commutation Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Torque Waveform for Three MOSFET
Commutation Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6-5
6-6
12
Page
5-1
5-2
5-3
5-4
5-5
5-6
5-7
5-8
5-9
6-4
DRM007
Title
BLDC Motor Control Board for Industrial and Appliance Applications
List of Figures
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
List of Tables
Freescale Semiconductor, Inc...
Table
Title
1-1
MC68HC908MR8 Peripherals and Memory . . . . . . . . . . . . . . . 17
2-1
2-2
2-3
2-4
2-5
2-6
2-7
2-8
2-9
2-10
Electrical Characteristics for 127 Vac Board Version . . . . . . . . 38
Electrical Characteristics for 230 Vac Board Version . . . . . . . . 38
AC Jack Connector (J1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3-Phase Motor Connector (J2) . . . . . . . . . . . . . . . . . . . . . . . . . 41
Single-Phase Motor 1 Connector (J3) . . . . . . . . . . . . . . . . . . . 41
Temperature Sensor Connector (J4) . . . . . . . . . . . . . . . . . . . . 41
Optoisolated RS-232 DB-9 Connector (J5) . . . . . . . . . . . . . . . 42
External 18 Vdc Source Connector (J6) . . . . . . . . . . . . . . . . . . 42
Single-Phase Motor 2 Connector (J7) . . . . . . . . . . . . . . . . . . . 42
Motor Hall Effect Sensors Connector (J8) . . . . . . . . . . . . . . . . 42
3-1
3-2
Bill of Materials for 127 Vac Board . . . . . . . . . . . . . . . . . . . . . . 49
Bill of Material Changes for 230 Vac Board . . . . . . . . . . . . . . . 53
4-1
PIN Bit Set Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5-1
5-2
5-3
Commutation Sequence for Clockwise Rotation . . . . . . . . . . . 80
Commutation Sequence for Counterclockwise Rotation . . . . . 81
RAM and FLASH Memory Usage. . . . . . . . . . . . . . . . . . . . . . . 95
6-1
Speed Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Page
List of Tables
For More Information On This Product,
Go to: www.freescale.com
DRM007
13
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Tables
DRM007
14
BLDC Motor Control Board for Industrial and Appliance Applications
List of Tables
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Section 1. Introduction and Setup
Freescale Semiconductor, Inc...
1.1 Contents
1.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3
MC68HC908MR8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
1.4
MC68HC908MR8 Pulse-Width Modulator . . . . . . . . . . . . . . . . 21
1.4.1
Fault Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.4.2
PWM Output Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.4.3
PWM Counter Timebase . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.4
PWM Load Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.5
Direct Output Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.4.6
Deadtime Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.5
Brief Overview to Brushless DC Motors . . . . . . . . . . . . . . . . . . 25
1.6
Washing Machine Application’s Overview . . . . . . . . . . . . . . . . 28
1.6.1
Movement Patterns of the Washer. . . . . . . . . . . . . . . . . . . . 28
1.6.2
Agitator Hits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.3
Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.4
User’s Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.5
Control Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.6.6
Target Washer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.7
System Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.8
Warnings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
1.9
Setup Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.9.1
Programming Mode Setup . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.9.2
Running Mode Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
15
Freescale Semiconductor, Inc.
Introduction and Setup
1.2 Introduction
Motorola’s BLDC (brushless dc motor) control board for industrial and
appliance applications is a system for controlling a 3-phase BLDC
motors with three Hall-effect position sensors. The system consists of
hardware and software tools for controlling this type of motor.
Freescale Semiconductor, Inc...
Hardware consists of:
•
Three-phase inverter
•
Sensing circuitry for current, voltage, and temperature
•
User interface: 16 x 2 character display and two push buttons
•
On-board power supply: 15 Vdc or 5 Vdc
•
Optoisolated RS-232 interface for external microcontroller
communication and for in-application programming.
There are two board versions available, one for operating at
110–127 Vac and the other for operating at 220–240 Vac. The 3-phase
inverter of the 110–127 Vac board operates at a nominal voltage of
180 Vdc and 8 A RMS with 11 A peak. The inverter of the 220–240 Vac
board operates at a nominal voltage of 320 Vdc driving the same current.
The example software consists of the following, but may be easily
modified to perform other process cycles.
•
PI speed controller for closed loop control
•
Six-step BLDC commutation control based on three Hall-effect
position sensors
•
User interface control
•
Two washing machine process implementations: wash process
and spin process
The wash process consists of generating a sine wave of speed
references, including positive and negative reference speeds. The spin
process consists of generating a start up curve of reference speeds and
maintaining a fixed reference speed for a certain time. The PI speed
controller operates in the 200 rpm up to 4000 rpm range.
DRM007
16
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
MC68HC908MR8
1.3 MC68HC908MR8
Freescale Semiconductor, Inc...
Motorola offers several 8-bit and 16-bit microcontroller families that are
perfectly adapted to the requirements of modern industrial and
household applications, combining high-performance and low cost.
This development is based on an MC68HC908MR8 microcontroller, a
member of the M68HC08 Family. The MC68HC908MR8 incorporates a
fault tolerant and flexible 6-channel, 12-bit pulse-width modulator (PWM)
designed to support center and edge-aligned modes with automatic
deadtime insertion and patented deadtime compensation capability.
Write-once protection of key configuration parameters further enhances
motor and consumer safety, the MC68HC908MR8 is appropriate for cost
and space conscious applications including smart appliances, blowers,
fans, refrigeration compressors, office automation products, and electric
lawn equipment.
Refer to Figure 1-1 for a block diagram of the MC68HC908MR8.
Table 1-1 summarizes the MC68HC908MR8 peripherals and memory.
The MC68HC908MR8 is a member of the low-cost, high-performance
M68HC08 Family of 8-bit microcontroller units (MCU). The M68HC08
Family is based on the customer-specified integrated circuit (CSIC)
design strategy. All MCU’s in the family use the enhanced M68HC08
central processor unit (CPU08) and are available with a variety of
modules, memory sizes and types, and package types. The central
processor unit can address 64 Kbytes of memory space.
Table 1-1. MC68HC908MR8 Peripherals and Memory
RAM
(Bytes)
FLASH
(Bytes)
Timer
I/O
Serial
A/D
PWM
Operating
Voltage
Maximum Bus
Frequency
256
8K
2-ch + 2-ch
16-bit IC,
OC, or PWM
14
SCI
4-ch to 7-ch
10 bit
6-ch
12 bit
5.0 V
8.0 MHz
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
17
Freescale Semiconductor, Inc.
Introduction and Setup
INTERNAL BUS
M68HC08 CPU
COMPUTER OPERATING
PROPERLY MODULE
DDRA
CONTROL AND STATUS
REGISTERS — 112 BYTES
LOW-VOLTAGE INHIBIT
MODULE
PORTA
ARITHMETIC/LOGIC
UNIT (ALU)
PTA6/ATD6
PTA5/ATD5
PTA4/ATD4
PTA3/ATD3
PTA2/ATD2
PTA1/ATD1
PTA0/ATD0
PORTB
CPU
REGISTERS
PTB6/TCH1B
PTB5/TCH0B
PTB4/TCH1A
PTB3/TCH0A
PTB2TCLKA
PTB1/TxD
PTB0/RxD
USER FLASH — 7680 BYTES
TIMER A AND TIMER B
INTERFACE MODULES
MONITOR ROM — 313 BYTES
USER VECTOR SPACE — 46 BYTES
OSC1
OSC2
CGMXFC
CLOCK GENERATOR
MODULE
RST
SYSTEM INTEGRATION
MODULE
IRQ
IRQ
MODULE
VREFH
SERIAL COMMUNICATIONS
INTERFACE MODULE
POWER-ON RESET
MODULE
PULSE-WIDTH
MODULATOR
Freescale Semiconductor, Inc...
USER RAM — 256 BYTES
DDRB
BREAK
MODULE
PWM6
PWM5
PWM4
PWM3
PWM2
PWM1
PTC1/FAULT4
PTC1/FAULT4
ANALOG-TO-DIGITAL
CONVERTER MODULE
PULSE-WIDTH
MODULATOR MODULE
VDD
VDDA
VSSA
VSS
POWER
Figure 1-1. MC68HC908MR8 Block Diagram
DRM007
18
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
MC68HC908MR8
Freescale Semiconductor, Inc...
Features of the MC68HC908MR8 include:
•
High-performance M68HC08 architecture
•
Fully upward-compatible object code with M6805, M146805, and
M68HC05 Families
•
8-MHz internal bus frequency
•
8 Kbytes of on-chip FLASH
•
On-chip programming firmware for use with host PC
•
On-chip random-access memory (RAM) 256 bytes
•
12-bit, 6-channel center-aligned or edge-aligned PWMMC
•
Serial communications interface module (SCI)
•
Two 16-bit, 2-channel timer interface modules (TIMA and TIMB)
•
Eight high current sink and source pins (PTA1/ATD1, PTA0/ATD0,
PTB6/TCH1B, PTB5/TCH0B, PTB4/TCH1A, PTB3/TCH0A,
PTB2/TCLKA, and PTB1/TxD)
•
Clock generator module (CGM)
•
Digitally filtered low-voltage inhibit (LVI), software selectable for
±5 percent or ±10 percent tolerance
•
10-bit, 4- to7-channel analog-to-digital converter (ADC)
•
System protection features:
– Optional computer operating properly (COP) reset
– Low-voltage detection with optional reset
– Illegal opcode detection with optional reset
– Illegal address detection with optional reset
•
Fault detection with optional PWM disabling
•
Available packages:
– 32-pin low-profile quad flat pack (LQFP)
– 28-pin dual in-line package (PDIP)
– 28-pin small outline package (SOIC)
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
19
Freescale Semiconductor, Inc.
Introduction and Setup
•
Low-power design, fully static with stop and wait modes
•
Break (BRK) module allows single breakpoint setting during
in-circuit debugging
•
Master reset pin and power-on reset (POR)
Freescale Semiconductor, Inc...
Features of the CPU include:
•
Fully upward, object-code compatibility with M68HC05 Family
•
16-bit stack pointer with stack manipulation instructions
•
16-bit index register with X-register manipulation instructions
•
8-MHz CPU internal bus frequency
•
64-Kbyte program/data memory space
•
Sixteen addressing modes
•
Memory-to-memory data moves without using the accumulator
•
Fast 8-bit by 8-bit multiply and 16-bit by 8-bit divide instructions
•
Enhanced binary-coded decimal (BCD) data handling
•
Modular architecture with expandable internal bus definition for
extension of addressing range beyond 64 Kbytes
•
Low-power stop and wait modes
The MC68HC908MR8 PWM module can generate three complementary
PWM pairs or six independent PWM signals. These PWM signals can be
center-aligned or edge-aligned.
A 12-bit timer PWM counter is common to all six channels. PWM
resolution is one clock period for edge-aligned operation and two clock
periods for center-aligned operation. The clock period is dependent on
the internal operating frequency (fop of the MCU) and a programmable
prescaler.
The highest resolution for edge-aligned operation is 125 ns
(fop = 8 MHz). The highest resolution for center-aligned operation is
250 ns (fop = 8 MHz).
When generating complementary PWM signals, the module features
automatic deadtime insertion to the PWM output pairs.
DRM007
20
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
MC68HC908MR8 Pulse-Width Modulator
1.4 MC68HC908MR8 Pulse-Width Modulator
Freescale Semiconductor, Inc...
The pulse-width modulator module (PWMMC) resident on the
MC68HC908MR8 is specifically designed to provide pulse-width
modulated outputs to drive a power stage connected to a dc servo,
brushless dc, or 3-phase ac motor system. The PWMMC module can be
partitioned and configured in several ways, depending on the specific
motor control application. Figure 1-2 shows a block diagram of the
PWMMC module and is referenced throughout this explanation of the
PWMMC generator.
Features of the PWM include:
•
Three complementary PWM pairs or six independent PWM
signals
•
Complementary mode features include:
– Deadtime insertion
– Separate top/bottom pulse-width correction via current
sensing or programmable software bits
•
Edge-aligned PWM or center-aligned PWM signals
•
PWM signal polarity
•
20-mA current sink capability on all PWM outputs
•
Manual PWM output control through software
•
Programmable fault protection.
One of the most important features of the PWMMC is its ability to “shut
itself down” when a system fault is detected. When dealing with a system
that potentially could have hundreds of amps of peak current, reacting to
faults such as Overcurrent or Overvoltage conditions is an absolute
necessity. Fault protection is discussed first. Then, we will work our way
from the outputs of the PWM inward.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
21
Freescale Semiconductor, Inc.
Introduction and Setup
OR
PRESCALER
UP/DOWN
COUNTER
PRESCALER
÷ 1, 2, 3, OR 8
PWM RELOAD AND INTERRUPT
÷ 1, 2, 3, OR 8
INTERRUPTS
PWM
GENERATORS
CONTROL
PWM
MODE SELECT
Freescale Semiconductor, Inc...
COMPARATORS
DOUBLE
BUFFERED
REGISTERS
DEADTIME
INSERTION
DIRECT
OUTPUT CONTROL
DISTORTION
CORRECTION
MOTOR CURRENT POLARITIES
FAULT
PROTECTION
PWM1
OUTPUT
PWM2
FAULT
PARTITIONING
POLARITY
CONTROL
PWM3
PWM4
FAULT
MODE SELECT
HIGH CURRENT
DRIVERS
PWM5
PWM6
SYSTEM FAULTS
Figure 1-2. PWMMC Module Block Diagram
The six outputs of the PWMMC generator can be configured as
individual pulse-width modulated signals where each output can be
controlled as an independent output. Another option is to configure the
outputs in pairs, with the outputs complementary or not, so driving
complementary top and bottom transistors on a power stage becomes
an easy task. The outputs of the PWMMC are capable of sinking up to
20 mA. That drive capability allows for direct drive of optocouplers
without the need of additional drivers.
To prevent erroneous signals from being output from the PWMMC
module while loading new values, the bulk of the registers are double
buffered. New output is inhibited until the load okay (LDOK) bit in the
PWM control register is set indicating that it is okay to output the new
values.
DRM007
22
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
MC68HC908MR8 Pulse-Width Modulator
1.4.1 Fault Protection
Freescale Semiconductor, Inc...
Conditions can arise in the external drive circuitry, requiring that the
PWM signals become inactive immediately. These conditions include
Overcurrent, Overvoltage, Overtemperature, or other error conditions.
Upon detection of a fault, the two fault input pins on the
MC68HC908MR8’s PWMMC module can be configured to react in a
number of different ways.
Each fault input has its own interrupt vector. In all fault conditions, the
output of the PWM generator is forced to a known inactive state. A
number of fault control and recovery options are available to the systems
architect. In some cases, it may be desirable to selectively disable
PWM(s) solely with software. Manual and automatic recovery
mechanisms are available that allow certain acceptable fault situations
to occur, such as starting a motor and using a fault input to limit the
maximum startup current. The fault inputs can be partitioned if the
MC68HC908MR8 is used to control multiple motors.
1.4.2 PWM Output Alignment
Depending on the system design, there is a choice between edge- or
center-aligned PWM signals output from the MC68HC908MR32’s PWM
generator. The PWM counter uses the value in the timer modulus
register to determine its maximum count. In center-aligned mode, a
12-bit up/down counter is used to create the PWM period. The PWM
resolution in center-aligned mode is two clock periods (highest
resolution is 250 ns at a processor speed of 8 MHz). The PWM period
will be equal to:
[(Timer modulus) x (PWM clock period) x 2]
In edge-aligned mode, a 12-bit up-only counter is used to create the
PWM period. Therefore, the PWM resolution in edge-aligned mode is
one clock (highest resolution is 125 ns at a processor speed of 8 MHz).
Again, the timer modulus register is used to determine the maximum
count. The PWM period will be equal to:
[(Timer modulus) x (PWM clock period)]
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
23
Freescale Semiconductor, Inc.
Introduction and Setup
1.4.3 PWM Counter Timebase
To permit lower PWM frequencies, a prescaler is provided which will
divide the PWM clock frequency by 1, 2, 4, or 8. This prescaler is
buffered and will not be used by the PWM generator until the LDOK bit
located in a PWM control register is set and a new PWM reload cycle
begins.
Freescale Semiconductor, Inc...
1.4.4 PWM Load Operations
When generating sine waves to a motor, an interrupt routine is typically
used to step through a sine table located in FLASH memory, scale that
sine value, and output the result to the system from the PWM generator.
The rate at which the sine table is scanned can be derived from an
interrupt from the PWM generator. The PWM module can be
programmed to provide an interrupt rate of every 1, 2, 3, or 8 PWM
reload cycles.
1.4.5 Direct Output Control
In some cases, the user may desire to bypass the PWM generator and
directly control the PWM outputs. A mechanism exists to disconnect the
PWM generator from its outputs and directly control the six PWM
outputs. When this mode is used, the PWM generator continues to run;
however, it’s normal PWM output is disabled as it is overridden by direct
output.
1.4.6 Deadtime Insertion
When the PWM generator is used in complementary mode, automatic
deadtime insertion can be provided to prevent turning on both top and
bottom inverter transistors in the same phase leg at the same time.
When controlling dc-to-ac inverters, the top and bottom PWMs in one
pair must never be active at any given time.
CAUTION:
DRM007
24
If the top and bottom transistors are turned on simultaneously, large
currents will flow through the two transistors as they attempt to discharge
the bus supply voltage. The transistors could be weakened or destroyed.
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
Brief Overview to Brushless DC Motors
Freescale Semiconductor, Inc...
Simply forcing the two PWMs to be inversions of each other is not always
sufficient. Since a time delay is associated with turning off the transistors
in the motor drive, there must be a “deadtime” between the deactivation
of one PWM power transistor and the activation of the opposite transistor
in a top and bottom pair. Deadtime can be specified in the deadtime
write-once register. This 8-bit value specifies the number of CPU clock
cycles to use for the deadtime.
1.5 Brief Overview to Brushless DC Motors
A brushless dc motor is a rotating electric machine where the stator is a
classic 3-phase stator like that of an induction motor and the rotor has
surface-mounted permanent magnets. There are no brushes on the
rotor and the commutation is performed electronically at certain rotor
positions. The stator is usually made from magnetic steel sheets. The
stator phase windings are inserted in the slots (distributed winding) as
shown on Figure 1-3.
Stator
Stator windings
in slots
Shaft
Rotor
Air gaps
Permanent
magnets
Figure 1-3. BLDC Motor – Cross Section
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
25
Freescale Semiconductor, Inc.
Introduction and Setup
Brushless dc motors are named in different ways:
•
Permanent magnet synchronous motors
•
Brushless permanent magnet
•
Permanent magnet ac motors, etc.
Freescale Semiconductor, Inc...
A BLDC motor is equivalent to an inverted dc commutation motor, where
the magnet rotates while the conductors remain stationary. In the dc
commutation motor, the commutator and brushes reverse the current
polarity. But, in the brushless dc motor, a power transistor (which must
be switched in synchronization with the rotor position) performs the
polarity reversal. The BLDC motor often has either internal or external
position sensors to sense actual rotor position so that synchronization
can be performed.
The motor can have more than one pole-pair per phase. The pole-pair
per phase defines the ratio between the electrical revolution and the
mechanical revolution. For example, the BLDC motor shown in
Figure 1-3 has four pole-pairs per phase; which leads to four electrical
revolutions; per one mechanical revolution.
Advantages of the brushless dc motors are:
DRM007
26
•
No electrical noise due to brushes and commutator
•
No tachometer needed for speed control
•
High starting torque and high no load speed
•
Good power output to size ratio
•
Higher efficiency than ac induction motors
•
Reversible
•
Precise speed control
•
Variable speed
•
Oil-less operation
•
Rapid acceleration and deceleration
•
Very low torque ripple
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
Brief Overview to Brushless DC Motors
The presented application uses three Hall effect sensors to sense actual
position. The Hall effect sensors’ signals together give the six output
values. These outputs are read by the microcontroller and the
corresponding output voltage is generated by PWM outputs, as shown
in Figure 1-4.
0°
15°
30°
45°
60°
75°
90°
HALL A
Freescale Semiconductor, Inc...
HALL B
HALL C
PWM1
PWM2
PWM3
PWM4
PWM5
PWM6
Figure 1-4. BLDC Motor Commutation Signals
These six PWM outputs are direct inputs to the 3-phase inverter. The
motor windings are connected to the inverter. The three Hall effect
sensors are connected to independent input capture channels of the
microcontroller. See Figure 1-5.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
27
Freescale Semiconductor, Inc.
Introduction and Setup
VBUS
PWM1
PWM3
PWM5
BRUSHLESS
MOTOR
PWM6
CURRENT
PROCESSING
VALUE
LIMIT
HALL C
TCH1B
TCH1A
Freescale Semiconductor, Inc...
HALL B
FILTERING
TCH0B
PWM4
HALL A
PWM2
ATD6
FAULT1
SHUNT
RESISTOR
VOLTAGE
PROCESSING
VALUE
PWM1
PWM2
PWM3
PWM4
PWM5
PWM6
ATD5
MC68HC908MR8
Figure 1-5. BLDC Motor Controller
1.6 Washing Machine Application’s Overview
This reference design has many possible applications and can be easily
reconfigured to suit industrial or appliance needs. The provided source
code example emulates a basic washing machine as discussed in the
following subsections.
1.6.1 Movement Patterns of the Washer
In washing machines there is a trade-off between clothes washability
and clothes damage. One important consideration in the design is the
agitator movement in the washer. The agitator movement pattern is
given by a look up table of desired speeds. This look up table could
DRM007
28
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
Washing Machine Application’s Overview
follow different shapes, such as square, trapezoidal or sinusoidal
shapes. That is why the reference speeds in this design are taken from
a table, leaving the user to customize the movement and test different
patterns. From a mechanical point of view, a sinusoid agitator movement
has less clothes damage, due to the smooth movement of the washer.
Freescale Semiconductor, Inc...
1.6.2 Agitator Hits
When washing, there are two important design considerations on each
hit of the agitator:
•
One is the angular displacement of the agitator in each hit.
Modifying the reference speeds curve and calculating the integral
of the entire hit can change this displacement.
•
The other parameter is the frequency at which the table of
reference speeds is accessed, giving different hits per minute in
the washer.
1.6.3 Software
The software for this reference design drives a brushless dc motor in the
four quadrants, which means that the motor can be reversed without any
need of stopping the motor first. This driver capability is very useful in
washers because of the water inertia in the washing machine.
1.6.4 User’s Menu
A user menu with a 16 x 2 character display and two push buttons was
included in the reference design board. This menu provides useful
information during operation.
1.6.5 Control Scheme
The closed loop control scheme becomes necessary in this application
to have more robustness in the washer operation, such as load change,
input voltage variations, or mechanical degradations.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
29
Freescale Semiconductor, Inc.
Introduction and Setup
1.6.6 Target Washer
Freescale Semiconductor, Inc...
The targeted washers for this application example are direct drive
washing machines. These washers have the following advantages over
the classic ones:
•
No belts between the motor shaft and the agitator of the washer.
•
Different speed ranges, allowing different patterns of agitator
movement.
•
Powerful microcontroller, which makes possible the
implementation of digital controllers.
1.7 System Concept
The system is designed to drive a 4-pole 3-phase BLDC star connected
motor with a 5 to 1 speed gearbox. The microcontroller runs the main
control algorithm. According to the user interface input and feedback
signals, it generates 3-phase PWM output signals for the motor inverter.
The system incorporates all of the application in one board. Figure 1-6
shows the system concept, including the following hardware:
•
On-board power supply
•
Feedback network
•
Three-phase inverter
•
Microcontroller unit
•
User interface
•
Optoisolated RS-232 interface
The motor used for this application is based on a ½ HP BLDC and a
maximum speed of 4000 rpm.
DRM007
30
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
System Concept
3-PHASE
BLDC
MOTOR
3-PHASE
INVERTER
120 / 230 VAC
FAULT
ADC
PWM
I/O
USER INTERFACE
SIX-STEP VOLTAGE
GENERATOR
I/O
16 x 2 LCD
SPEED PI
CONTROLLER
REQUIRED VOLTAGE
CURRENT
POSITION
ACTUAL
SPEED
REQUIRED
SPEED
1/T
POSITION,
DIRECTION
RECOGNITION
I/O
RS-232
SCI
Freescale Semiconductor, Inc...
SENSING CIRCUITRY
FOR I, V, AND T
HALL EFFECT
SENSOR SIGNALS
WASH PROCESS
REQUIRED TABLE
MC68HC908MR8
Figure 1-6. System Concept
The control process is as follows:
The state of the Hall sensor’s inputs is periodically scanned, while the
speed of the motor is measured on each new incoming edge from the
Hall sensors. According to the user menu, the speed reference is
calculated and controlled based upon the current and desired speed.
The comparison between the actual speed and the desired speed
generates a speed error. The speed error is brought to the speed PI
controller that generates a new corrected applied voltage. There are
two independent modules in software, one for commutating the motor
and other for controlling the speed, which gives us a four-quadrant
BLDC motor drive.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
31
Freescale Semiconductor, Inc.
Introduction and Setup
The Hall sensor signals are scanned independently of the speed
controller. Each new incoming edge of any Hall sensor signal calls an
interrupt routine, which calculates a new voltage shape, applied to the
BLDC motor. This process is called commutation. The PWM
transistors work in complementary mode, when the upper transistor is
on, the lower transistor is off and vice versa.
Freescale Semiconductor, Inc...
1.8 Warnings
This reference board operates in an environment that includes
dangerous voltages and rotating machinery.
Due to the high-voltage power stage operating directly from an ac line,
oscilloscope grounds and power stage grounds are at different
potentials, unless the oscilloscope is floating. Note that probe grounds
and, therefore, the case of a floated oscilloscope, are subjected to
dangerous voltages.
DRM007
32
•
Before moving scope probes, making connections, etc., you must
turn off the main switch.
•
Operation in lab setups that have grounded tables and/or chairs
should be avoided.
•
Wearing safety glasses, avoiding ties and jewelry, using shields,
and operation by personnel trained in high-voltage lab techniques
are advisable.
•
Never turn on the board in running mode if it is not known if the
code is downloaded.
•
To reduce the cost of the board, optoisolation circuitry was not
included: the microcontroller’s ground is tied to a power stage
ground. For this reason, special care must be taken when
handling the board. Touching its components when it is turned on
must be avoided.
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
Setup Guide
1.9 Setup Guide
This board operates in two different modes: programming mode and
running mode. Programming mode allows downloading code to the
microcontroller. In running mode the microcontroller executes the
downloaded code.
Freescale Semiconductor, Inc...
Out of the box conditions suppose the board is programmed with “BLDC
CODE V1.s19”. Default position of Jumper JP1 is between 2 and 3 pins.
The board contains its own dc power supply for the power stage, besides
a 15 Vdc regulated power supply and a 5 Vdc regulated power supply.
The 15 Vdc and the 5 Vdc power supplies can be sourced by the dc
power supply for power stage or by and external source of 18 Vdc at
200 mA. Input for this external source is the connector labeled J6.
Selecting internal or external sourcing of 15 Vdc and 5 Vdc regulated
power supplies, is done by means of switch S5. Then, if the user wants
to use an external power supply, connect its terminals to connector J6
and slide the switch S5 to the position labeled “EXT”.
1.9.1 Programming Mode Setup
The following procedure describes programming mode setup. Before
starting you must turn off the main switch. Auxiliary external power
supply usage is recommended.
A PC computer is required having Metrowerks CodeWarrior
Development Studio for HC08 Microcontrollers or PEMICRO
PROG08SZ — FLASH programmer for M68HC908MR. The PC serial
port baud rate should be set up at 9600 bps with no DTR signal.
The reference board works as a Class III — direct serial to target with
MON08 serial port circuitry built in. The programmers software should be
configured to match this.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
33
Freescale Semiconductor, Inc.
Introduction and Setup
To program the MCU perform the following steps:
1. Unplug the active cord.
2. Install a shorting jumper on pins 1 and 2 of JP1 to enter the
microcontroller to monitor mode.
3. Connect a serial cable from a PC RS-232 serial port to the
reference board’s DB9 connector J5.
Freescale Semiconductor, Inc...
4. Connect external 18 Vdc power supply to J6 and slide switch S5
to position labeled “EXT”. Or, plug ac line cord into jack J1 and turn
on the main switch S4.
5. Continue with the FLASH programming procedure of the software
used by the computer.
Figure 1-7. Monitor Setup
DRM007
34
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Introduction and Setup
Setup Guide
1.9.2 Running Mode Setup
Setup procedure for running mode is described here. This procedure
supposes the microcontroller is programmed with a valid version of
code. Before starting you must turn off the main switch S4.
1. Unplug the ac line cord.
2. Install a shorting jumper on pins 2 and 3 of JP1 to entry
microcontroller to user mode.
Freescale Semiconductor, Inc...
3. Connect motor phase terminals to connector J2 according to
labels near the connector.
4. Connect motor Hall sensor terminals to header J8 according to its
label.
5. Slide switch S5 to position labeled “INT”.
6. Plug ac line cord into jack J1.
7. Turn on the main switch S4.
Alternatively to steps 5 through 7, you can connect an external 18 Vdc
power supply to J6 and slide switch S5 to position labeled “EXT”.
The green LED, D21, must be turned on indicating that the 5 Vdc
regulated power supply is working properly.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
DRM007
35
Freescale Semiconductor, Inc.
Introduction and Setup
HALL EFFECT
SENSORS CONNECTOR
LCD
EXTERNAL 18 VDC
SOURCE CONNECTOR
TEMPERATURE
SENSOR
CONNECTOR
POWER ON
LED
ENTER
SWITCH
RS-232
INTERFACE
OPTIONS
SWITCH
Freescale Semiconductor, Inc...
RESET
SWITCH
SINGLE-PHASE
M1 CONNECTOR
EXTERN/INTERNAL
SOURCE SWITCH
SINGLE PHASE
M2 CONNECTOR
MAIN
SWITCH
3-PHASE
MOTOR
CONNECTOR
A.C. JACK
Figure 1-8. Board Layout
DRM007
36
BLDC Motor Control Board for Industrial and Appliance Applications
Introduction and Setup
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Section 2. Operational Description
Freescale Semiconductor, Inc...
2.1 Contents
2.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.3
Electrical Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.4
User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.5
Connectors Pin Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.5.1
J1 — AC Jack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.5.2
J2 — 3-Phase Motor Connector. . . . . . . . . . . . . . . . . . . . . . 41
2.5.3
J3 — Single Phase Motor 1 Connector . . . . . . . . . . . . . . . . 41
2.5.4
J4 — Temperature Sensor Connector . . . . . . . . . . . . . . . . . 41
2.5.5
J5 — RS-232 Interface Connector . . . . . . . . . . . . . . . . . . . . 42
2.5.6
J6 — External 18 Vdc Source Connector. . . . . . . . . . . . . . . 42
2.5.7
J7 — Single Phase Motor 2 Connector . . . . . . . . . . . . . . . . 42
2.5.8
J8 — Motor Hall Effect Sensor Connector . . . . . . . . . . . . . . 42
2.2 Introduction
This section describes the electrical characteristics, user interfaces, and
connections for the BLDC (brushless dc motor) control board.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Operational Description
For More Information On This Product,
Go to: www.freescale.com
DRM007
37
Freescale Semiconductor, Inc.
Operational Description
2.3 Electrical Characteristics
The electrical characteristics in Table 2-1 and Table 2-2 apply to
operation of the BLDC reference board at 25°C.
Table 2-1. Electrical Characteristics for 127 Vac Board Version
Freescale Semiconductor, Inc...
Inputs
Min
Typ
Max
Unit
AC input voltage
110
120
127
V RMS
AC input current
—
—
9
A RMS
Auxiliary dc input voltage
16
18
20
V
Auxiliary dc input current
—
—
150
mA
Minimum logic 1 input voltage
3.5
—
—
V
Maximum logic 0 input voltage
—
—
1.5
V
Motor output voltage
—
—
180
V RMS
Motor output current
—
—
8
A RMS
9504
9600
9696
Baud
RS-232 connection speed
Table 2-2. Electrical Characteristics for 230 Vac Board Version
Inputs
Min
Typ
Max
Unit
AC input voltage
210
220
230
V RMS
AC input current
—
—
9
A RMS
Auxiliary dc input voltage
16
18
20
V
Auxiliary dc input current
—
—
150
mA
Minimum logic 1 input voltage
3.5
—
—
V
Maximum logic 0 input voltage
—
—
1.5
V
Motor output voltage
—
—
320
V RMS
Motor output current
—
—
8
A RMS
9504
9600
9696
Baud
RS-232 connection data rate
DRM007
38
BLDC Motor Control Board for Industrial and Appliance Applications
Operational Description
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Operational Description
User Interfaces
2.4 User Interfaces
Freescale Semiconductor, Inc...
The BLDC board user interface consists of a 16 x 2 line character liquid
crystal display (LCD), a LCD contrast potentiometer, a reset switch, a
jumper, two push buttons, a slide switch, an indicator light-emitting diode
(LED), and an optoisolated RS-232 interface.
•
D21: PWR ON — D21, labeled PWR ON, illuminates when power
is applied to the board.
•
JP1 — Jumper JP1 is a 3-position jumper header. When shorted
between position 1 and 2 the microcontroller is set to enter the
HC08 monitor mode. For more detailed information, refer to the
MC68HC908MR8 Technical Data (Motorola document order
number MC68HC908MR8/D).
•
LCD — A 16 characters per 2 lines liquid crystal display.
•
S5 — S5 is a slide switch located on the top-right side of the board.
It is used to select between external or internal input of power for
15 Vdc and 5 Vdc power supplies.
•
S1: RESET — S1, the RESET switch, is a push button located
near the right border of the board. It resets the microcontroller of
the board.
•
S2: OPTIONS — Push-button labeled OPTIONS scrolls all the
washing machine cycles programmed.
•
S3: ENTER — Push-button labeled ENTER selects the options
showed in the LCD.
•
J5 — An Optoisolated RS-232 interface, for monitor mode
communication with a host computer, is available via DB-9
connector J5.
After turning on the board, when the board is programmed with code
version “BLDC CODE V1.s19”, the first message displayed on the LCD
is “BLDC WASH”.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Operational Description
For More Information On This Product,
Go to: www.freescale.com
DRM007
39
Freescale Semiconductor, Inc.
Operational Description
Freescale Semiconductor, Inc...
By pressing the push button labeled OPTIONS (S2) the following menu
options (defined in the following paragraphs) are displayed on the LCD:
•
“Fault Occurred!!!”
•
“Motor Stalled!!!”
•
“BLDC WASH”
•
“BLDC SPIN CW”
•
“BLDC SPIN CCW”
•
“SPEED DES +1980 CU +000”
•
“BLDC STOP”
“Fault Occurred!!!” is a message display when an over voltage or over
current has activated the FAULT1 input signal. The motor is stopped
when this happens and the message is displayed.
“Motor Stalled!!!” is a message displayed when the motor is stalled.
“BLDC WASH” option is the typical washing cycle. The motor rotates in
both directions, clockwise and counterclockwise. To produce this
movement of the motor a defined look-up table of desired speeds is
accessed continuously.
“BLDC SPIN CW” option makes the motor rotate in a clockwise direction.
It is applied as a starting curve table and then the speed is maintained at
a desired value programmed in software.
“BLDC SPIN CCW” option behaves similar to “BLDC SPIN CW” but in
counterclockwise direction.
“SPEED” option displays the desired speed (‘DES’) programmed in
software and the current speed (‘CU’), both in RPMs with a direction sign
(‘+’ or ‘–’) corresponding to either clockwise or counterclockwise
direction.
“BLDC STOP” option is intended to stop the motor.
When the push button labeled ENTER (S3) is pressed, the option
showed on the LCD is executed. For example, if the option “BLDC SPIN
CW” is displayed on the LCD and this button is pressed then the spin
DRM007
40
BLDC Motor Control Board for Industrial and Appliance Applications
Operational Description
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Operational Description
Connectors Pin Descriptions
clockwise cycle starts. Stopping a washing cycle is accomplished by
selecting the option “BLDC STOP” by mean of OPTIONS button and
then pressing the ENTER button.
2.5 Connectors Pin Descriptions
The following subsections describe the connector pins.
Freescale Semiconductor, Inc...
2.5.1 J1 — AC Jack
Table 2-3. AC Jack Connector (J1)
Pin Number
Name
Description s
1
Line
Line signal
2
Neutral
Neutral signal
3
GND
Chassis ground
2.5.2 J2 — 3-Phase Motor Connector
Table 2-4. 3-Phase Motor Connector (J2)
Pin Number
Name
Description
1
Phase A
Signal for phase A motor terminal
2
Phase B
Signal for phase B motor terminal
3
Phase C
Signal for phase C motor terminal
2.5.3 J3 — Single Phase Motor 1 Connector
Table 2-5. Single-Phase Motor 1 Connector (J3)
Pin Number
Name
Description
1
Phase B
Signal for phase B motor terminal
2
Phase C
Signal for phase C motor terminal
2.5.4 J4 — Temperature Sensor Connector
Table 2-6. Temperature Sensor Connector (J4)
Pin Number
Name
Description
1
VCC
5 Vdc output signal
2
TEMPERATURE_SENSE
DC input signal from
temperature sensor
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Operational Description
For More Information On This Product,
Go to: www.freescale.com
DRM007
41
Freescale Semiconductor, Inc.
Operational Description
2.5.5 J5 — RS-232 Interface Connector
Table 2-7. Optoisolated RS-232 DB-9 Connector (J5)
Freescale Semiconductor, Inc...
Pin Number
Name
Description
1
Unused
N/A
2
RxD
Data received by the PC from the control board
3
TxD
Data transmitted from the PC to the control board
4
DTR
Positive or negative voltage for communication
5
GND
Common ground reference
6
Unused
N/A
7
RTS
Negative or positive voltage for communication
8
Unused
N/A
9
Unused
N/A
2.5.6 J6 — External 18 Vdc Source Connector
Table 2-8. External 18 Vdc Source Connector (J6)
Pin Number
Name
Description
1
18 Vdc
18 Vdc signal from external source
2
GND
Common ground reference
2.5.7 J7 — Single Phase Motor 2 Connector
Table 2-9. Single-Phase Motor 2 Connector (J7)
Pin Number
Name
Description
1
Phase B
Signal for phase B motor terminal
2
Phase C
Signal for phase C motor terminal
2.5.8 J8 — Motor Hall Effect Sensor Connector
Table 2-10. Motor Hall Effect Sensors Connector (J8)
Pin Number
DRM007
42
Name
Description
1
GND
GND
2
VCC
5 Vdc output signal
3
HALL_A
Input signal from motor Hall sensor A
4
HALL_B
Input signal from motor Hall sensor B
5
HALL_C
Input signal from motor Hall sensor C
BLDC Motor Control Board for Industrial and Appliance Applications
Operational Description
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Section 3. Schematics and Bill of Materials
Freescale Semiconductor, Inc...
3.1 Contents
3.2
Schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.3
Bill of Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.2 Schematics
A set of schematics for the BLDC (brushless dc motor) control board
appears in Figure 3-1 through Figure 3-5. Interrupted lines coded with
the same letters are electrically connected.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
DRM007
43
22nF / 400V
C2
1
S4
10A
J6
1
2
F2
7A Fast Acting
R7
(BC1429-ND @ 127VAC) (BC1432-ND @ 230VAC)
22nF / 400V
C39
2
J1
PLUG AC
3
IC2
MC78M15CDT
3
IN OUT
GND
8
6
7
5
470uF/25V
+ C4
500mA
F1
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
B2
GBPC2508W
+
GND
+
C6
470uF/25V
100nF / 16V
C45
C49
0.1 uF
C5
0.1uF/50V
D21
GREEN
R40
330
+
C48
0.1 uF
VCC
V_BUS
+15V
C46
22nF / 400V
C1
(1500uF/250V @ 127VAC) (560uF/400V @ 230VAC)
B1
1KAB05E-ND
S5
470uF/10V
+ C50
R52
(47K/1W @ 127VAC) (150K/1W @ 230VAC)
Figure 3-1. Power Supply
-
RT1
CL-40
-
+
IC3
MC33269DT-5.0
3
IN OUT
100nF/25V
C19
1
T1
(SW-328 @ 127VAC) (DSW-328 @ 230VAC)
4
2
3
1
2
44
2
DRM007
t
EXTERNAL_POWER_SUPPLY_CONNECTOR
1
C47
0.1 uF
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
C32
0.1uF
+15V R39
2.2k
C15
0.02uF
C14
15pF
D20
8.2V
S3
ENTER
R30
10k
VCC
FAULT
PWM_AT
PWM_AB
PWM_BT
PWM_BB
PWM_CT
PWM_CB
X1
4MHz
C13
15pF
1x3 PIN HEADER
JP1
VCC
C11
0.1uF
R23
10k
R24
10M
R33
VSSA
OSC2
OSC1
CGMXFC
/IRQ
PWM1
PWM2
PWM3
BLDC Motor Control Board for Industrial and Appliance Applications
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
R48
100K
+
VCC
R4
1K
R60
1K
TxD
RxD
RS
R41
330
Q7
2N2222
VCC
R57
1K
ENABLE
PTA1/ATD1
PTA0/ATD0
PTB6/TCH1B
PTB5/TCH0B
VSS
VDD
PTB4/TCH1A
PTB3/TCH0A
Figure 3-2. MCU
VCC
IC9
MC68HC908MR8
1
2
3
4
5
6
7
8
C12
0.1uF
C42
10uF/10V
4.7
VCC
1N4148
D2
24
23
22
21
20
19
18
17
10K
R22
+
TEMPERATURE_SENSE
V_SENSE
I_SENSE
32
31
30
29
28
27
26
25
VDDA
/RST
VREFH
PTA6/ATD6
PTA5/ATD5
PTA4/ATD4
PTA3/ATD3
PTA2/ATD2
PWM4
PWM5
PWM6
PTC0/FAULT1
PTC1/FAULT4
PTB0/RxD
PTB1/TxD
PTB2/TCLKA
9
10
11
12
13
14
15
16
S1
Reset
VCC
R29
10K
4
3
2
1
VCC
5
6
7
8
R34
2.2K
C17
10uF/35V
S2
OPTIONS
IC8
LTV-827S
C18
10uF/35V
VCC
C16
0.47uF/10V
RS
ENABLE
R3 20K
+
10nF
10nF
D9 1N4148
D3 1N4148
D4 1N4148
D1 1N4148
C35
R27
1K
C34
R26
1K
C52
VCC
100
TxD
RTS
RxD
DTR
5
9
4
8
3
7
2
6
1
0.47uF/10V
GND
10nF
C36
100
R53
100
R54
R55
R28
1K
J8
HALL_EFFECT_CONN
LCD
1x14 PIN HEADER
VCC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
J5
5
4
3
2
1
MOTOROLA
HALL_C
HALL_B
HALL_A
VCC
GND
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Schematics
DRM007
45
DRM007
46
PWM_CT
PWM_CB
PWM_BT
PWM_BB
PWM_AT
PWM_AB
C54
1nF
C55
1nF
C51
1nF
R58
10K
R51
10K
R56
10K
C53
1nF
C56
1nF
C57
1nF
R59
10K
R50
10K
R49
10K
D23
D14
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
D19
C8
0.1uF
+15V
C27
0.1uF
+15V
C24
0.1uF
+15V
6
8
1
4
2
3
6
8
1
4
2
3
6
8
1
4
2
3
HO
LO
HO
LO
HO
LO
IR2101/SO
VS
VB
VCC
COM
HIN
LIN
IC1
IR2101/SO
VS
VB
VCC
COM
HIN
LIN
IC5
IR2101/SO
VS
VB
VCC
COM
HIN
LIN
IC4
7
5
7
5
7
5
R20
600
R45
75
R21
600
R44
75
R38
600
R43
75
R37
600
R42
75
R36
600
R46
75
Figure 3-3. Gate Driver
C30
0.47uF/25V
+ C9
33uF/50V
MURA160T3
C10
0.47uF/25V
C29
0.47uF/25V
+ C26
33uF/50V
MURA160T3
C25
0.47uF/25V
C31
0.47uF/25V
+ C23
33uF/50V
MURA160T3
C22
0.47uF/25V
R35
600
R47
75
D5
MBRS130CT
D7
MBRS130CT
D18
MBRS130CT
D16
MBRS130CT
D13
MBRS130CT
D11
MBRS130CT
Freescale Semiconductor, Inc...
D6
MMSZ5248BT1
D8
MMSZ5248BT1
D17
MMSZ5248BT1
D15
MMSZ5248BT1
D12
MMSZ5248BT1
D10
MMSZ5248BT1
SOURCE_COM
GATE_CB
SOURCE_CT
GATE_CT
SOURCE_COM
GATEBB
SOURCE_BT
GATE_BT
SOURCE_COM
GATE_AB
SOURCE_AT
GATE_AT
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
MOTOROLA
SOURCE_COM
BLDC Motor Control Board for Industrial and Appliance Applications
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
Q4
IRFB17N50L
Q3
IRFB17N50L
GATE_CT
1
2
1
2
1
2
3
J7
J3
J2
GATE_CB
PHASE_C
SOURCE_CT
Figure 3-4. 3-Phase H-Bridge
PHASE_A
PHASE_B
PHASE_C
SHUNT_-
R19
0.005 Ohms / 3 Watts / 1%
SHUNT_+
GATE_BB
Q2
IRFB17N50L
GATE_AB
SOURCE_BT
GATE_BT
PHASE_B
Q1
IRFB17N50L
PHASE_A
SOURCE_AT
GATE_AT
V_BUS
Q6
IRFB17N50L
Q5
IRFB17N50L
SINGLE_PHASE2_CONNECTOR
SINGLE_PHASE1_CONNECTOR
3_PHASE_CONNECTOR
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Schematics
DRM007
47
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
VCC
R10
500K 1%
R12
(10k 1% @ 127VAC) (2.5k 1% @ 230VAC)
V_BUS
R25
500K 1%
C20
10pF
C21
22pF
R11
10k 1%
R9
10K 1%
R15
100K 1%
2 -
SHUNT_R18
1K 1%
3 +
R16
100K 1%
SHUNT_+
R17
1K 1%
8
1
IC6A
MC33502D
C43
68pF
100
R13
C7
15pF
+15V
3
2
C37
20nF
VCC
R2
10K
7
LM393D
IC7A
1
C28
22pF
R5
2.5K 1%
C3
0.1uF
6 -
5 +
R31
8.25k 1%
R6
10K 1%
R32
1K
+15V
5
6
C44
15pF
D22
1N5817MCT-ND
IC6B
MC33502D
C40
0.1uF
C41
0.1uF
Figure 3-5. Current and Voltage Sense
R14
15K
V_SENSE
4
VCC
8
4
C33
0.1uF
4
8
4
8
VCC
+
-
48
+
DRM007
-
VCC
7
J4
R1
10K
VCC
Q8
2N2222
R8
10K
I_SENSE
TEMPERATURE_SENSE
TEMPERATURE_CONNECTOR
VCC
IC7B
LM393D
1
2
Freescale Semiconductor, Inc...
C38
15pF
FAULT
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Bill of Materials
3.3 Bill of Materials
The BLDC for Washing Machines Motor Controller Board Bill of
Materials (BOM) 127 Vac version is described in Table 3-1. The
230 Vac board version has only five components different from 127 Vac
version, Table 3-2 shows those changes.
Freescale Semiconductor, Inc...
Table 3-1. Bill of Materials for 127 Vac Board (Sheet 1 of 5)
Qty
Value
Description
Label
Manufacturer
Part Number
Distributor
Distributor
Part Number
Diode Bridges
1 1.2 A
1.2 A Rectifier
B1
International Rectifier 1KAB05E
Digikey
1KAB05E-ND
1 25 A
25 A Rectifier
B2
International Rectifier GBPC2508W
Digikey
GBPC2508W-ND
ECOS2EP152EA
Digikey
P7413-ND
Capacitors
1 1500 uF / 250v
Large Can Aluminum
Electrolytic Capacitors
6 0.47 uF / 25v
C10, C22,
Ceramic Capacitor (1206) C25, C29, Panasonic - ECG
C30, C31
ECJ-3YB1E474K
Digikey
PCC1891TR-ND
5 15 pF
C7, C13,
Ceramic Capacitor (0805) C14, C38, Yageo America
C44
0805CG150J9B200
Digikey
311-1101-1-ND
2 0.02 uF
Ceramic Capacitor (0805)
ECJ-2VB1H223K
Digikey
PCC223BGCT-ND
1 0.47 uF/10v
Ceramic Capacitor (0805)
ECJ-2YB1C474K
Digikey
PCC1818CT-ND
2 10 uF / 35v
CPOL-USCT3216
C17, C18 Panasonic - ECG
EEV-HA1V100WR
Digikey
PCE3299TR-ND
3 0.022 uF / 400v
Large Ceramic Capacitor
C2, C39,
Vishay / Sprague
C46
225P22394XD3
Newark
47F143
1 10 pF
Ceramic Capacitor (0805)
Yageo America
0805CG100J9B200
Digikey
311-1099-1-ND
2 22 pF
Ceramic Capacitor (0805)
C21, C28 Yageo America
0805CG220J9B200
Digikey
311-1103-1-ND
15 0.1 uF
C3, C8,
C11, C12,
C19, C24,
C27, C32,
Ceramic Capacitor (0805)
Panasonic - ECG
C33, C40,
C41, C45,
C47, C48,
C49
ECJ-2VB1E104K
Digikey
PCC1828TR-ND
3 10 nF
Ceramic Capacitor (0805)
C34, C35,
Panasonic - ECG
C36
ECJ-2VB1H103K
Digikey
PCC103BNCT-ND
C1
Panasonic
C15, C37 Panasonic - ECG
C16
C20
Panasonic - ECG
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
DRM007
49
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Table 3-1. Bill of Materials for 127 Vac Board (Sheet 2 of 5)
Freescale Semiconductor, Inc...
Qty
Value
Description
Label
Manufacturer
Part Number
Distributor
Distributor
Part Number
6 1 nF
C51, C53,
Ceramic Capacitor (0805) C54, C55, Yageo America
C56, C57
0805CG102J9B200
Digikey
311-1122-1-ND
2 470 uF / 25v
Electrolitic Capacitor
C4, C6
Panasonic - ECG
EEV-FK1V471Q
Digikey
PCE3464CT-ND
1 10 uF / 10v
Electrolitic Capacitor
C42
Panasonic - ECG
ECE-V1AA100NR
Digikey
PCE3125CT-ND
1 68 pF
Ceramic Capacitor (0805)
C43
Panasonic - ECG
ECJ-2VC1H680J
Digikey
PCC680CGCT-ND
1 0.1 uF / 50v
Ceramic Capacitor (0805)
C5
Panasonic - ECG
ECJ-2YB1H104K
Digikey
PCC1840CT-ND
1 470 uF / 10v
POL-CAPF
C50
Panasonic - ECG
EEV-FK1A471P
Digikey
PCE3392CT-ND
1 0.47 uF / 10v
Ceramic Capacitor (0805)
C52
Panasonic - ECG
ECJ-2YF1E474Z
Digikey
PCC1857CT-ND
3 33 uF / 50v
CPOL-USCT7343
T491X336K025AS
Newark
C9, C23,
Kemet
C26
Diodes
5 LL4148
LL4148
D1, D2, D3,
Diodes Inc.
D4, D9
LL4148
3 MURA160T3
SCHOTTKY_SMA
D14, D19,
ON
D23
MURA160T3
1 MMSZ5237BT1
Zener Diode 8.2 v
D20
ON
1 Green
SMD Green Led
D21
Stanley Electric Sales
DG1112H-TR
of America
Digikey
404-1026-2-ND
1 1N5817MCT
Schottky - 20v / 1A
D22
Diodes Inc.
Digikey
1N5817MCT-ND
6 MBRS130LT
SCHOTTKY_SMB
D5, D7,
D11, D13, International Rectifier MBRS130LTR
D16, D18
Digikey
MBRS130LCT-ND
D6, D8,
D10, D12, ON
D15, D17
Diodes Inc
SMAZ18-13
Digikey
IR2101S-ND
6
MMSZ5248BT1 Zener Diode 18 v
MMSZ5237BT1
1N5817M
MMSZ5248BT1
Fuses
1 500 mA SMT
SM-FUSESM
F1
Bourns
MF-SM050
1 10 Amp
FUSE22
F2
Schurterinc
OGD 0031.8231
Integrated Circuits
IC1, IC4,
International Rectifier IR2101S
IC5
3
IR2101S
1 MC78M15CDT
Voltage Regulator 15v /
500mA
IC2
ON
MC78M15CDT
1 MC33269DT-5.0
Voltage Regulator 5v /
800mA
IC3
ON
MC33269DT-5.0
1 MC33502D
Dual Operational Amplifier
IC6
ON
MC33502D
DRM007
50
BLDC Motor Control Board for Industrial and Appliance Applications
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Bill of Materials
Table 3-1. Bill of Materials for 127 Vac Board (Sheet 3 of 5)
Qty
Value
Description
Label
Manufacturer
Part Number
Distributor
Distributor
Part Number
1 LM393D
Low Offset Voltage
Comparator
IC7
ON
LM393D
1 LTV-827S
Optoisolator SMD
IC8
Lite-On Inc.
LTV-827S
Digikey
160-1369-5-ND
Freescale Semiconductor, Inc...
Connectors
1 AC_jack
AC Power Connector
J1
SCHURTER
GSP2.9213.13
Newark
32C1691
1 66503
66503
J2
MOLEX/WALDOM
66503
Newark
29B3093
2 6650202
6650202
J3, J7
MOLEX/WALDOM
66502
Newark
29B3092
1
S02P
J4
TYCO
ELECTRONICS
640456-2
Newark
90F4250
1 FDB9
DB9 / Female connector
J5
CINCH
DEKL-9SAT-F
Newark
95F4126
1
W237-102
J6
TYCO
ELECTRONICS
796949-2
Newark
34C9478
1
S05P
J8
TYCO
ELECTRONICS
640456-5
Newark
90F5643
SPC CONNECTORS 8431-0721
Newark
16N2602
Digikey
67-1779-ND
Newark
33C4970
Jumpers
1
JP2E
JP1
LCD
1
LCD_OPTREXN
LCD
LUMEX
LCM-S01602DTR/A
Microcontroller
1 HC908MR8
MC68HC90
Motorola
8MR8
Microcontroller
MC68HC908MR8
Transistors
6 IRFPC40VH
Power Mosfet 500V 17A
Q1, Q2,
Q3, Q4,
Q5, Q6
International Rectifier IRFB17N50L
2 MMBT2222AL
NPN transistor 2N2222AL
Q7, Q8
ON
MMBT2222AL
Resistors
16 10 K
Resistor (0805)
R1, R2, R8,
R22, R23,
R26, R27,
R28, R29,
Yageo America
R30, R49,
R50, R51,
R56, R58,
R59
2 500 k / 1%
Resistor (0805)
R10, R25 Yageo America
1 10 k / 1%
Resistor (0805)
R11
Yageo America
9C08052A1002FKHFT Digikey
311-10.0KCCT-ND
9C08052A4993FKHFT Digikey
311-499KCCT-ND
9C08052A1002FKHFT Digikey
311-10.0KCCT-ND
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
DRM007
51
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Table 3-1. Bill of Materials for 127 Vac Board (Sheet 4 of 5)
Freescale Semiconductor, Inc...
Qty
Value
Description
4 100
Resistor (0805)
1 15 K
Resistor (0805)
2 100 K / 1%
Label
Manufacturer
R13, R53,
Yageo America
R54, R55
Part Number
Distributor
Distributor
Part Number
9C08052A1000FKHFT Digikey
311-100CCT-ND
Yageo America
9C08052A1502FKHFT Digikey
311-15.0KCCT-ND
Resistor (0805)
R15, R16 Yageo America
9C08052A1652FKHFT Digikey
311-16.5KCTR-ND
2 1 K / 1%
Resistor (0805)
R17, R18 Yageo America
9C08052A1001FKHFT Digikey
311-1.00KCCT-ND
1 .005 / 3w / 1%
Shunt Resistor
4 1K
Resistor (0805)
R4, R32,
Yageo America
R57, R60
9C08052A1001FKHFT Digikey
311-1.00KCCT-ND
6 600
Resistor (0805)
R20, R21,
R35, R36, Yageo America
R37, R38
9C08052A6040FKHFT Digikey
311-604CCT-ND
1 10 M
Resistor (0805)
R24
Yageo America
9C08052A1005FKHFT Digikey
311-10.0MCCT-ND
1 8.25 K / 1%
Resistor (0805)
R31
Yageo America
9C08052A8251FKHFT Digikey
311-8.25KCCT-ND
1 4.7
Resistor (0805)
R33
Yageo America
9C08052A4R70JLHFT Digikey
311-4.7ACT-ND
2 2.2 K
Resistor (0805)
R34, R39 Yageo America
9C08052A2201FKHFT Digikey
311-2.20KCCT-ND
2 330
Resistor (0805)
R40, R41 Yageo America
9C08052A3300FKHFT Digikey
311-330CCT-ND
6 75 - 1/4 w
Resistor (1206)
R42, R43,
R44, R45, Yageo America
R46, R47
9C12063A1200FKHFT Digikey
311-120FCT-ND
1 100 K
Resistor (0805)
R48
Yageo America
9C08052A1003FKHFT Digikey
311-100KCTR-ND
1 2.5 K / 1%
Resistor (0805)
R5
Yageo America
9C08052A2501FKHFT Digikey
311-2.50KCCT-ND
1 47k / 1w
Resistor (2512)
R52
Panasonic - ECG
ERJ-1TYJ473U
PT47KXCT-ND
3 10 K / 1%
Resistor (0805)
R6, R9,
R12
Yageo America
9C08052A1002FKHFT Digikey
311-10.0KCCT-ND
2322 594 51516
Digikey
BC1429-ND
ST4TA203
Digikey
ST4A203TR-ND
R14
R19
IRC
OAR-3 0.005 1%
Future Electronics
Digikey
Varistor
1
Varistor 150v RMS
R7
BC Components
NTC
1 CL40
Disc thermistor
RT1
NTC Thermistors
CL40
Potentiometer
1 20 K
Trimmer
R3
Copal Electronics
Switches
1 RESET
Push Button
S1
E-switch
TL59FF260Q
Newark
2
Push Button
S2, S3
E-switch
TL59FF260Q
Newark
1 CKDFA
Main Switch Power
Supply
S4
C&K COMPONENTS DF62J12S2APQF
1
Slide Switch
S5
C&K COMPONENTS CK1101M2S3CQE2
DRM007
52
Newark
91F4835
BLDC Motor Control Board for Industrial and Appliance Applications
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Schematics and Bill of Materials
Bill of Materials
Table 3-1. Bill of Materials for 127 Vac Board (Sheet 5 of 5)
Qty
Value
Description
Label
Manufacturer
Part Number
Distributor
Distributor
Part Number
Transformer
1 328SW
Side-Winder Transformer
T1
Stancor
SW-328
Freescale Semiconductor, Inc...
Test Points
1 VCC
Test Point - Vcc
TP1
Keystone Electronics 5000
Newark
52F7277
1 15V
Test Point - 15v
TP2
Keystone Electronics 5000
Newark
52F7277
1 DGND
Test Point - DGND
TP3
Keystone Electronics 5001
Newark
52F7278
1 AGND
Test Point - AGND
TP4
Keystone Electronics 5001
Newark
52F7278
1 VBUS
Test Point - VBUS
TP5
Keystone Electronics 5000
Newark
52F7277
1 C
Test Point - Hall Sensor C
TP6
Keystone Electronics 5002
Newark
52F7279
1 B
Test Point - Hall Sensor B
TP7
Keystone Electronics 5003
Newark
52F7280
1 A
Test Point - Hall Sensor A
TP8
Keystone Electronics 5004
Newark
52F7281
Digikey
CTX502-ND
Heat Sink
1
Heatsink
U1
Aavid Thermalloy
780103B04500
Crystal
1 4 MHz
4 MHz crystal
CTS-Frequency
Controls
X1
ATS040SM
Table 3-2. Bill of Material Changes for 230 Vac Board
Qty
Value
Description
Label
Part
Number
Manufacturer
Distributor
Distributor
Part Number
Capacitor
1
560 mF/400 V
Large Can Aluminum Electrolytic
Capacitors
C1
Panasonic
ECOS2GP1561EA
Digikey
P6157-ND
Resistors
1
2.5 K/1%
Resistor (0805)
R12
Yageo America
9C08052A2501FKHFT
Digikey
311-2.50KCCT-ND
1
150 K/1 W
Resistor (2512)
R52
Panasonic – ECG
ERJ-1TYJ154U
Digikey
PT150KXCT-ND
2322 594 52516
Digikey
BC1432-ND
Varistor
1
Varistor 250 V RMS
R7
BC Components
Transformer
1
328 DSW
Dual Side-Winder Transformer
T1
Stancor
DSW-328
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
DRM007
53
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Schematics and Bill of Materials
DRM007
54
BLDC Motor Control Board for Industrial and Appliance Applications
Schematics and Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Section 4. Hardware Design Considerations
Freescale Semiconductor, Inc...
4.1 Contents
4.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.3
Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56
4.4
RS-232 interface and MON08 Hardware Interface. . . . . . . . . . 58
4.5
Clock Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
4.6
Hall-Effect Sensors Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.7
LCD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
4.8
Reset Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.9
3-Phase H-Bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63
4.10
Current Feedback and Cycle-by-Cycle Limiting . . . . . . . . . . . . 64
4.11
Voltage Feedback. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
4.12
Current and Voltage Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.13
Heat Sink Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
55
Freescale Semiconductor, Inc.
Hardware Design Considerations
4.2 Introduction
The hardware for motor control developed for the reference design has
the power output for the motor, and the microcontroller on the same
board. In addition to the hardware that is needed to run the motor, a
variety of feedback signals that facilitate control algorithm development
are included.
Freescale Semiconductor, Inc...
4.3 Power Supply
The main power input to the board is through a power jack (J1). From
this power input, V_BUS signal is generated. This voltage (V_BUS) is
generated through a rectifier bridge (B2). To minimize the effects of the
in-rush current when S4 is turned on, a NTC (RT1) was placed to slowly
charge V_BUS capacitor (C1). When S4 is turned OFF, C1 is sometimes
charged (depending on last system operation). To avoid any risk, a
discharge resistor (R52) is connected in parallel to C1. See Figure 4-1.
NOTE:
J1
PLUG AC
1
There is also an Overvoltage (R7) and an Overcurrent (F2) protection.
S4
10A
RT1
CL-40
F2
7A Fast Acting
t
C1
(1500uF/250V @ 127VAC) (560uF/400V @ 230VAC)
V_BUS
2
+
C2
22nF / 400V
3
C39
-
22nF / 400V
B2
GBPC2508W
R7
(BC1429-ND @ 127VAC) (BC1432-ND @ 230VAC)
C46
22nF / 400V
+
R52
(47K/1W @ 127VAC) (150K/1W @ 230VAC)
Figure 4-1. V_BUS Power Supply
DRM007
56
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Hardware Design Considerations
Power Supply
From the line input jack (J1) the low voltage power supplies (5 Vdc and
15 Vdc) are derived. These power supplies are generated using voltage
regulators (IC2 and IC3). To help developers vary V_BUS voltage using
a variable transformer in J1 and also let them program the
microcontroller without having the power-stage turned on (V_BUS),
an alternate Vdc power supply can be connected (J6) to keep 5 Vdc and
15 Vdc on the board when varying AC voltage in J1. To enable this
external power supply, S5 slide switch must be turned to “EXT” position.
A green LED (D21) was included to show proper +5 Vdc power supply
operation. See Figure 4-2.
+15V
C47
0.1 uF
1
IC2
MC78M15CDT
GN
3
IN D OUT
1
+ C4
2
IC3
MC33269DT-5.0
GN
3
IN D OUT
C19
470uF/25V
C49
0.1 uF
VCC
+ C50
2
C45
470uF/10V
100nF/25V
R40
330
C48
0.1 uF
100nF / 16V
D21
GREEN
EXTERNAL_POWER_SUPPLY_CONNECTOR
J6
1
2
F1
J1
PLUG AC
1
C2
22nF / 400V
1
S4
10A
5
500mA
F2
7A Fast Acting
S5
2
3
2
3
6
7
4
8
-
+
C39
+
22nF / 400V
B1
1KAB05E-ND
C6
470uF/25V
C5
0.1uF/50V
T1
(SW-328 @ 127VAC) (DSW-328 @ 230VAC)
R7
(BC1429-ND @ 127VAC) (BC1432-ND @ 230VAC)
RT1
CL-40
t
C1
(1500uF/250V @ 127VAC) (560uF/400V @ 230VAC)
V_BUS
+
-
C46
22nF / 400V
+
B2
GBPC2508W
R52
(47K/1W @ 127VAC) (150K/1W @ 230VAC)
Figure 4-2. 15 Vdc and 5 Vdc Power Supplies
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
57
Freescale Semiconductor, Inc.
Hardware Design Considerations
4.4 RS-232 interface and MON08 Hardware Interface
Freescale Semiconductor, Inc...
The board provides an RS-232 interface by the use of an optoisolator
referenced at 5 Vdc voltage level (IC8). This topology lets the user
program the microcontroller using the MON08 interface, and
communicate via the RS-232 interface when operating in run mode. This
topology also, allows operating the board ground at a different level than
the PC (or RS-232 device), avoiding the risk of damaging the board or
the PC. See Figure 4-3.
MC68HC908MR8
5
/IRQ
PTB1/TxD
PTB0/RxD
IC9
14
1x3 PIN HEADER
JP1
VCC
15
+
R57
1K
R30
10k
VCC
C18
10uF/35V
+
C17
10uF/35V
R60
1K
D1 1N4148
RxD
D4 1N4148
D2
+15V R39
2.2k
C32
0.1uF
GND
1
VCC
8
DTR
1N4148
S3
ENTER
2
R41
330
3
VCC
D20
8.2V
7
IC8
LTV-827S
D3 1N4148
6
TxD
4
C42
10uF/10V
R48
100K
+
5
R34
2.2K
D9 1N4148
TxD
RTS
RxD
5
9
4
8
3
7
2
6
1
R4
1K
Q7
2N2222
Figure 4-3. RS-232 and MON08 Interfaces
DRM007
58
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware Design Considerations
Clock Source
4.5 Clock Source
The board uses a 4.00-MHz crystal (X1) connected to microcontroller’s
oscillator inputs (OSC1 and OSC2). The MC68HC908MR8 uses its
internal phase-locked loop (PLL) to multiply the input frequency in order
to achieve its 8 MHz maximum operating frequency. See Figure 4-4.
Freescale Semiconductor, Inc...
C13
15pF
X1
4MHz
R24
10M
2
3
OSC2
OSC1
MC68HC908MR8
C14
15pF
IC9
Figure 4-4. Clock Source
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
59
Freescale Semiconductor, Inc.
Hardware Design Considerations
4.6 Hall-Effect Sensors Interface
Freescale Semiconductor, Inc...
The board contains a Hall-effect interface connected to the
microcontroller’s timer A (channel 1) and timer B (channel 0 and
channel 1) port signals, TCH1A, TCH0B, and TCH1B. The circuit is
designed to accept +5.0 V Hall-effect sensor inputs. Input noise filtering
is supplied on the input path for the Hall-effect interface. Figure 4-5
shows the hardware interface.
HALL_EFFECT_CONN
J8
VCC
PTB6/TCH1B
MC68HC908MR8
PTB5/TCH0B
PTB4/TCH1A
5 4 3 2 1
22
21
C B A
R26
1K
R27
1K
R28
1K
18
R55
100
R54
100
R53
IC9
C34
C35
C36
10nF
10nF
10nF
100
VCC
C52
0.47uF/10V
Figure 4-5. Hall-Effect Sensors Interface
DRM007
60
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware Design Considerations
LCD Interface
4.7 LCD Interface
The board contains an LCD as main user interface feedback. The LCD
contains an internal driver. The display is controlled and managed by the
microcontroller through it’s port signals. Figure 4-6 shows the hardware
interface.
VCC
R22
R3
Freescale Semiconductor, Inc...
10K
26
PTA3/ATD3
25
PTA2/ATD2
PTA1/ATD1
PTA0/ATD0
LCD
1x14 PIN HEADER
20K
1
2
3
4
5
6
7
8
9
10
11
12
13
14
24
23
MC68HC908MR8
PTB2/TCLKA
16
PTC1/FAULT4
13
IC9
Figure 4-6. LCD Interface
4.8 Reset Button
The board contains a reset button (RESET). This button is directly
connected to the microcontroller’s reset pin which causes an external pin
reset to the microcontroller. Figure 4-7 shows the hardware interface.
Pulling the asynchronous RST pin low halts all processing. The PIN bit
of the SIM reset status register (SRSR) is set as long as RST is held low
for a minimum of 67 CGMXCLK cycles, assuming that neither the
power-on reset (POR) nor the low-voltage inhibit (LVI) was the source of
the reset. Refer to Table 4-1 detailed information on PIN bit set timing
and to Figure 4-8 for the relative timing.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
61
Freescale Semiconductor, Inc.
Hardware Design Considerations
VCC
R23
10k
S1
Reset
31
/RST
C11
0.1uF
Freescale Semiconductor, Inc...
MC68HC908MR8
IC9
Figure 4-7. Reset Button
Table 4-1. PIN Bit Set Timing
Number of Cycles Required
to Set PIN
Reset Type
POR/LVI
4163 (4096 + 64 + 3)
All Others
67 (64 + 3)
CGMOUT
RST
IAB
PC
VECT H
VECT L
Figure 4-8. External Reset Timing
DRM007
62
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware Design Considerations
3-Phase H-Bridge
4.9 3-Phase H-Bridge
Freescale Semiconductor, Inc...
The power output is configured as a 3-phase MOSFET inverter with
free-wheeling diodes. The gate drivers of the MOSFETs are integrated
circuits for high and low side gate drivers with high voltage capability.
The gate drivers have a minimum logic 1 input of 3 volts and a maximum
logic 0 input voltage of 0.8 volts. A schematic of one of the three phases
and its corresponding gate driver circuitry is shown in Figure 4-9.
R44
75
R21
600
C10
0.47uF/25V
+15V
D19
C54
1nF
R58
10K
C53
1nF
R59
10K
MURA160T3
C8
0.1uF
+ C9
33uF/50V
D8
MMSZ5248BT1
SOURCE_CT
IC1
2
3
PWM_CT
PWM_CB
GATE_CT
D7
MBRS130CT
6
8
1
4
HIN
LIN
HO
LO
VS
VB
VCC
COM
7
5
R45
75
R20
600
GATE_CB
D5
MBRS130CT
IR2101/SO
D6
MMSZ5248BT1
SOURCE_COM
C30
0.47uF/25V
V_BUS
GATE_CT
SOURCE_CT
Q5
IRFB17N50L
PHASE_C
GATE_CB
SOURCE_COM
Q6
IRFB17N50L
SHUNT_+
R19
0.005 Ohms / 3 Watts / 1%
SHUNT_-
Figure 4-9. Phase C Output and Gate Driver
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
63
Freescale Semiconductor, Inc.
Hardware Design Considerations
Freescale Semiconductor, Inc...
As a protection for power transitions of the microcontroller’s power
supply, there are pull-down resistors R58 and R59. So, the MOSFETs
are not triggered during transitions.
The gate drive circuit has two different impedance output values, one for
turn-on time and other for turn-off time for each of the power transistors,
TOP and BOTTOM in each phase. This is possible using D7 and D5 for
the turn-off impedances of the transistors per phase. The turn-on
impedance is given by R20 and R21 respectively, and the turn-off
impedance is given by the parallel connection of R44||R21 and R45||R20
respectively. With the values displayed in the schematic, the turn-on
time is 800 ns, and the turn-off time is 600 ns with the IRFB17N50L
MOSFET.
In the software for this reference design, deadtime is fixed to 2 µs. This
gives enough time for the transistors to change their state of
conductance with no short circuit of the phase output.
The bootstrap capacitor C10 is used to turn-on the TOP transistor
without a charge pump circuitry. Turning on the lower transistors first is
recommended in order to charge this bootstrap capacitor each time the
motor is initially energized.
4.10 Current Feedback and Cycle-by-Cycle Limiting
The 3-phase current is sensed by resistor R19 in Figure 4-9, and
amplified by a differential amplifier shown in Figure 4-10. The circuit
provides an amplified voltage of the chopped current of the inverter.
The output of the amplifier represents 0.5 volts per ampere in the shunt
resistor (R19). The MC33502 OPAMP was used for this amplifier circuit.
At this point, for current sensing within the microcontroller the ADC
conversion must be synchronized with the PWM module. That is why a
peak detector circuit was implemented to have a suitable current
waveform for sensing.
DRM007
64
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware Design Considerations
Current Feedback and Cycle-by-Cycle Limiting
V_BUS
GATE_CT
Q7
IRFB17N50L
SOURCE_CT
VCC
GATE_CB
SOURCE_COM
R16
100K 1%
R17
1K 1%
R19
0.005 Ohms / 3 Watts / 1%
8
IC8A
MC33502D
3 +
1
2 R18
1K 1%
R15
100K 1%
SHUNT_AMP_CURRENT
4
Figure 4-10. Current Differential Amplifier
This peak detector is shown in Figure 4-11. Consisting of a voltage
follower configuration with diode output for detecting peaks in the input
signals.
8
VCC
5 +
SHUNT_AMP_CURRENT
R13
100
C7
15pF
IC6B
MC33502D
7
6 -
C37
20nF
I_SENSE
D22
1N5817MCT-ND
4
Freescale Semiconductor, Inc...
C33
0.1uF
Q9
IRFB17N50L
R2
10K
Figure 4-11. Current Peak Detector for Current Sensing
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
65
Freescale Semiconductor, Inc.
Hardware Design Considerations
This peak is stored in capacitor C37 when current flows through R19.
When the MOSFETs are switched off, the voltage stored in C37 starts to
discharge through R2.
The output of the peak detector is connected to a comparator for the
cycle-by-cycle current limiting. The FAULT1 input signal of the
microcontroller is used for limiting the current. The FAULT configuration
in the MCU CONFIG register is set to automatic operation; so,
cycle-by-cycle current limiting is accomplished.
Freescale Semiconductor, Inc...
The current limiter is shown in Figure 4-12. A LM393 was used for this
purpose. The output of this current limiter is an open collector, so
multiple inputs of limiting can be possible using only one FAULT input
signal of the microcontroller.
I_SENSE
R32
1K
C28
22pF
8
+15V
7
+
5
-
6
R5
2.5K 1%
4
C44
15pF
VCC
I_LIMIT_OC
IC7B
LM393D
R6
10K 1%
Figure 4-12. Cycle-by-Cycle Current Limiter
DRM007
66
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware Design Considerations
Voltage Feedback
4.11 Voltage Feedback
For V_BUS FAULT there are two different values, depending on the
reference board. For the 115 Vac reference design board, the value is
chosen for 250 Vdc maximum, and 400 Vdc maximum for the 230 Vac
reference design board. The LM393 is used for the voltage FAULT
signal, which is shared with the current FAULT signal of the circuit shown
in Figure 4-12. The voltage feedback circuitry and voltage FAULT
detector (V_LIMIT_OC) is shown in Figure 4-13.
C20
10pF
V_SENSE
R9
10K 1%
V_BUS
C43
68pF
R14
15K
4
R10
500K 1%
2
3
R11
10k 1%
V_LIMIT_OC
LM393D
IC7A
8
VCC
1
+
R25
500K 1%
-
Freescale Semiconductor, Inc...
Bus voltage is scaled down by a voltage divider consisting of R25, R10,
and R9. The values are chosen such that a 500-volt maximum bus
voltage corresponds to 5 volts at output V_SENSE. So,
V_SENSE = V_BUS / 100.
+15V
R12
(10k 1% @ 127VAC) (2.5k 1% @ 230VAC)
C21
22pF
C3
0.1uF
Figure 4-13. Voltage Feedback and Fault Detector
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
67
Freescale Semiconductor, Inc.
Hardware Design Considerations
4.12 Current and Voltage Limiter
The circuit is shown in Figure 4-14. FAULT is signal connected to the
FAULT1 pin of the microcontroller. This input of the microcontroller is
used for limiting current and voltage. When either input of the FAULT is
in logic 0 state, the transistor Q8 is switched off and the FAULT signal
will be set to logic 1.
VCC
Freescale Semiconductor, Inc...
VCC
R8
10K
R1
10K
FAULT
I_LIMIT_OC
Q8
2N2222
V_LIMIT_OC
C38
15pF
Figure 4-14. Current and Voltage Limiter
4.13 Heat Sink Selection
A recommended application note written by the manufacturer of the heat
sink used in this board for selecting a heat sink can be found on the
World Wide Web at:
http://www.aavidthermalloy.com/technical/papers/pdfs/select.pdf
The thermal model of a semiconductor with heat sink is:
RϑDA =
Where:
RSDA
DRM007
68
(T
J MAX
− TA
PD
)− R
ϑJC
− RϑCD
Thermal impedance of selected heat sink
TJMAX
MOSFET junction maximum temperature
TA
Ambient temperature
PD
MOSFET power
RSJC
MOSFET thermal impedance junction to case
RSCD
Thermal impedance of the thermal conductive tape
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware Design Considerations
Heat Sink Selection
The values for the components selected on this board are:
Heat sink (part number: 780103B04500):
RSDA = 1.45 °C-in2 /W
MOSFET (part number: IRF17N50L):
RSJC = 0.75 °C-in2 /W
Thermally conductive tape (part number: 8805):
RSCD = 0.50 °C-in2 /W
Freescale Semiconductor, Inc...
If we suppose that every MOSFET can be as hot as 110°C and ambient
temperature is 25°C, we will get:
PD = 31.48 W
This is the maximum total power allowed for the six MOSFETs with this
heat sink.
The formula to obtain PD for a single MOSFET is:
PD = (I )2·(Rds )
eff
on
Where:
PD
Power dissipated by a single MOSFET when conducting
Ieff
Effective MOSFET current
Rdson
MOSFET drain-source impedance when it is conducting
(0.28 Ω for this MOSFET)
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
69
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Hardware Design Considerations
DRM007
70
BLDC Motor Control Board for Industrial and Appliance Applications
Hardware Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Section 5. Software Design Considerations
Freescale Semiconductor, Inc...
5.1 Contents
5.2
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.3
Controller Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.4
Speed Control Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
5.4.1
Motor Stalled Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . .79
5.5
Commutation Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.6
Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.6.1
Processes: Latest Position Capture,
Period Measuring, and Speed Calculation . . . . . . . . . . . 84
5.6.2
Process Speed Controller . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.6.3
Process MOSFET Gating Selection . . . . . . . . . . . . . . . . . . . 84
5.6.4
Process Washing Machine. . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.7
Application State Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.8
Drive State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.9
Description of Routines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1
Main(void). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.1
Stop Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.2
Waiting for Command . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.3
Displaying Actual and Reference Speed . . . . . . . . . . . . . 89
5.9.1.4
Wash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.9.1.5
Spin CW and Spin CCW . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.1.6
Fixed Reference Speed . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.2
InitPLL(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.3
InitPWMMC(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.4
InitTimerA(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.9.5
InitTimerB(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9.6
Byte ResolveButtons(void) . . . . . . . . . . . . . . . . . . . . . . . . . . 91
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
71
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software Design Considerations
5.9.7
5.9.8
5.9.9
5.9.10
5.9.11
5.9.12
5.9.13
5.9.14
5.9.15
5.9.16
5.9.17
5.9.18
5.9.19
5.9.20
5.9.21
5.9.22
5.10
InitMotor(Byte Commanded_Operation) . . . . . . . . . . . . . . . 91
TimerAOverflow_ISR(void). . . . . . . . . . . . . . . . . . . . . . . . . . 91
Signed Word 16 PIController(void). . . . . . . . . . . . . . . . . . . . 92
MotorStalledProtection(void) . . . . . . . . . . . . . . . . . . . . . . . .92
HALLA_ISR(void) and HALLB_ISR(void). . . . . . . . . . . . . . . 92
HALLC_ISR(void). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
NextSequence(void). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
StopMotor(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
InitLCD(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
CtrlLCD(Byte ctrl) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Ctrl8LCD(Byte ctrl) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
MovCursorLCD(Byte places, Byte dir) . . . . . . . . . . . . . . . . . 93
DataLCD(Byte data) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
StringLCD(Byte *msgLCD). . . . . . . . . . . . . . . . . . . . . . . . . . 94
WaitMs(Byte milis) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Wait40ms(void) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
MCU Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5.2 Introduction
This section describes data flow of the software implemented for this
reference design. The microcontroller is mastering all inputs from the
user interface and the Hall effect sensors. From the user interface,
functionality (washing machine process) and desired speed for the
motor can be set. This data is input for the speed controller that is also
detailed in this section. Another input for the speed controller is the
actual speed of the motor that is calculated based on the Hall effect
sensors values. The controller processes this information and calculates
the most suitable value for the MOSFET’s PWM signals. Using PWM
modules, the microcontroller triggers the MOSFET through a power
stage.
NOTE:
DRM007
72
The commutation algorithm and speed control for the motor are driven
by input capture and timer interrupts.
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Controller Design
5.3 Controller Design
The motor system to be controlled was considered as a first order
system, with a time constant of 10 milliseconds. For a robust operation
of the washing machine, a PI controller was implemented with a
controller period of 1 millisecond. The actual motor speed is calculated
from input capture channels, and the desired speed is generated in the
microcontroller depending on the washing machine process being
executed.
Freescale Semiconductor, Inc...
The system has the following transfer function in the continuous time
domain.
1
τ
G (s ) =
s+ 1
τ
Taking the Z transformation and considering the zero-order-hold of the
PWM module, the system’s transfer function becomes:
1 − e −T τ z −1



G (z ) = 
−T
τ
1 − e ⋅ z −1
The PI controller transfer function in the Z domain is:
(
Kp + Ki ) − Kp ⋅ z −1
C (z ) =
1 − z −1
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
73
Freescale Semiconductor, Inc.
Software Design Considerations
Closing the loop:
+
E (z )
R(z )
C (z )
M (z )
G (z )
U (z )
Freescale Semiconductor, Inc...
-
R(z )
C ( z )G ( z )
1 + C ( z )G ( z )
U (z )
R(z )
Gd (z )
U (z )
Where:
1 − e −T τd z −1



Gd (z ) = 
−T
1 − e τd ⋅ z −1
Then, the controller:
C (z ) =
C (z ) =
1− e
−T
1− e
τd
−T
τ
Gd (z )
G (z )[1 − Gd (z )]
1 − e τ ⋅ z −1 (Kp + Ki ) − Kp ⋅ z −1
⋅
=
1 − z −1
1 − z −1
−T
Solving for Ki
Ki = 1 − e
DRM007
74
−T
τd
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Controller Design
And for Kp
Kp =
Ki
1− e
−T
τ
− Ki
Where:
T
— Controller period
τ
— Time constant of motor speed in open loop
Freescale Semiconductor, Inc...
τd — Desired time constant of motor speed in closed loop
Kp — Proportional gain of the controller
Ki — Integral gain of the controller
The implementation of the PI controller using parallel programming is
given in this diagram:
Kp
Mp(z )
+
E (z )
M (z )
+
Ki
1 − z −1
Mi (z )
Converting into equations in discrete time domain:
Mp(K) = Kp • E(K)
Mi(K) = Kp • E(K)
M(K) = Mp(K) + Mi(K)
The targeted motor for the application has a time constant of
10 milliseconds. Based on that, a controller period is defined as
1 millisecond (10 times bigger frequency). Thus, the system has this
transfer function:
0.095163 ⋅ z −1
G (z ) =
1 − 0.904837 ⋅ z −1
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
75
Freescale Semiconductor, Inc.
Software Design Considerations
The desired time constant is 100 milliseconds for the closed loop
system. That gives the following values for the controller parameters:
Ki = 0.00995
Kp = 0.094609
Freescale Semiconductor, Inc...
In the microcontroller implementation of this controller, a scale factor is
defined. It is better if the scale value is a power of two. So, 256 is our
scale value.
I_ Gain = 0.00995 • 256 = 2.54 ≈ 3
P_Gain = 0.094609 • 256 = 24.22 ≈ 24
Once the controller parameters are calculated, it is possible to
implement them into the microcontroller.
The PI controller implementation is shown in Figure 5-1.
5.4 Speed Control Algorithm
The speed control algorithm consists of three main parts: the actual
speed calculation, the speed regulator by a PI controller, and a motor
stalled protection. This algorithm is executed by a timer overflow
interrupt handler each millisecond. The flowchart of this interrupt handler
is shown in Figure 5-2.
DRM007
76
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Speed Control Algorithm
PI_Controller
ControlDifference =
Reference_Speed Speed
NO
ControlDifference
>= 0
YES
Freescale Semiconductor, Inc...
ControlDifference = ControlDifference
P_Portion =
ControlDifference
* Kp
P_Portion = ControlDifference
* Kp
I_Portion =
ControlDifference
* Ki
I_Portion = ControlDifference
* Ki
I_PortionK_1 >
MAXINTEGRAL
NO
I_PortionK_1 <
MININTEGRAL
YES
YES
I_PortionK_1 =
MAXINTEGRAL
I_PortionK_1 =
MININTEGRAL
NO
I_PortionK_1 =
I_PortionK_1 +
P_Portion
Controller Output =
I_PortionK_1 +
P_Portion
End
Figure 5-1. PI Controller Flowchart
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
77
Freescale Semiconductor, Inc.
Software Design Considerations
TIMA_OV_ISR
1
newPWM =
(Controller Output
/ 256) + 128
Dif_Capture =
Actual_Capture Past_Capture
MotorStalled
Protection
Dif_Capture <
MINCAPTURE
YES
Speed =
MAXSPEED
NO
Freescale Semiconductor, Inc...
MilliCounter =
MilliCounter + 1
Dif_Capture >
MAXCAPTURE
YES
Speed =
MINSPEED
2
NO
MilliCounter > 10
NO
Speed = 1665 /
(Dif_Capture / 18)
End
YES
MilliCounter = 0
YES
Actual_Direction =
CCW
YES
Speed = -Speed
BLDCState =
BLDCWASH
NO
End of SPIN
Table
NO
PI_Controller
Controller
Output < 0
YES
Controller Output
= -Controller
Output
YES
NO
Speed Reference
= WASHTable
[index++]
Speed Reference
= SPINTable
[index++]
NO
NO
2
Required Direction
= CW
Required Direction
= CCW
Required
Direction =
CCW
YES
1
Speed Reference
= -Speed
Reference
Figure 5-2. Speed Control Algorithm Flowchart
DRM007
78
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Speed Control Algorithm
5.4.1 Motor Stalled Protection
The motor stalled protection subroutine is used for commutating the
motor windings if the motor hasn’t moved to a new angular position. If
the motor doesn’t change its angular position in a period of 250
milliseconds, the motor is completely stopped.
The motor stalled subroutine’s flowchart is the following:
Freescale Semiconductor, Inc...
Motor Stalled
Protection
Time_Out =
Time_Out + 1
Time_Out > 250
YES
Stop Motor
NO
(Time_Out % 8) = 0
YES
NextSequence
NO
End
Figure 5-3. Motor Stalled Protection Flowchart
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
79
Freescale Semiconductor, Inc.
Software Design Considerations
5.5 Commutation Algorithm
Freescale Semiconductor, Inc...
The commutation algorithm provides the generation of a rotational field
according to rotor position. This algorithm uses the Hall sensors to
obtain the rotor position. Outputs from the Hall sensors are connected to
three independent input-capture channels through an analog filter. The
timers are set to catch each input signal edge and call an interrupt
routine, which provides the commutation algorithm.
The Hall sensor consists of three sensors (sensor A, sensor B, and
sensor C). These sensors comprise six states (001, 010, 011, 100, 101,
and 110). Each state determines which motor phase the 3-phase
inverter should power. The interrupt routine reads the state of the Hall
sensors from the MCU port. This value is used as pointer to the
commutation table (see Table 5-1 and Table 5-2), which includes
information about the power MOSFETs gating. Figure 5-4 shows the
resultant voltage which is applied to a BLDC motor per one electrical
revolution.
Table 5-1. Commutation Sequence for Clockwise Rotation
Hall Sensor Inputs
Two MOSFET Scheme
Three MOSFET Scheme
Hall
Sensor A
Hall
Sensor B
Hall
Sensor C
Phase A
Phase B
Phase C
Phase A
Phase B
Phase C
1
1
0
+Vdc
NC
–Vdc
+Vdc
–Vdc
–Vdc
1
0
0
+Vdc
–Vdc
NC
+Vdc
–Vdc
+Vdc
1
0
1
NC
–Vdc
+Vdc
–Vdc
–Vdc
+Vdc
0
0
1
–Vdc
NC
+Vdc
–Vdc
+Vdc
+Vdc
0
1
1
–Vdc
+Vdc
NC
–Vdc
+Vdc
–Vdc
0
1
0
NC
+Vdc
–Vdc
+Vdc
+Vdc
–Vdc
DRM007
80
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Commutation Algorithm
Table 5-2. Commutation Sequence for Counterclockwise Rotation
Freescale Semiconductor, Inc...
Hall Sensor Inputs
Two MOSFET Scheme
Three MOSFET Scheme
Hall
Sensor A
Hall
Sensor B
Hall
Sensor C
Phase A
Phase B
Phase C
Phase A
Phase B
Phase C
1
0
1
NC
+Vdc
–Vdc
–Vdc
+Vdc
–Vdc
1
0
0
–Vdc
+Vdc
NC
–Vdc
+Vdc
+Vdc
1
1
0
–Vdc
NC
+Vdc
–Vdc
–Vdc
+Vdc
0
1
0
NC
–Vdc
+Vdc
+Vdc
–Vdc
+Vdc
0
1
1
+Vdc
–Vdc
NC
+Vdc
–Vdc
–Vdc
0
0
1
+Vdc
NC
–Vdc
+Vdc
+Vdc
–Vdc
Phase A
Phase B
Phase C
0°
60°
120°
180°
240°
300°
Note: Use black area for three MOSFET commutation scheme.
Figure 5-4. 3-Phase Voltage System Applies to BLDC Motor
The generation of the PWM voltage waveforms is done by the
complementary mode when using a three MOSFET commutation
scheme, and by loading 0 to the corresponding phases and configuring
the microcontroller to have a TOPNEG PWM when using a two
MOSFET commutation scheme. This is done because the
M68HC908MRx microcontrollers don’t have the PWM MASK option, so
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
81
Freescale Semiconductor, Inc.
Software Design Considerations
the complementary mode with a two MOSFET commutation scheme is
done by software. The deadtime is fixed to 2 microseconds for both
commutation schemes. This method allows independence of
commutation and speed control. See Figure 5-5.
Freescale Semiconductor, Inc...
Start of next sequence
Read new state of Hall
sensors
Look up new transistor states
from angular rotor position
Put new value to PWM
module
End
Figure 5-5. Commutation Algorithm for Hall Sensors
DRM007
82
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Data Flow
5.6 Data Flow
Freescale Semiconductor, Inc...
The control algorithm of a closed loop BLDC drive for washing machines
is described in Figure 5-6.
User's Menu
(LCD and push
buttons)
Period
Measurement
Washing Machine
Process
Desired Speed
Desired Speed
Speed Calculation
Position Sensors
(Hall Sensors)
Latests Position
Capture
Motor Direction
Speed Controller
(PI controller)
Angular Position
Actual Speed
MOSFET gating
selection
PWM State
PWM Generation
Figure 5-6. Main Data Flow
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
83
Freescale Semiconductor, Inc.
Software Design Considerations
5.6.1 Processes: Latest Position Capture, Period Measuring, and Speed Calculation
Freescale Semiconductor, Inc...
The latest position capture, period measuring, and speed calculation
processes relate to the inputs of the Hall sensors. The sensors generate
streams of pulses that are captured (separately for each sensor) by the
input capture (IC) function. The process latest position capture captures
the latest state of the Hall sensors.
The processes period measuring and speed calculation read the time
between the adjacent rising edges of Hall sensor output and calculate
the actual motor speed variable speed.
5.6.2 Process Speed Controller
This process calculates the duty cycle of the PWM based on the output
of the speed controller (the PI controller).
5.6.3 Process MOSFET Gating Selection
This process calculates which PWM channel is enabled for PWM
generation. Two commutation schemes are present here. In the file
main.h, a compiler directive allows the programmer to select between
the two MOSFET scheme and the three MOSFET scheme. For the
deadtime insertion there are things which should be noted.
If the three MOSFET commutation scheme is selected by the directive:
#define MOS_3_COM
#undef MOS_2_COM
The PWM module automatically makes deadtime insertion by
hardware.
If the two MOSFET commutation scheme is selected by the directive:
#undef MOS_3_COM
#define MOS_2_COM
Deadtime insertion is done by software and PWM module
configuration.
DRM007
84
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Data Flow
As an example, the algorithm for 50% of duty cycle on phase A and the
two MOSFET commutation scheme is:
•
In the microcontroller CONFIG register the PWM write once
register is configured as:
– Center aligned PWM
– Independent mode
Freescale Semiconductor, Inc...
– TOPNEG enabled
•
The required duty cycle is directly loaded into the PVAL register
for the TOP transistor.
•
The value loaded into the PVAL register for the BOT transistor is
calculated as:
#define DEADTIME 0x10
PMOD = 0x100;
PVAL1 = 0x80;
PVAL2 = PVAL1 – DEADTIME;
The output signal for one PWM cycle is shown in Figure 5-7.
SOFTWARE
DEADTIME
INSERTION
PWM1
TOP MOSFET
TOPNEG ENABLED
PWM2
BOTTOM MOSFET
BOTNEG DISABLED
1 CYCLE PWM
Note: The PWMMC is configured with independent mode
and center aligned operation
Figure 5-7. Software Deadtime Insertion
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
85
Freescale Semiconductor, Inc.
Software Design Considerations
5.6.4 Process Washing Machine
The process generates reference speeds, depending on the process
phase being executed of the washer. The user selects the washer
process by a user’s menu.
5.7 Application State Diagram
Freescale Semiconductor, Inc...
Reset
Initialization
Interrupts
Main Loop
(State Machine)
Figure 5-8. Application State Diagram
As Figure 5-8 shows, the application state consists of the initialization
routine, followed by a main loop with background tasks. The time critical
functions are calculated by the interrupt routines.
A brief description of the 3-phase BLDC motor control follows:
•
Initialization routine:
– PWM initialization
– System timer initialization
– Input capture initialization for position feedback
– Variable initialization for speed measurement
– Character display initialization
– I/O ports initialization
– PLL initialization
– MCU initialization
DRM007
86
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Application State Diagram
•
Main loop:
– Application state machine
– Check push buttons
– Display messages for user menu
– Display actual and desired motor speed
•
Initialize motor for running state:
– Load desired speed from look up table
Freescale Semiconductor, Inc...
– Charge bootstrap capacitors
– Resume timers for speed control
•
Timer A overflow interrupt handler:
– Speed calculation
– Speed PI controller calculation
– Setting of new duty cycle to PWM
– Motor stalled protection
– Load new desired speed from look up table depending on the
washer process being executed
•
Timer A Ch1, Timer B Ch0 and Ch1 interrupt handlers:
– Reading the angular motor position
– Spin direction calculation
– Selecting gating signals for MOSFETs
•
Timer B Ch1 interrupt handler
– Calculation of period between edges for one Hall effect sensor
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
87
Freescale Semiconductor, Inc.
Software Design Considerations
5.8 Drive State Machine
The drive can be one of the states shown in Figure 5-9 (which also
shows transition conditions among the drive states).
Generating Reference
Speed
Freescale Semiconductor, Inc...
Stop
Command
Stop Motor
Display Actual
and Reference
Speed
Stop
Command
WASH
command
Generating Ramp
Waiting for
command
SPIN CW
command
Ramp Finished
Fixed
Reference
Speed
Generating Ramp
Stop Motor
Motor
Stalled
Detection
SPIN CCW
command
Ramp Finished
From any
State
Figure 5-9. Drive State Machine and Transitions
DRM007
88
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Description of Routines
5.9 Description of Routines
The following subsections provide a description of each routine.
Freescale Semiconductor, Inc...
5.9.1 Main(void)
This routine contains the principal state machine of the application. It
includes initialization and user’s menu for selecting two different
processes of the washing machine: SPIN and WASH. It also includes
two additional options: STOP and Speed display, where the actual and
measured speeds are displayed in the LCD.
5.9.1.1 Stop Motor
The application arrives in this state by two different ways: first if there is
no Hall sensor changes for more than 250 milliseconds, and second if
the user selects the option STOP from the menu.
5.9.1.2 Waiting for Command
This is the idle state of the application. Only the LCD and the push
buttons are processed in this state. The UPPER button is used for
changing the message displayed; thus, the command to be executed,
and the LOWER button is used for executing the currently displayed
message command, except for the SPEED message, which displays the
actual and desired speed of the motor.
5.9.1.3 Displaying Actual and Reference Speed
In this state, the actual and reference speed are continuously displayed.
5.9.1.4 Wash
When the user selects the WASH process from the user’s menu, the
application starts running the motor. First an initialization routine is called
for charging bootstrap capacitors, resume timers for speed control, and
the first reference speed for the Wash process look up table is loaded
into variable RefSpeed. Once the motor is running, a timer overflow
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
89
Freescale Semiconductor, Inc.
Software Design Considerations
interrupt handler is used for the speed control and continuous generation
of reference speeds, including positive and negative values, so the
agitator moves in both directions of rotation.
Freescale Semiconductor, Inc...
5.9.1.5 Spin CW and Spin CCW
When the Spin process is selected in either direction, the motor
initialization is called, and then an acceleration ramp is loaded from a
Spin look up table, and the sign of the reference speed is set according
to the direction of rotation selected.
5.9.1.6 Fixed Reference Speed
When the acceleration ramp table of the Spin process is fully loaded, the
reference speed remains constant.
5.9.2 InitPLL(void)
This function is called once in the application. It sets the bus frequency
to 8 MHz with an external crystal of 4 MHz.
5.9.3 InitPWMMC(void)
This function initializes the PWM module for motor control with the
following settings:
•
PWM frequency of 15.625 kHz
•
Two microseconds of deadtime
•
Reload every PWM cycle
5.9.4 InitTimerA(void)
Timer A and timer A channel 1 are initialized for speed control and
commutation control. The overflow interrupt is enabled for speed control
each millisecond. Channel 1 is configured as an input capture channel
with interrupt enabled on any edge. This channel is connected to Hall
sensor A.
DRM007
90
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Description of Routines
5.9.5 InitTimerB(void)
Timer B channel 0 and channel 1 are configured as input capture
channels with interrupts enabled on any edge. Channel 0 is connected
to Hall sensor B and channel 1 to Hall sensor C. These two channels are
used also for commutation control. Channel 1 is used for period
calculation between two Hall sensor edges.
Freescale Semiconductor, Inc...
5.9.6 Byte ResolveButtons(void)
The state of the input pins, where the push buttons are continuously
checked for any change, are tested here. A debounce delay is included
in the routine. If there is no change on the push buttons, and the Speed
message is being displayed, the respective value of the actual speed
and reference speed are displayed in this routine.
5.9.7 InitMotor(Byte Commanded_Operation)
This subroutine is called from main to perform one of the two of the
washing machine processes. The process is selected by the parameter
value, Commanded_Operation.
Parameters:
BLDCWASH — Wash process of the washing machine.
BLDCSPIN — Spin process
Depending on the process selected from the user’s menu, the Speed
reference is loaded from the respective look up table. The speed
controller integral portion is set to 0, the bootstrap capacitors are
charged and the timers are resumed.
5.9.8 TimerAOverflow_ISR(void)
Refer to 5.4 Speed Control Algorithm.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
91
Freescale Semiconductor, Inc.
Software Design Considerations
5.9.9 Signed Word 16 PIController(void)
Refer to 5.3 Controller Design.
5.9.10 MotorStalledProtection(void)
Refer to 5.4.1 Motor Stalled Protection.
Freescale Semiconductor, Inc...
5.9.11 HALLA_ISR(void) and HALLB_ISR(void)
Interrupt handler routines to drive Hall sensors A and B for BLDC motor
commutation. Direction is computed from the last Hall sensor input state.
5.9.12 HALLC_ISR(void)
Interrupt handler routines to drive Hall sensor C for BLDC motor
commutation. Direction is computed from the last Hall Sensor input
state. In this routine, the period between edges is measured for speed
calculation.
5.9.13 Fault1_ISR(void)
Interrupt handler subroutine for Fault1. The motor is stopped when a
FAULT occurs. The FAULT is asserted when the current limit or voltage
limit has been reached by the power stage.
5.9.14 NextSequence(void)
In this routine, the MOSFET selection is performed based on the
commutation scheme and the Required_Direction of the motor. Refer to
5.5 Commutation Algorithm.
DRM007
92
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
Description of Routines
5.9.15 InitLCD(void)
Freescale Semiconductor, Inc...
This function initializes the character display with these settings:
•
4-bit operation mode
•
2-line display
•
No display shift and move right
•
Clear display and return to home position
•
Display on, blink off, and cursor off
5.9.16 CtrlLCD(Byte ctrl)
This subroutine is used for sending control bytes to the LCD. Because
the function is called in 4-bit operation mode, this routine sends the 8-bit
value in two parts.
Parameters:
ctrl — An 8-bit value for different control of the LCD, such as
number of lines, blink on or off, etc.
5.9.17 Ctrl8LCD(Byte ctrl)
This subroutine is used for sending control bytes to the LCD in 8-bit
mode. The function is used only to enter 4-bit mode, since the other four
data pins have no connection.
Parameters:
ctrl — An 8-bit value for different control of the LCD, such as
number of lines, blink on or off, etc.
5.9.18 MovCursorLCD(Byte places, Byte dir)
Function used to move the LCD cursor to right or left the number of
desired places.
Parameters:
places — Number of places wanted to move the LCD cursor
without affecting any LCD actual message.
dir — Direction in which the cursor is to be moved, right or left.
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
93
Freescale Semiconductor, Inc.
Software Design Considerations
5.9.19 DataLCD(Byte data)
ASCII symbol to be displayed on the LCD, at the current cursor position.
Parameters:
data — 8-bit value representing the ASCII code of the symbol to
be displayed in the LCD at current position.
Freescale Semiconductor, Inc...
5.9.20 StringLCD(Byte *msgLCD)
This function displays a string in the LCD at current cursor position. If a
'&' character is present in the string, a new line feed is commanded to
the LCD. The function sends all the bytes in the string until a presence
of an End Of String, EOS or 0x00 byte.
Parameters:
*msgLCD — Pointer to the string to be displayed on the LCD.
5.9.21 WaitMs(Byte milis)
Delay routine that waits for a number of milliseconds to send in the
parameter milis. The delay is calculated for an 8 MHz fBUS operation.
Parameters:
milis — An 8-bit value representing the number of milliseconds the
delay will take.
5.9.22 Wait40µs(void)
Fixed delay of 40 microseconds.
DRM007
94
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Design Considerations
MCU Usage
5.10 MCU Usage
Table 5-3 shows how much memory is needed to run the 3-phase BLDC
motor drive in a speed closed loop using Hall sensors, washing machine
functions, and user’s interface. A part of the MCU memory is still
available for other tasks.
Table 5-3. RAM and FLASH Memory Usage
Freescale Semiconductor, Inc...
Memory
(In 8-Bit Words)
Available
(MC68HC908MR8)
Used
(Application + Stack)
Program FLASH
7680
2820
Data RAM
256
36 + 96
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
DRM007
95
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software Design Considerations
DRM007
96
BLDC Motor Control Board for Industrial and Appliance Applications
Software Design Considerations
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — BLDC Motor Control Board
Figure 6-1 shows the motor power output versus the motor torque with
drives for the two commutation schemes developed in the reference
design — consisting of switching two MOSFETs at each angular position
or three MOSFETs at each angular position.
Pow er Output Vs Torque
500.00
450.00
400.00
Power Output (Watts)
350.00
300.00
Tw o-MOSFETs Scheme
250.00
Three-MOSFETs Scheme
200.00
150.00
100.00
50.00
24
.6
5
27
.9
3
18
.2
0
21
.4
9
15
.2
8
11
.7
6
9.
43
7.
82
6.
08
4.
34
2.
54
0.00
0.
93
Freescale Semiconductor, Inc...
Section 6. Practical Results
Torque (lb-in)
Figure 6-1. Power Output versus Torque Motor Characteristic
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Practical Results
For More Information On This Product,
Go to: www.freescale.com
DRM007
97
Freescale Semiconductor, Inc.
Practical Results
Figure 6-2 shows the motor torque output versus motor maximum
speed for the two commutation algorithms developed in the reference
design.
Speed Vs Torque
4000
Freescale Semiconductor, Inc...
3500
Speed (RPM)
3000
2500
Tw o-MOSFETs Scheme
2000
Three-MOSFETs Scheme
1500
1000
500
27
.9
3
24
.6
5
21
.4
9
18
.2
0
15
.2
8
11
.7
6
9.
43
7.
82
6.
08
4.
34
2.
54
0.
93
0
Torque (lb-in)
Figure 6-2. Speed versus Torque Motor Characteristic
Current waveforms are shown in the two oscilograms:
NOTE:
DRM007
98
•
Figure 6-3 for the commutation scheme switching two MOSFETs
at a time
•
Figure 6-4 for the commutation scheme switching three
MOSFETs at a time
There is less torque ripple, which is dependent on the current, for the
commutation algorithm switching three MOSFETs.
BLDC Motor Control Board for Industrial and Appliance Applications
Practical Results
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Practical Results
Figure 6-3. Current Waveform for Two MOSFET Commutation Scheme
Figure 6-4. Current Waveform for Three MOSFET Commutation Scheme
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Practical Results
For More Information On This Product,
Go to: www.freescale.com
DRM007
99
Freescale Semiconductor, Inc.
Practical Results
Taking the rectified current of the three-phase inverter, the torque ripple
in the motor can be seen assuming that torque is proportional to current.
This is shown in Figure 6-5 and Figure 6-6 for the two MOSFET
commutation scheme and the three MOSFET commutation scheme,
respectively.
Freescale Semiconductor, Inc...
12
11
10
9
8
7
6
5
4
3
2
1
0
Figure 6-5. Torque Waveform for Two MOSFET
Commutation Scheme
10
9
8
7
6
5
4
3
2
1
0
Figure 6-6. Torque Waveform for Three MOSFET
Commutation Scheme
DRM007
100
BLDC Motor Control Board for Industrial and Appliance Applications
Practical Results
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Practical Results
The speed control algorithm results are listed in Table 6-1 for this
reference design. This data includes:
•
Steady-state error of the controller for different speeds
•
Minimum and maximum controllable speed ranges
Freescale Semiconductor, Inc...
Table 6-1. Speed Results
Full Load
(13.4 lb-in)
Full Load
(13.4 lb-in)
No Load
No Load
Maximum Speed
(RPM)
Minimum Speed
(RPM)
Maximum Speed
(RPM)
Minimum Speed
(RPM)
3 MOSFET
2189.7 (–31.3, +62.6)
218.9 (± 31.3)
3440.9 (–187.7, +31.3)
218.9 (± 31.3)
2 MOSFET
2033.3 (± 31.3)
218.9 (± 31.3)
2658.9 (± 62.6)
218.9 (± 31.3)
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Practical Results
For More Information On This Product,
Go to: www.freescale.com
DRM007
101
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Practical Results
DRM007
102
BLDC Motor Control Board for Industrial and Appliance Applications
Practical Results
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — Remote Keyless Access
Section 7. Source Code
7.1 Contents
Freescale Semiconductor, Inc...
7.2
Include Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.2.1
MR8IO.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.2.2
START08.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.2.3
MAIN.H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.2.4
TIMER.H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.2.5
LCD.H. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
7.2.6
TABLES.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
7.3
Source Code Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.3.1
START08.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.3.2
MAIN.C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
7.3.3
TIMER.C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
7.3.4
LCD.C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
103
Freescale Semiconductor, Inc.
Source Code
7.2 Include Files
Freescale Semiconductor, Inc...
7.2.1 MR8IO.H
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* --------------------------------------------------------------------------- *
* File name :
mr8io.h
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* --------------------------------------------------------------------------- *
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
All the MCU registers and some bit mask values are declared
*
*
in this document as defines to interface with most of the
*
*
microcontroller registers and peripherals
*
\*****************************************************************************/
/*
*/
#define
#define
#define
#define
#define
#define
PORTS section
/*
*/
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
A TIMER section
DRM007
104
PORTA
PORTB
PORTC
DDRA
DDRB
DDRC
TASC
TACNT
TACNTH
TACNTL
TAMOD
TAMODH
TAMODL
TASC0
TACH0
TACH0H
TACH0L
TASC1
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
char*)(0x00))
char*)(0x01))
char*)(0x02))
char*)(0x04))
char*)(0x05))
char*)(0x06))
/*
/*
/*
/*
/*
/*
port
port
port
data
data
data
char*)(0x0E))
int*)(0x0F))
char*)(0x0F)
char*)(0x10))
int*)(0x11))
char*)(0x11))
char*)(0x12))
char*)(0x13))
int*)(0x14))
char*)(0x14))
char*)(0x15))
char*)(0x16))
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
A */
B */
C */
direction port A */
direction port B */
direction port C */
A
A
A
A
A
A
A
A
A
A
A
A
status/ctrl register */
counter register */
counter high */
counter low */
modulo register */
modulo high */
modulo low */
channel 0 status/ctrl */
channel 0 register */
channel 0 high */
channel 0 low */
channel 1 status/ctrl */
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Include Files
#define TACH1
#define TACH1H
#define TACH1L
(*(volatile int*)(0x17))
(*(volatile char*)(0x17))
(*(volatile char*)(0x18))
Freescale Semiconductor, Inc...
/*
OPTION section
*/
#define MOR
(*(volatile char*)(0x1F))
ter */
/* timer A channel 1 register */
/* timer A channel 1 high */
/* timer A channel 1 low */
/* CONFIG Configuration Write-Once Regis-
/*
PWM section
*/
#define PCTL1
(*(volatile char*)(0x20))
#define PCTL2
(*(volatile char*)(0x21))
/* PWM control register 1 */
/* PWM control register 2 */
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
FCR
FSR
FTAC
PWMOUT
PCNT
PCNTH
PCNTL
PMOD
PMODH
PMODL
PVAL1
PVAL1H
PVAL1L
PVAL2
PVAL2H
PVAL2L
PVAL3
PVAL3H
PVAL3L
PVAL4
PVAL4H
PVAL4L
PVAL5
PVAL5H
PVAL5L
PVAL6
PVAL6H
PVAL6L
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
char*)(0x22))
char*)(0x23))
char*)(0x24))
char*)(0x25))
int*)(0x26))
char*)(0x26))
char*)(0x27))
int*)(0x28))
char*)(0x28))
char*)(0x29))
int*)(0x2a))
char*)(0x2a))
char*)(0x2b))
int*)(0x2c))
char*)(0x2c))
char*)(0x2d))
int*)(0x2e))
char*)(0x2e))
char*)(0x2f))
int*)(0x30))
char*)(0x30))
char*)(0x31))
int*)(0x32))
char*)(0x32))
char*)(0x33))
int*)(0x34))
char*)(0x34))
char*)(0x35))
Fault control register */
Fault Status register */
Fault acknowledge register */
PWM output control register */
PWM counter register */
PWM counter register high */
PWM counter register low */
PWM counter Modulo register */
PWM counter Modulo reg. high */
PWM counter Modulo reg. low */
PWM 1 value register */
PWM 1 value register high */
PWM 1 value register low */
PWM 2 value register */
PWM 2 value register high */
PWM 2 value register low */
PWM 3 value register */
PWM 3 value register high */
PWM 3 value register low */
PWM 4 value register */
PWM 4 value register high */
PWM 4 value register low */
PWM 5 value register */
PWM 5 value register high */
PWM 5 value register low */
PWM 6 value register */
PWM 6 value register high */
PWM 6 value register low */
#define DEADTM (*(volatile char*)(0x36)) /* Dead Time Write-once register */
#define DISMAP (*(volatile char*)(0x37)) /* PWM Disable Mapping Write-once register
*/
/*
*/
#define
#define
#define
SCI section
SCC1
SCC2
SCC3
(*(volatile char*)(0x38))
(*(volatile char*)(0x39))
(*(volatile char*)(0x3A))
/* SCI control register 1 */
/* SCI control register 2 */
/* SCI control register 3 */
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
105
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Source Code
#define
#define
#define
#define
SCS1
SCS2
SCDR
SCBR
(*(volatile
(*(volatile
(*(volatile
(*(volatile
/*
*/
#define
/*
*/
#define
#define
#define
#define
#define
INTERRUPT section
/*
*/
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
B TIMER section
/*
*/
#define
#define
#define
PLL section
/*
*/
#define
#define
#define
#define
SIM section
char*)(0x3B))
char*)(0x3C))
char*)(0x3D))
char*)(0x3E))
/*
/*
/*
/*
SCI
SCI
SCI
SCI
status register 1 */
status register 2 */
data register */
baud rate */
ISCR
(*(volatile char*)(0x3F))
A/D section
/* IRQ status/control register */
ADSCR
ADR
ADRH
ADRL
ADCLK
char*)(0x40))
int*)(0x41))
char*)(0x41))
char*)(0x42))
char*)(0x43))
/*
/*
/*
/*
/*
ADC
ADC
ADC
ADC
ADC
char*)(0x51))
int*)(0x52))
char*)(0x52))
char*)(0x53))
int*)(0x54))
char*)(0x54))
char*)(0x55))
char*)(0x56))
int*)(0x57))
char*)(0x57))
char*)(0x58))
char*)(0x59))
int*)(0x5A))
char*)(0x5A))
char*)(0x5B))
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
timer
TBSC
TBCNT
TBCNTH
TBCNTL
TBMOD
TBMODH
TBMODL
TBSC0
TBCH0
TBCH0H
TBCH0L
TBSC1
TBCH1
TBCH1H
TBCH1L
PCTL
PBWC
PPG
SBSR
SRSR
SBFCR
FLCR
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile char*)(0x5C))
(*(volatile char*)(0x5D))
(*(volatile char*)(0x5E))
(*(volatile
(*(volatile
(*(volatile
(*(volatile
status and control reg. */
data register */
data register high */
data register low */
clock register */
B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
status/ctrl register */
counter register */
counter high */
counter low */
modulo register */
modulo high */
modulo low */
channel 0 status/ctrl */
channel 0 register */
channel 0 high */
channel 0 low */
channel 1 status/ctrl */
channel 1 register */
channel 1 high */
channel 1 low */
/* PLL control register */
/* PLL bandwidth register */
/* PLL programming register */
char*)(0xFE00))/*
char*)(0xFE01))/*
char*)(0xFE03))/*
char*)(0xFE08))/*
SIM break status register */
SIM reset status register */
SIM break control register */
FLASH control register */
#define LVISCR (*(volatile char*)(0xFE0F)) /* LVI status/control register */
#define FLBPR (*(volatile char*)(0xFF7E)) /* FLASH block protect register */
#define COPCTL (*(volatile char*)(0xFFFF)) /* COP control register */
DRM007
106
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Include Files
Freescale Semiconductor, Inc...
/*
*/
#define
#define
#define
#define
#define
/*
*/
#define
#define
#define
#define
/*
*/
#define
/*
*/
*/
#define
#define
#define
#define
#define
/*
*/
#define
#define
#define
#define
#define
#define
ADC Flags and bit masks
ATD8_PTC0
Continuous_Conversion 0x20
ADC_Input_Clock_by_8 0x60
Internal_Bus_Clock
0x10
COCO
0x06
0x80
PLL Flags and bit masks
BCS
0x10
PLLON 0x20
AUTO
0x80
LOCK
0x40
IRQ Flags and bit masks
IMASK
0x02
PWM Flags and bit masks
PWMEN
LDOK
PWMINT
PWMF
FTACK1
0x01
0x02
0x20
0x10
0x01
TIM Flags and bit masks
TRST
TSTOP
TOIE
CHIE
TOF
CHF
0x10
0x20
0x40
0x40
0x80
0x80
/*****************************************************************************\
* End mr8io.h
*
******************************************************************************/
;
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
107
Freescale Semiconductor, Inc.
Source Code
7.2.2 START08.H
;
/******************************************************************************
FILE
: start08.h
PURPOSE : datastructures for startup
LANGUAGE: ANSI-C
*/
/*****************************************************************************/
Freescale Semiconductor, Inc...
#ifndef START08_H
#define START08_H
#ifdef __cplusplus
extern "C" {
#endif
#include "hidef.h"
/*
the following datastructures contain the data needed to
initialize the processor and memory
*/
typedef struct{
unsigned char *_FAR beg;
int size;
/* [beg..beg+size] */
} _Range;
typedef struct _Copy{
int size;
unsigned char *_FAR dest;
} _Copy;
typedef void (*_PFunc)(void);
typedef struct _LibInit{
_PFunc *startup;
/* address of startup desc */
} _LibInit;
typedef struct _Cpp{
_PFunc initFunc;
} _Cpp;
/* address of init function */
#define STARTUP_FLAGS_NONE
#define STARTUP_FLAGS_ROM_LIB
#define STARTUP_FLAGS_NOT_INIT_SP
ized */
DRM007
108
0
(1<<0) /* if module is a ROM library */
(1<<1) /* if stack pointer has not to be initial-
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Include Files
#pragma DATA_SEG FAR _STARTUP
#ifdef __ELF_OBJECT_FILE_FORMAT__
/* ELF/DWARF object file format */
Freescale Semiconductor, Inc...
/* attention: the linker scans the debug information for this structures */
/* to obtain the available fields and their sizes. */
/* So dont change the names in this file. */
extern struct _tagStartup {
unsigned char
flags;
/* STARTUP_FLAGS_xxx */
_PFunc
main;
/* top level procedure of user program */
#ifndef __NO_STACK_OFFSET
unsigned short stackOffset;
/* initial value of the stack pointer */
#endif
unsigned short nofZeroOuts;
/* number of zero out ranges */
_Range
*_FAR pZeroOut; /* vector of ranges with nofZeroOuts elements */
_Copy
*_FAR toCopyDownBeg; /* rom-address where copydown-data begins
*/
#if 0 /* switch on to implement ROM libraries */
unsigned short nofLibInits;
/* number of library startup descriptors */
_LibInit
*_FAR libInits; /* vector of pointers to library startup
descriptors */
#endif
#if defined(__cplusplus)
unsigned short nofInitBodies;
/* number of init functions for C++ constructors
*/
_Cpp
*_FAR initBodies; /* vector of function pointers to init functions for
C++ constructors */
#endif
} _startupData;
#else
extern struct _tagStartup{
unsigned
flags;
_PFunc
main;
unsigned
dataPage;
long
stackOffset;
int
nofZeroOuts;
_Range
*_FAR pZeroOut;
roOuts elements */
long
toCopyDownBeg;
_PFunc
*_FAR mInits;
minated by 0 */
_PFunc
*_FAR libInits;
terminated by 0x0000FFFF */
} _startupData;
/* top procedure of user program */
/* page where data allocation begins */
/* pZeroOut is a vector of ranges with nofZe/* rom-address where copydown-data begins */
/* mInits is a vector of function pointers, ter/* libInits is a vector of function pointers,
#endif
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
109
Freescale Semiconductor, Inc.
Source Code
#pragma DATA_SEG DEFAULT
extern void _Startup(void);
/* execution begins in this procedure */
/*--------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
Freescale Semiconductor, Inc...
#endif
;
7.2.3 MAIN.H
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* ----------------------------------------------------------------------------*
* File name :
main.h
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* ----------------------------------------------------------------------------*
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
File subroutines and State Flags values are defined in this *
*
document. Macro definition and new type definition where
*
*
added here
*
\*****************************************************************************/
#define MOS_2_COM
#undef MOS_3_COM
// New Data type definitions
typedef unsigned short int UINT16;
// 16 bit unsigned integer
(0, 65535)
typedef signed short int
SINT16;
// 16 bit signed integer (-32768, 32767)
typedef unsigned char
UBYTE; // 8 bit unsigned byte (0, 255)
typedef signed char
SBYTE; // 8 bit signed byte
(-128, 127)
// Function Headers
UBYTE ResolveButtons(void);
// Macro Definitions
#define Forever()
#define EnableInterrupts()
#define DisableInterrupts()
DRM007
110
while(1)
{__asm CLI;}
{__asm SEI;}
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Include Files
#define DebounceDelay()
#define WaitUntilUpButtonIsReleased()
WaitMs(30)
while((PORTB & OPTIONS_BUTTON) == 0x00)
// General Boolean defines
#define TRUE 1
#define FALSE 0
Freescale Semiconductor, Inc...
// Buttons Definition
#define OPTIONS_BUTTON
#define ENTER_BUTTON
0x08
0x04
// MCU Configuration
#define EDGE_ALIGNED
#define CENTER_ALIGNED
#define INDEPENDENT_PWMS
#define COMPLEMENTARY_MODE
#define COP_DISABLE
#define TOPNEG
#define FAULT_1_AUTOMATIC
#define FAULT_1_MANUAL
#define FAULT_1_INT
0x80
0x00
0x10
0x00
0x01
0x20
0x01
0x00
0x02
/*****************************************************************************\
* End main.h
*
******************************************************************************/
;
7.2.4 TIMER.H
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* ----------------------------------------------------------------------------*
* File name :
timer.h
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* ----------------------------------------------------------------------------*
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
File subroutines and State Flags values are defined in this
*
*
document. Also Macro definitions are placed here.
*
\*****************************************************************************/
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
111
Freescale Semiconductor, Inc.
Source Code
Freescale Semiconductor, Inc...
// Function Headers
void InitTimerA(void);
void InitTimerB(void);
void StopMotor(void);
void WaitMs(UBYTE number_of_miliseconds);
void InitPWMMC(void);
void InitPLL(void);
void NextSequence(void);
SINT16 PIController (void);
void MotorStalledProtection(void);
void InitMotor(UBYTE commanded_operation);
// Macro Definitions
#define HallSensorInputs()
#define TurnOffAllPWMOutputs()
#define Turn_On_Low_Side_MOSFETs()
#define ResumeTimerA()
#define ResumeTimerB()
#define Reset_TimerA()
#define Reset_TimerB()
// Timer Flags
#define Prescaler_by_1
#define Prescaler_by_2
#define Prescaler_by_4
#define Prescaler_by_8
#define Prescaler_by_16
#define Prescaler_by_32
#define Prescaler_by_64
#define _1milli
#define _100milis
#define IC_any_Edge
#define Port_Control
#define MAXPERIOD
#define MINPERIOD
#define MAXSPEED
#define MINSPEED
#define MAXINTEGRAL
#define MININTEGRAL
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x007D
0xC350
0x0C
0x00
4605
237
126
7
25000
-25000
// Brushless Status and
#define HALL_A
#define HALL_B
#define HALL_C
#define CW
#define CCW
#define BLDCSTOP
#define BLDCSPIN
#define BLDCWASH
#define WASHTABLEPOINTS
#define SPINTABLEPOINTS
Control
0x10
0x20
0x40
0
1
0
1
2
256
256
DRM007
112
(PORTB & 0x70)
(PWMOUT = 0x40)
(PWMOUT = 0x6A)
(TASC &= ~TSTOP)
(TBSC &= ~TSTOP)
(TASC |= TRST)
(TBSC |= TRST)
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Source Code
Include Files
#define NO_FAULT
#define MOTOR_STALLED
#define FAULT_OCCURRED
0x00
0x01
0x02
// PWM Module
#define _15_625KHz
#define ZEROPWM
#define DEADTIME
#define PWMOFF
#define PWMFREQ
#define PWMON
#define RELOAD_1
#define RELOAD_2
#define RELOAD_4
#define RELOAD_8
0x100
0x80
0x10
0x0000
_15_625KHz
PWMFREQ
0x00
0x40
0x80
0xC0
/*****************************************************************************\
* End timer.h
*
******************************************************************************/
;
7.2.5 LCD.H
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* ----------------------------------------------------------------------------*
* File name :
lcd.h
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* ----------------------------------------------------------------------------*
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
The functions prototypes and some usefull #defines where
*
*
placed in this document for a better understanding of LCD
*
*
interface
*
\*****************************************************************************/
// Function Declaration Headers
void WaitMs(UBYTE number_of_miliseconds);
void Wait40us(void);
void InitLCD(void);
void DataLCD(UBYTE data_to_be_displayed);
void StringLCD(UBYTE *pointer_to_string);
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
113
Freescale Semiconductor, Inc.
Source Code
void CtrlLCD(UBYTE control_byte);
void Ctrl8LCD(UBYTE control_byte);
void MovCursorLCD(UBYTE number_of_places, UBYTE direction);
Freescale Semiconductor, Inc...
// Macro Definitions
#define Set_E()
#define Clear_E()
#define Set_RS()
#define Clear_RS()
(PORTB
(PORTB
(PORTC
(PORTC
|=
&=
|=
&=
E)
~E)
RS)
~RS)
#define EnableInterrupts()
{__asm CLI;}
// General Defines
#define CLEARLCD
#define MOVECURSORCOMMAND
#define MAXLCDMSGS
#define RIGHT
#define LEFT
#define EOS
#define EOL
#define First_Column
0x01
0x10
5
0x04
0x00
0
'&'
16
// Control Pins
#define RS
#define E
0x02
0x04
// LCD States
#define BLDC_WASH
#define BLDC_SPINCW
#define BLDC_SPINCCW
#define SPEED
#define BLDC_STOP
0
1
2
3
4
/*****************************************************************************\
* End lcd.h
*
******************************************************************************/
;
DRM007
114
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Include Files
7.2.6 TABLES.H
Freescale Semiconductor, Inc...
;
/* Table used for WASH process of the washing machine */
const SBYTE WASHTable[WASHTABLEPOINTS] =
{14,15,16,18,19,20,22,23,24,25,27,28,29,30,32,33,34,35,36,37,38,40,41,42,43,44,
45,46,47,48,48,49,50,51,52,53,53,54,55,56,56,57,58,58,59,59,60,60,61,61,61,62,
62,62,63,63,63,63,64,64,64,64,64,64,64,64,64,64,64,63,63,63,63,63,62,62,62,61,
61,60,60,59,59,58,58,57,56,56,55,54,54,53,52,51,50,50,49,48,47,46,45,44,43,42,
41,40,39,38,37,35,34,33,32,31,29,28,27,26,24,23,22,21,19,18,17,15,14,13,-13,
-15,-16,-17,-19,-20,-21,-22,-24,-25,-26,-28,-29,-30,-31,-32,-34,-35,-36,-37,
-38,-39,-40,-41,-42,-43,-44,-45,-46,-47,-48,-49,-50,-51,-52,-52,-53,-54,-55,
-55,-56,-57,-57,-58,-59,-59,-60,-60,-61,-61,-61,-62,-62,-62,-63,-63,-63,-63,
-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-63,-63,-63,-63,-62,-62,-62,
-61,-61,-60,-60,-59,-59,-58,-58,-57,-57,-56,-55,-55,-54,-53,-52,-52,-51,-50,
-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-33,-32,-31,-30,
-29,-27,-26,-25,-24,-22,-21,-20,-18,-17,-16,-14,-13};
/* table used for SPIN process of washing machine */
const SBYTE SPINTable[SPINTABLEPOINTS] =
{14,15,15,15,16,16,16,16,17,17,17,18,18,18,19,19,19,19,20,20,20,21,21,21,22,22,
22,23,23,23,23,24,24,24,25,25,25,26,26,26,26,27,27,27,28,28,28,28,29,29,29,30,
30,30,30,31,31,31,32,32,32,32,33,33,33,34,34,34,34,35,35,35,36,36,36,36,37,37,
37,37,38,38,38,39,39,39,39,40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,44,
44,44,44,45,45,45,45,46,46,46,46,47,47,47,47,47,48,48,48,48,49,49,49,49,49,50,
50,50,50,51,51,51,51,51,52,52,52,52,52,53,53,53,53,53,53,54,54,54,54,54,55,55,
55,55,55,55,56,56,56,56,56,56,57,57,57,57,57,57,58,58,58,58,58,58,58,59,59,59,
59,59,59,59,59,60,60,60,60,60,60,60,60,61,61,61,61,61,61,61,61,61,61,62,62,62,
62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,64,
64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64 };
;
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
115
Freescale Semiconductor, Inc.
Source Code
7.3 Source Code Files
Freescale Semiconductor, Inc...
7.3.1 START08.C
;
/******************************************************************************
FILE
: start08.c
PURPOSE
: 68HC08 standard startup code
LANGUAGE
: ANSI-C / INLINE ASSEMBLER
---------------------------------------------------------------------------HISTORY
22 oct 93
Created.
04/17/97
Also C++ constructors called in Init().
******************************************************************************/
#include "start08.h"
/**********************************************************************/
struct _tagStartup _startupData;
/* read-only:
_startupData is allocated in ROM and
initialized by the linker */
#define USE_C_IMPL 0 /* for now, we are using the inline assembler implementation for
the startup code */
#if !USE_C_IMPL
#pragma MESSAGE DISABLE C20001 /* Warning C20001: Different value of stackpointer
depending on control-flow */
/* the function _COPY_L releases some bytes from the stack internally */
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
static void near loadByte(void) {
asm {
PSHH
PSHX
LDA
5,SP
PSHA
LDX
7,SP
PULH
LDA
0,X
AIX
#1
STX
6,SP
PSHH
PULX
STX
5,SP
PULX
DRM007
116
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
PULH
RTS
}
}
Freescale Semiconductor, Inc...
#endif
extern void
/* DESC:
incl.)
IN:
OUT:
WRITTEN:
_COPY_L(void);
copy very large structures (>= 256 bytes) in 16 bit address space (stack
TOS count, TOS(2) @dest, H:X @src
X,H */
#ifdef __ELF_OBJECT_FILE_FORMAT__
#define toCopyDownBegOffs 0
#else
#define toCopyDownBegOffs 2 /* for the hiware format, the toCopyDownBeg field is a
long. Because the HC08 is big endian, we have to use an offset of 2 */
#endif
static void Init(void) {
/* purpose:
1) zero out RAM-areas where data is allocated
2) init run-time data
3) copy initialization data from ROM to RAM
*/
unsigned int i;
int *p;
#if USE_C_IMPL
/* C implementation of ZERO OUT and COPY Down */
int j;
char *dst;
_Range *r;
r = _startupData.pZeroOut;
/* zero out */
for (i=0; i != _startupData.nofZeroOuts; i++) {
dst = r->beg;
j = r->size;
do {
*dst = 0; /* zero out */
dst++;
j--;
} while(j != 0);
r++;
}
#else /* faster and smaller asm implementation for ZERO OUT */
asm {
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
117
Freescale Semiconductor, Inc.
Source Code
ZeroOut:
;
LDA
INCA
STA
LDA
INCA
STA
LDHX
BRA
Zero_3:
;
Zero_4:
;
Freescale Semiconductor, Inc...
; CLR
_startupData.nofZeroOuts:1 ; nofZeroOuts
i:1
; i is counter for number of zero outs
_startupData.nofZeroOuts:0 ; nofZeroOuts
i:0
_startupData.pZeroOut
Zero_5
; *pZeroOut
i:1 is already 0
; { HX == _pZeroOut }
PSHX
PSHH
; { nof bytes in (int)2,X }
; { address in (int)0,X
}
LDA
0,X
PSHA
LDA
2,X
INCA
STA
p
; p:0 is used for high byte of byte counter
LDA
3,X
LDX
1,X
PULH
INCA
BRA
Zero_0
Zero_1:
Zero_2:
Zero_0:
;
;
;
CLRA
A is already 0, so we don't have to clear it
CLR
AIX
0,X
#1
DBNZA
Zero_2
DBNZ
PULH
PULX
AIX
p, Zero_1
DBNZ
DBNZ
;
;
i:1, Zero_4
i:0, Zero_3
;
Zero_6:
Zero_5:
CopyDown:
; restore *pZeroOut
; advance *pZeroOut
#4
;
}
#endif
/* copy down */
DRM007
118
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Source Code
Source Code Files
/* _startupData.toCopyDownBeg ---> {nof(16) dstAddr(16) {bytes(8)}^nof} Zero(16)
*/
#if USE_C_IMPL /* (optimized) C implementation of COPY DOWN */
p = (int*)_startupData.toCopyDownBeg;
for (;;) {
i = *p; /* nof */
if (i == 0) {
break;
}
dst = (char*)p[1]; /* dstAddr */
p+=2;
do {
/* p points now into 'bytes' */
*dst = *((char*)p); /* copy byte-wise */
((char*)p)++;
dst++;
i--;
} while (i!= 0);
}
#elif defined(__OPTIMIZE_FOR_SIZE__)
{
asm {
LDA
PSHA
LDA
PSHA
_startupData.toCopyDownBeg:(1+toCopyDownBegOffs)
JSR
TAX
INCA
STA
JSR
INCA
STA
DECA
BNE
CBEQX
loadByte
JSR
PSHA
PULH
JSR
TAX
BRA
loadByte
; load high byte ptr
loadByte
; load high byte ptr
; HX is now destination pointer
JSR
STA
AIX
loadByte
0,X
#1
_startupData.toCopyDownBeg:(0+toCopyDownBegOffs)
Loop0:
i
loadByte
; load high byte counter
; save for compare
; load low byte counter
i:1
notfinished
#0, finished
notfinished:
Loop1
Loop3:
Loop2:
; load data byte
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
119
Freescale Semiconductor, Inc.
Source Code
Loop1:
DBNZ
DBNZ
BRA
i:1, Loop2
i:0, Loop3
Loop0
finished:
AIS #2
}
Freescale Semiconductor, Inc...
}
#else /* optimized asm version. Some bytes (ca 3) larger than C version (when considering the runtime routine too), but about 4 times faster */
asm {
LDX
_startupData.toCopyDownBeg:(0+toCopyDownBegOffs)
PSHX
PULH
LDX
_startupData.toCopyDownBeg:(1+toCopyDownBegOffs)
next:
LDA
0,X
; list is terminated by 2 zero bytes
ORA
1,X
BEQ copydone
PSHX
; store current position
PSHH
LDA
3,X
; psh dest low
PSHA
LDA
2,X
; psh dest high
PSHA
LDA
1,X
; psh cnt low
PSHA
LDA
0,X
; psh cnt high
PSHA
AIX
#4
JSR _COPY_L ; copy one block
PULH
PULX
TXA
ADD
1,X
; add low
PSHA
PSHH
PULA
ADC
0,X
; add high
PSHA
PULH
PULX
AIX
#4
BRA next
copydone:
}
#endif
DRM007
120
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Source Code
Source Code Files
/* FuncInits: for C++, this are the global constructors */
#ifdef __cplusplus
#ifdef __ELF_OBJECT_FILE_FORMAT__
i = _startupData.nofInitBodies - 1;
while ( i >= 0) {
(&_startupData.initBodies->initFunc)[i](); /* call C++ constructors */
i--;
}
#else
if (_startupData.mInits != NULL) {
_PFunc *fktPtr;
fktPtr = _startupData.mInits;
while(*fktPtr != NULL) {
(**fktPtr)(); /* call constructor */
fktPtr++;
}
}
#endif
#endif
/* LibInits: used only for ROM libraries */
}
#pragma NO_EXIT
#ifdef __cplusplus
extern "C"
#endif
void _Startup (void) { /* To set in the linker parameter file: 'VECTOR 0 _Startup' */
/* purpose:
1) initialize the stack
2) initialize run-time, ...
initialize the RAM, copy down init dat etc (Init)
3) call main;
called from: _PRESTART-code generated by the Linker
*/
#ifdef __ELF_OBJECT_FILE_FORMAT__
//asm{
//
mov #$40,$25
//
}
DisableInterrupts; /* in HIWARE format, this is done in the prestart code */
#endif
for (;;) { /* forever: initialize the program; call the root-procedure */
if (!(_startupData.flags&STARTUP_FLAGS_NOT_INIT_SP)) {
/* initialize the stack pointer */
INIT_SP_FROM_STARTUP_DESC();
}
Init();
(*_startupData.main)();
} /* end loop forever */
}
;
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
121
Freescale Semiconductor, Inc.
Source Code
Freescale Semiconductor, Inc...
7.3.2 MAIN.C
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* --------------------------------------------------------------------------- *
* File name :
main.c
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* --------------------------------------------------------------------------- *
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
In this file, the MCU configuration, data initialization and*
*
an endless loop is implemented. Also a subroutine to sense
*
*
push button changes and an algorithm for calculating the
*
*
desired and actual motor speed.
*
\*****************************************************************************/
#ifndef _MAIN_H
#define _MAIN_H
#include "main.h"
#include "timer.h"
#include "MR8IO.h"
#include "lcd.h"
#endif
/************************** LCD MESSAGES ***********************************/
const UBYTE MSGS[MAXLCDMSGS][13] = {
{"
BLDC WASH"},
{"BLDC SPIN CW"},
{"BLDC SPI CCW"},
{"
SPEED
&"},
{"
BLDC STOP"}
};
#pragma DATA_SEG DATA_ZEROPAGE
UBYTE
DRM007
122
LCDState = BLDC_WASH, // Variable for LCD command pointer
BLDCState = BLDCSTOP, // State variable for Brushless DC motor
FAULTState = NO_FAULT; /* State of the FAULT. Motor was stalled or
FAULT 1 occurred */
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
/*****************************************************************************\
* void main(void): This function includes MCU and its peripherals
*
*
configuration. Also an endless loop for the main menu
*
*
in the LCD display for user interface
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
Freescale Semiconductor, Inc...
void main(void) {
extern UBYTE Required_Direction;
UBYTE botpressed;
/* This variable is used to store the key
pressed by the user */
// MCU init
#ifdef MOS_3_COM
MOR = CENTER_ALIGNED | COMPLEMENTARY_MODE | COP_DISABLE;
#endif
#ifdef MOS_2_COM
DISMAP = 0x20;
MOR = CENTER_ALIGNED | TOPNEG | INDEPENDENT_PWMS | COP_DISABLE;
#endif
ISCR = IMASK;
FCR = FAULT_1_MANUAL | FAULT_1_INT;
InitPLL();
InitPWMMC();
// Port init
PORTA
PORTB
PORTC
DDRA
DDRB
DDRC
=
=
=
=
=
=
0x00;
0x00;
0x00;
0x0F;
0x04;
0x02;
WaitMs(250);
InitLCD();
InitTimerA();
InitTimerB();
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
123
Freescale Semiconductor, Inc.
Source Code
EnableInterrupts();
do
{
/* At this point of the endless main loop,
a new string of the main menu is displayed
in the LCD for user interface */
Freescale Semiconductor, Inc...
CtrlLCD(CLEARLCD);
StringLCD((UBYTE *)(MSGS[LCDState]));
/* This function call doesn't return until
one of the two buttons is pressed and
released */
botpressed = ResolveButtons();
/* The LEFT button is used for changing the LCD
message for other system functions, such as
varying BLDC and FAN DC speed, starting and
stopping both motors, etc. */
if (botpressed == OPTIONS_BUTTON)
{
LCDState = (UBYTE)(LCDState + 1);
if (LCDState == MAXLCDMSGS) LCDState = BLDC_WASH;
}
/* The RIGHT button is used for selecting the
current function displayed in the LCD */
else if (botpressed == ENTER_BUTTON)
{
/* Function 1. Wash function for a washing machine
is selected here. */
if(LCDState == BLDC_WASH)
{
if(BLDCState == BLDCSTOP)
{
LCDState = BLDC_STOP;
InitMotor(BLDCWASH);
}
}
DRM007
124
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
/* Function 2. Spin CW function for the washing machine */
Freescale Semiconductor, Inc...
else if(LCDState == BLDC_SPINCW)
{
if(BLDCState == BLDCSTOP)
{
LCDState = BLDC_STOP;
Required_Direction = CW;
InitMotor(BLDCSPIN);
}
}
/* Function 3. Spin CCW function for the washing machine */
else if(LCDState == BLDC_SPINCCW)
{
if(BLDCState == BLDCSTOP)
{
LCDState = BLDC_STOP;
Required_Direction = CCW;
InitMotor(BLDCSPIN);
}
}
/* Function 4. At any time, when this function is selected,
the brushless dc motor is stopped and all the
values are reinitialized for another start */
else if(LCDState == BLDC_STOP)
StopMotor();
}
}Forever();
}
UBYTE ResolveButtons(void)
{
extern
SBYTE RefSpeed,
Speed;
#pragma DATA_SEG DATA_ZEROPAGE
static
UBYTE buffer = 0; /* used for buffer temporal calculations
of motor actual speed */
do
{
if((PORTB & OPTIONS_BUTTON) == 0x00)
{
DebounceDelay();
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
125
Freescale Semiconductor, Inc.
Source Code
if((PORTB & OPTIONS_BUTTON) == 0x00)
{
WaitUntilUpButtonIsReleased();
return OPTIONS_BUTTON;
}
}
else
{
asm BIH no_button_pressed;
DebounceDelay();
asm BIH no_button_pressed;
Freescale Semiconductor, Inc...
asm button_pressed: /* Wait until DOWN button is released */
asm BIL button_pressed;
return ENTER_BUTTON;
asm no_button_pressed:
}
/* For displaying the actual and desired speed select this message.
This algorithm converts a UBYTE value to ASCII values suitable for
the LCD display */
if ((LCDState == SPEED))
{
if (RefSpeed < 0)
{
buffer = (UBYTE)(-RefSpeed);
StringLCD("DES-");
}
else
{
buffer = (UBYTE)RefSpeed;
StringLCD("DES+");
}
DataLCD((UBYTE)(((buffer * 31) / 100)
DataLCD((UBYTE)(((buffer * 31) / 100)
DataLCD((UBYTE)(((buffer * 31) % 100)
if (Speed < 0)
{
buffer = (UBYTE)(-Speed);
StringLCD("0 CU-");
}
else
{
buffer = (UBYTE)Speed;
StringLCD("0 CU+");
}
DataLCD((UBYTE)(((buffer * 31) / 100)
DataLCD((UBYTE)(((buffer * 31) / 100)
DataLCD((UBYTE)(((buffer * 31) % 100)
DRM007
126
/ 10) + '0');
% 10) + '0');
/ 10) + '0');
/ 10) + '0');
% 10) + '0');
/ 10) + '0');
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
DataLCD('0');
MovCursorLCD(First_Column, LEFT);
Freescale Semiconductor, Inc...
}
if (FAULTState != NO_FAULT)
{
CtrlLCD(CLEARLCD);
if (FAULTState == MOTOR_STALLED)
StringLCD("Motor Stalled!!!");
else
StringLCD("Fault Occured!!!");
FAULTState = NO_FAULT;
LCDState = BLDC_STOP;
}
}Forever();
}
/*****************************************************************************\
* End main.c
*
******************************************************************************/
;
7.3.3 TIMER.C
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* ----------------------------------------------------------------------------*
* File name :
timer.c
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* ----------------------------------------------------------------------------*
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
The implementation of different motor control algorithms are*
*
in this document. Also the interrupt handler subroutines are*
*
here in timer.c
*
\*****************************************************************************/
#ifndef _TIMER_H
#define _TIMER_H
#include "main.h"
#include "timer.h"
#include "tables.h"
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
127
Freescale Semiconductor, Inc.
Source Code
#include "MR8IO.h"
#include "lcd.h"
#endif
#pragma DATA_SEG DATA_ZEROPAGE
Freescale Semiconductor, Inc...
SINT16
newPWM = PWMOFF,
/* variable that indicates the duty cycle
of the BLDC motor windings, and the
output of the speed controller */
_newPWM = PWMOFF,/* Negative value of newPWM for
complementary mode */
P_Portion = 0,
/* Proportional portion of the controller*/
I_Portion = 0,
/* Integral portion of the controller */
I_PortionK_1 = 0,
/* Integral portion in last control
action */
ControllerOutput = 0;
/* Output of the controller */
SBYTE
Speed = MINSPEED,
RefSpeed = MINSPEED,
ControlDifference = 0;
UBYTE
Required_Direction = CW,/* Required direction of motor rotation */
Actual_Direction = CW, /* Actual direction of motor rotation */
Time_Out = 0,/* Used for detecting motor stalled
condition*/
TempHalls = 0,
/* Used for temporal storage of Hall
sensors */
P_Gain = 24,
/* Proportional parameter of the
controller */
I_Gain = 3,
/* Integral parameter of the controller */
SPINTable_Index = 0,
/* Index used for SPIN process table */
WASHTable_Index = 0,
/* Index used for WASH process table */
Milli_Counter = 0;/* Counter of milliseconds to change
reference speed value in the two processes of
the washing machine */
UINT16
Past_Capture = 0,
Actual_Capture = 0,
Dif_Capture = 0;
/* Actual Speed of the motor */
/* Reference Speed of the motor */
/* Error signal of the controller */
/* Past value of the capture value in one
of the timer channels */
/* Actual value of the capture value in one
of the timer channels */
/* Actual period between captures for speed
calculation */
/*****************************************************************************\
* void Init_Motor(UBYTE Commanded_Operation): This subroutine is called from *
*
main to perform one of the three washing machine processes. The
*
*
process is selected by the parameter value, Commanded_Operation. *
*
*
* Parameters: Commanded_Operation.
*
*
BLDCWASH. Wash process of the washing machine.
*
*
BLDCSPIN. Spin process.
*
*
*
* Return: None.
*
\*****************************************************************************/
DRM007
128
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
Freescale Semiconductor, Inc...
void InitMotor(UBYTE Commanded_Operation)
{
extern UBYTE BLDCState;
BLDCState = Commanded_Operation;
/* Initialize Reference speed and pointers to tables */
if (BLDCState == BLDCWASH)
{
WASHTable_Index = 0;
RefSpeed = WASHTable[WASHTable_Index++];
}
else
{
SPINTable_Index = 0;
RefSpeed = SPINTable[SPINTable_Index++];
if (Required_Direction == CCW)
RefSpeed = -RefSpeed;
}
/* Initialize variables used for motor control and speed calculation */
Actual_Capture = MAXPERIOD;
Past_Capture = 0;
I_PortionK_1 = 0;
Milli_Counter = 0;
Time_Out = 0;
/* Charge bootstrap capacitors*/
#ifdef MOS_3_COM
PVAL1 = PWMOFF;
PVAL3 = PWMOFF;
PVAL5 = PWMOFF;
PCTL1 |= LDOK;
Turn_On_Low_Side_MOSFETs();
WaitMs(10);
PWMOUT = 0x00;
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL3 = PWMON;
PVAL5 = PWMON;
PVAL2 = PWMON;
PVAL4 = PWMON;
PVAL6 = PWMON;
PCTL1 |= LDOK;
WaitMs(10);
PVAL2
PVAL4
PVAL6
PCTL1
= PWMOFF;
= PWMOFF;
= PWMOFF;
|= LDOK;
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
129
Freescale Semiconductor, Inc.
Source Code
#endif
/* Initialize timers for capture operation and interrupt every 1 ms */
InitTimerB();
InitTimerA();
ResumeTimerB();
ResumeTimerA();
newPWM = ZEROPWM;
Freescale Semiconductor, Inc...
return;
}
/*****************************************************************************\
* void InitTimerA (void): This subroutine is called from main and from the
*
*
subroutine for executing any washing machine process. * *
Its function is to initialize timer A.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
void InitTimerA (void)
{
/*
Used for:
1 Speed control
2 Commutation
*/
TASC;
TASC = TOIE | TSTOP | TRST | Prescaler_by_64;
TAMOD = _1milli;
TASC1 = CHIE | IC_any_Edge; //
HALL A
return;
}
/*****************************************************************************\
* void InitTimerB (void): This subroutine is called from main and from the
*
*
subroutine for executing any washing machine process.
*
*
Its function is to initialize timer A.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
DRM007
130
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
void InitTimerB (void)
{
Freescale Semiconductor, Inc...
/*
Used for:
1 Speed Calculation
2 Commutation
*/
TBSC;
TBSC
TBMOD
TBSC0
TBSC1
=
=
=
=
TSTOP | TRST | Prescaler_by_64;
0xFFFF;
CHIE | IC_any_Edge;
//
HALL B
CHIE | IC_any_Edge;
//
HALL C
return;
}
/*****************************************************************************\
* interrupt void TIMA_OV_ISR (void): Interrupt handler subroutine for motor
*
*
control, motor stalled protection and application
*
*
management. This interrupt occurs every millisecond. *
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
interrupt void TimerAOverflow_ISR (void)
{
extern UBYTE BLDCState;
// 519 max, 403 typ
TASC;
TASC &= ~TOF;
Dif_Capture = Actual_Capture - Past_Capture;
if (Dif_Capture > MAXPERIOD)
Speed = MINSPEED;
else if (Dif_Capture < MINPERIOD)
Speed = MAXSPEED;
else
{
/*
1665
Speed =
-----------------(Dif_Capture / 18)
*/
asm{
TXA
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
131
Freescale Semiconductor, Inc.
Source Code
LDX
DIV
LDHX
PSHA
TXA
PULX
DIV
STA
#0x12
#0x0681
Speed
}
Freescale Semiconductor, Inc...
}
if (Actual_Direction == CCW)
Speed = -Speed;
ControllerOutput = PIController();
if (ControllerOutput < 0)
{
ControllerOutput = -ControllerOutput;
Required_Direction = CCW;
}
else
Required_Direction = CW;
/*
ControllerOutput
newPWM = ---------------- + 128
256
*/
newPWM = (UBYTE)((UBYTE)(ControllerOutput >> 8) + 0x80);
MotorStalledProtection();
Milli_Counter++;
/* Enters if Milli_Counter > 10 milliseconds */
if (Milli_Counter > 10)
{
Milli_Counter = 0;
/* Wash Process */
if (BLDCState == BLDCWASH)
RefSpeed = WASHTable[WASHTable_Index++];
/* Spin Process */
else if (SPINTable_Index != 0)
{
RefSpeed = SPINTable[SPINTable_Index++];
if (Required_Direction == CCW)
RefSpeed = -RefSpeed;
}
}
return;
}
DRM007
132
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
/*****************************************************************************\
* SINT16 PI_Controller (void): This subroutines contains the PI controller
*
*
implementation.
*
*
*
* Parameters: None.
*
*
*
* Return: SINT16. Controller output.
*
\*****************************************************************************/
Freescale Semiconductor, Inc...
/*
R(K)
U(K)
---|
|
Mp(K)
---------| Kp |-------|
|
|
|
--|
---|
---------------| + | E(K) |
--| + |
M(K) |
|
|
|--------|
|
|---------| Plant |-------| - |
|
--| + |
|
| |
|
--|
---------|
--------|
|
|
|
Ki
|
|
|
|
-------|----------|---|
|
|1 - Z^(-1)|
Mi(K)
|
|
---------|
|
|
-----------------------------------------------------------------------
E(K) = R(K) - U(K)
Mp(K) = E(K) * Kp
Mi(K) = Mi(K - 1) + E(K) * Ki
M(K) = Mp(K) + Mi(K)
where:
Symbol
E(K):
R(K):
U(K):
Mp(K):
Mi(K):
Mi(K - 1):
M(K):
Kp:
Ki:
Variable Name
ControlDifference
RefSpeed
Speed
P_Portion
I_Portion
I_PortionK_1
ControllerOutput
P_Gain
I_Gain
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
133
Freescale Semiconductor, Inc.
Source Code
*/
SINT16 PIController (void) // 171 max, 152 typ
{
Freescale Semiconductor, Inc...
ControlDifference = RefSpeed - Speed;
if (ControlDifference >= 0)
{
P_Portion = (SINT16)((UBYTE)(ControlDifference) *
I_Portion = (SINT16)((UBYTE)(ControlDifference) *
}
else
{
ControlDifference = -ControlDifference;
P_Portion = (SINT16)(-((UBYTE)(ControlDifference)
I_Portion = (SINT16)(-((UBYTE)(ControlDifference)
}
(UBYTE)(P_Gain));
(UBYTE)(I_Gain));
* (UBYTE)(P_Gain)));
* (UBYTE)(I_Gain)));
if (I_PortionK_1 > MAXINTEGRAL)
I_PortionK_1 = MAXINTEGRAL;
else if (I_PortionK_1 < MININTEGRAL)
I_PortionK_1 = MININTEGRAL;
I_PortionK_1 = I_PortionK_1 + I_Portion;
return (I_PortionK_1 + P_Portion);
}
/*****************************************************************************\
* void Motor_Stalled_Protection (void): This subroutines doesn't let the
*
*
motor to stop. It calls NextSequence if a period of
*
*
time has passed and no hall sensor changes have
*
*
arrived. If a longer period of time has passed with
*
*
no hall sensor changes, the motor is stopped.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
void MotorStalledProtection(void) // 140 max, 43 typ
{
extern UBYTE FAULTState;
Time_Out++;
/* If no hall sensor interrupt has occured in a timeframe of 250 milli
second, stop the motor and quit process execution */
if (Time_Out > 250)
DRM007
134
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
{
StopMotor();
FAULTState = MOTOR_STALLED;
}
else
Freescale Semiconductor, Inc...
{
/* If 8 timeout has completed, a motor stalled protection action is
taken, calling subroutine NextSequence instead of being called from
a Hall Effect Sensor Interrupt */
if ((Time_Out & 0x07) == 0)
{
TempHalls = HallSensorInputs();
NextSequence();
}
}
return;
}
/*****************************************************************************\
* interrupt void HALL_A_ISR(void): Interrupt handler subroutine for driving
*
*
Hall A input signal. in this interrupts
*
*
is called NextSequence Subroutine for
*
*
commuting the BLDC motor
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
interrupt void HallA_ISR (void) // 160 max, 148 typ
{
TASC1;
TASC1 &= ~CHF;
TempHalls = HallSensorInputs();
/* Compute actual rotor direction from hall effect sensor changes */
if ( (TempHalls == (HALL_C)) || (TempHalls == (HALL_A | HALL_B)) )
Actual_Direction = CW;
else
Actual_Direction = CCW;
Time_Out = 0;
NextSequence();
return;
}
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
135
Freescale Semiconductor, Inc.
Source Code
Freescale Semiconductor, Inc...
/*****************************************************************************\
* interrupt void HALL_B_ISR(void): Interrupt handler subroutine for driving
*
*
Hall B input signal. in this interrupts
*
*
is called NextSequence Subroutine for
*
*
commuting the BLDC motor
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
interrupt void HallB_ISR (void) // 160 max, 148 typ
{
TBSC0;
TBSC0 &= ~CHF;
TempHalls = HallSensorInputs();
/* Compute actual rotor direction from hall effect sensor changes */
if ( (TempHalls == (HALL_A)) || (TempHalls == (HALL_B | HALL_C)) )
Actual_Direction = CW;
else
Actual_Direction = CCW;
Time_Out = 0;
NextSequence();
return;
}
/*****************************************************************************\
* interrupt void HALL_C_ISR(void): Interrupt handler subroutine for driving
*
*
Hall C input signal. in this interrupts
*
*
is called NextSequence Subroutine for
*
*
commuting the BLDC motor. Othe function
*
*
of this interrupt handler is to provide
*
*
to the overflow interrupt two consecutive *
*
periods of hall changes, to calculate
*
*
actual speed.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
interrupt void HallC_ISR (void) // 189 max, 177 typ
{
TBSC1;
TBSC1 &= ~CHF;
DRM007
136
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
/* This hall effect sensor is used as a period feedback for control input
of the speed of the motor */
Past_Capture = Actual_Capture;
Actual_Capture = TBCH1;
TempHalls = HallSensorInputs();
Freescale Semiconductor, Inc...
/* Compute actual rotor direction from hall effect sensor changes */
if ( (TempHalls == (HALL_B)) || (TempHalls == (HALL_A | HALL_C)) )
Actual_Direction = CW;
else
Actual_Direction = CCW;
Time_Out = 0;
NextSequence();
return;
}
/*****************************************************************************\
* void NextSequence (void): This subroutine has all the posible combinations *
*
of hall effect sensor inputs and direction of the
*
*
motor, to properly commutate it.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
void NextSequence(void) //108 max, 96 typ
{
#ifdef MOS_3_COM
_newPWM = PWMFREQ - newPWM;
#endif
#ifdef MOS_2_COM
#pragma DATA_SEG DATA_ZEROPAGE
static SINT16 backupnewPWM;
backupnewPWM = newPWM;
_newPWM = newPWM;
newPWM = PWMFREQ - newPWM;
#endif
/* This commutation truth table is based on "Commutate truth table.xls"*/
if (Required_Direction == CW)
{
if (TempHalls == (HALL_A))
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
137
Freescale Semiconductor, Inc.
Source Code
{
#ifdef MOS_3_COM
PVAL1 = newPWM;
PVAL3 = _newPWM;
PVAL5 = newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = newPWM;
PVAL2 = PVAL1 - DEADTIME;
Freescale Semiconductor, Inc...
PVAL3 = _newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = PWMON;
PVAL6 = PWMOFF;
#endif
}
else if (TempHalls == (HALL_A | HALL_C))
{
#ifdef MOS_3_COM
PVAL1 = _newPWM;
PVAL3 = _newPWM;
PVAL5 = newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL2 = PWMOFF;
PVAL3 = _newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
}
else if (TempHalls == (HALL_C))
{
#ifdef MOS_3_COM
PVAL1 = _newPWM;
PVAL3 = newPWM;
PVAL5 = newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = _newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = PWMON;
PVAL4 = PWMOFF;
DRM007
138
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
PVAL5 = newPWM;
PVAL6 = PVAL5 - DEADTIME;
Freescale Semiconductor, Inc...
#endif
}
else if (TempHalls == (HALL_B | HALL_C))
{
#ifdef MOS_3_COM
PVAL1 = _newPWM;
PVAL3 = newPWM;
PVAL5 = _newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = _newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = PWMON;
PVAL6 = PWMOFF;
#endif
}
else if (TempHalls == (HALL_B))
{
#ifdef MOS_3_COM
PVAL1 = newPWM;
PVAL3 = newPWM;
PVAL5 = _newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL2 = PWMOFF;
PVAL3 = newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = _newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
}
else if (TempHalls == (HALL_A | HALL_B))
{
#ifdef MOS_3_COM
PVAL1 = newPWM;
PVAL3 = _newPWM;
PVAL5 = _newPWM;
#endif
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
139
Freescale Semiconductor, Inc.
Source Code
#ifdef MOS_2_COM
PVAL1 = newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = PWMON;
PVAL4 = PWMOFF;
PVAL5 = _newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
}
Freescale Semiconductor, Inc...
}
else
{
if (TempHalls == (HALL_A))
{
#ifdef MOS_3_COM
PVAL1 = _newPWM;
PVAL3 = newPWM;
PVAL5 = newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = _newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = PWMON;
PVAL6 = PWMOFF;
#endif
}
else if (TempHalls == (HALL_A | HALL_C))
{
#ifdef MOS_3_COM
PVAL1 = _newPWM;
PVAL3 = newPWM;
PVAL5 = _newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL2 = PWMOFF;
PVAL3 = newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = _newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
DRM007
140
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
}
else if (TempHalls == (HALL_C))
{
#ifdef MOS_3_COM
PVAL1 = newPWM;
PVAL3 = newPWM;
PVAL5 = _newPWM;
#endif
Freescale Semiconductor, Inc...
#ifdef MOS_2_COM
PVAL1 = newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = PWMON;
PVAL4 = PWMOFF;
PVAL5 = _newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
}
else if (TempHalls == (HALL_B | HALL_C))
{
#ifdef MOS_3_COM
PVAL1 = newPWM;
PVAL3 = _newPWM;
PVAL5 = _newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = _newPWM;
PVAL4 = PVAL3 - DEADTIME;
PVAL5 = PWMON;
PVAL6 = PWMOFF;
#endif
}
else if (TempHalls == (HALL_B))
{
#ifdef MOS_3_COM
PVAL1 = newPWM;
PVAL3 = _newPWM;
PVAL5 = newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL2 = PWMOFF;
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
141
Freescale Semiconductor, Inc.
Source Code
PVAL3 = _newPWM;
PVAL4 = PVAL3 - DEADTIME;
Freescale Semiconductor, Inc...
PVAL5 = newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
}
else if (TempHalls == (HALL_A | HALL_B))
{
#ifdef MOS_3_COM
PVAL1 = _newPWM;
PVAL3 = _newPWM;
PVAL5 = newPWM;
#endif
#ifdef MOS_2_COM
PVAL1 = _newPWM;
PVAL2 = PVAL1 - DEADTIME;
PVAL3 = PWMON;
PVAL4 = PWMOFF;
PVAL5 = newPWM;
PVAL6 = PVAL5 - DEADTIME;
#endif
}
}
PCTL1 |= LDOK;
#ifdef MOS_2_COM
newPWM = backupnewPWM;
#endif
return;
}
/*****************************************************************************\
* void init_PWMMC (void):Initialization of the PWM module is implemented
*
*
in this subrouine and the frequency is set to
*
*
15.625 kHz.
*
*
*
* Parameters: None.
*
*
* Return: None.
*
\*****************************************************************************/
DRM007
142
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
void InitPWMMC(void)
{
PMOD = PWMFREQ;
// Frequency of 15.625 KHz
Freescale Semiconductor, Inc...
#ifdef MOS_3_COM
PVAL1 = PWMOFF;
PVAL3 = PWMOFF;
PVAL5 = PWMOFF;
DEADTM = DEADTIME;
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL3 = PWMON;
PVAL5 = PWMON;
PVAL2 = PWMOFF;
PVAL4 = PWMOFF;
PVAL6 = PWMOFF;
#endif
PCTL2 = RELOAD_1;
/* Reload every 4 PWM cycle. Fop=Fbus=8000000 Hz.
PWMFreq = 8MHz / (2*256) = 15.625 kHz
Reload Freq = 15.625 kHz / 4 = 3.90625 kHz */
PCTL1 = PWMEN;
// Turn on PWM module
PCTL1 |= LDOK;
return;
}
/*****************************************************************************\
* void stop_motor (void): The motor is stopped in this subroutine, either
* *
for user command or motor stalled.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
void StopMotor(void)
{
extern
UBYTE BLDCState;
InitTimerA();
InitTimerB();
BLDCState = BLDCSTOP;
#ifdef MOS_3_COM
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
143
Freescale Semiconductor, Inc.
Source Code
TurnOffAllPWMOutputs();
PVAL1 = PWMOFF;
PVAL3 = PWMOFF;
PVAL5 = PWMOFF;
Freescale Semiconductor, Inc...
#endif
#ifdef MOS_2_COM
PVAL1 = PWMON;
PVAL3 = PWMON;
PVAL5 = PWMON;
PVAL2 = PWMOFF;
PVAL4 = PWMOFF;
PVAL6 = PWMOFF;
#endif
PCTL1 |= LDOK;
return;
}
/*****************************************************************************\
* void init_PLL (void): PLL is initialized to run at 8 MHz of Bus frequency
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
void InitPLL(void) // Fbus = 8000000 +/- 2% Hz
{
PCTL &= ~BCS;
// select external reference as base clock
PCTL &= ~PLLON;
// turn off PLL
PPG = 0x86;
// program N and L
PBWC |= AUTO;
// enable automatic bandwidth control
PCTL |= PLLON;
// turn on PLL
while((PBWC & LOCK)==0);
// wait for PLL to lock
PCTL |= BCS;
return;
}
/*****************************************************************************\
* interrupt void Fault1_ISR(void): Interrupt handler subroutine for Fault1.
*
*
The motor is stopped when a FAULT occurs. *
*
The FAULT is asserted when the current
*
*
limit or voltage limit has been reached by *
*
the power stage.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
DRM007
144
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
Freescale Semiconductor, Inc...
interrupt void Fault1_ISR (void)
{
extern UBYTE FAULTState;
StopMotor();
FTAC |= FTACK1;
FAULTState = FAULT_OCCURED;
return;
}
interrupt void Error_Trap (void)
{
return;
}
/*****************************************************************************\
* End timer.c
*
******************************************************************************/
;
7.3.4 LCD.C
;
/*****************************************************************************\
* Copyright (c) 2002, Motorola Inc.
*
* Motorola Confidential Proprietary
*
* ----------------------------------------------------------------------------*
* File name :
lcd.c
*
* Project name:
Brushless DC Motor Drive with the MR8 Microcontroller
*
* ----------------------------------------------------------------------------*
* Author :
Jorge Zambada
*
* Email :
[email protected]
*
* Department :
Mexico Applications Lab - SPS
*
*
*
* Description :
The LCD interface and delay subroutines are implemented in *
*
this file.
*
\*****************************************************************************/
#ifndef _LCD_H
#define _LCD_H
#include "main.h"
#include "MR8IO.h"
#include "lcd.h"
#endif
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
145
Freescale Semiconductor, Inc.
Source Code
/*****************************************************************************\
* void init_LCD(void): Subroutine to initialize the LCD character display for *
*
4-bit operation, blink off, display on.
*
*
*
* Parameters: None.
*
*
*
* Return: None.
*
\*****************************************************************************/
Freescale Semiconductor, Inc...
void InitLCD(void)
{
/* Sequence followed for LCD initialization */
// In 8 bit operation mode
WaitMs(15);
Ctrl8LCD(0x03);
// Set 8
WaitMs(5);
Ctrl8LCD(0x03);
// Set 8
WaitMs(1);
Ctrl8LCD(0x03);
// Set 8
Ctrl8LCD(0x02);
// Set 4
bit operation
bit operation
bit operation
bit operation
// In 4 bit operation mode
CtrlLCD(0x28); // 4 bit operation with 2 line display
CtrlLCD(0x06);
// No display shift and move right
CtrlLCD(0x01);
// Clear display and return home position
CtrlLCD(0x0C);
// Display on, cursor off and blink off
return;
}
/*****************************************************************************\
* void ctrl_LCD(void): Subroutine for sending control bytes to the LCD. This
*
*
routine send the 8 bit value in two parts, since this *
*
function is called in 4 bit operation mode.
*
*
*
* Parameters: ctrl. An 8 bit value for different control of the LCD, such as *
*
number of lines, blink on or off, etc.
*
*
*
* Return: None.
*
\*****************************************************************************/
void CtrlLCD(UBYTE ctrl)
{
// Upper Nibble
PORTA &= 0xF0;
// puting pin states of the LCD in PORTA pins
PORTA |= (ctrl >> 4) & 0x0F;
Set_E();
Clear_E();
DRM007
146
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Source Code
Source Code Files
Wait40us();
// Lower Nibble
PORTA &= 0xF0;
PORTA |= ctrl & 0x0F;
Set_E();
Clear_E();
// puting pin states of the LCD in PORTA pins
Freescale Semiconductor, Inc...
if ((ctrl==0x01) || (ctrl==0x02)) WaitMs(2);
Wait40us();
return;
}
/*****************************************************************************\
* void ctrl8LCD(void): Subroutine for sending control bytes to the LCD in 8
*
*
bit mode. use this function only to enter 4-bit mode, *
*
since the other 4 data pins have no connection
*
*
*
* Parameters: ctrl. An 8 bit value for different control of the LCD, such as *
*
number of lines, blink on or off, etc.
*
*
*
* Return: None.
*
\*****************************************************************************/
void Ctrl8LCD(UBYTE ctrl)
{
PORTA &= 0xF0;
PORTA |= ctrl & 0x0F;
Set_E();
Clear_E();
// puting pin states of the LCD in PORTA pins
Wait40us();
return;
}
/*****************************************************************************\
* void mov_cursor_LCD(UBYTE places, UBYTE dir): subroutine to move the LCD
*
*
cursor to RIGHT or LEFT the
*
*
the number of places the user *
*
wants specyfied in 'places'
*
*
*
* Parameters: places. Number of places wanted to move the LCD cursor without *
*
affecting any LCD actual message.
*
*
dir. Direction in which the cursor is to be moved. RIGHT or
*
*
LEFT.
*
*
*
* Return: None.
*
\*****************************************************************************/
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
147
Freescale Semiconductor, Inc.
Source Code
void MovCursorLCD(UBYTE places, UBYTE dir)
{
UBYTE ctrl_byte = 0x10 | dir;
do
{
CtrlLCD(ctrl_byte);
}while((--places)>0);
return;
Freescale Semiconductor, Inc...
}
/*****************************************************************************\
* void data_LCD(UBYTE data): ASCII symbol to be displayed in the LCD in the
*
*
current cursor position.
*
*
*
* Parameters: data. 8-bit value representing the ASCII code of the symbol
*
*
to be displayed in the LCD at current position
*
*
*
* Return: None.
*
\*****************************************************************************/
void DataLCD(UBYTE data)
{
// Upper Nibble
PORTA &= 0xF0;
// puting pin states of the LCD in PORTA pins
PORTA |= (data >> 4) & 0x0F;
Set_RS();
Set_E();
Clear_E();
// Lower Nibble
PORTA &= 0xF0;
PORTA |= data & 0x0F;
Set_E();
Clear_E();
// puting pin states of the LCD in PORTA pins
Wait40us();
Clear_RS();
return;
}
DRM007
148
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Source Code
Source Code Files
/*****************************************************************************\
* void string_LCD(UBYTE *msgLCD): A function that displays a string in the LCD*
*
at current cursor position. If a '&' cha*
*
racter is present in the string, a new line
*
*
is commanded in the LCD. the function send *
*
all the bytes in the string until a presense*
*
of a EndOfString, EOS or 0x00 byte.
*
*
*
* Parameters: *msgLCD. Pointer to the string to be displayed in the LCD
*
*
*
* Return: None.
*
\*****************************************************************************/
void StringLCD(UBYTE *msgLCD)
{
while(*msgLCD != EOS)
{
if(*msgLCD == EOL) MovCursorLCD(29,RIGHT);
else DataLCD(*msgLCD);
msgLCD++;
}
return;
}
// new line
/*****************************************************************************\
* void wait_ms(UBYTE milis): Delay routine that waits for a number of milli- *
*
seconds send in the parameter milis. the delay
*
*
is calculated for a 8 MHz Fbus operation.
*
*
*
* Parameters: milis. A 8 bit value representing the number of milliseconds the*
*
delay will wait.
*
*
*
* Return: None.
*
\*****************************************************************************/
void WaitMs(UBYTE milis)
{
UBYTE wait40usCount = 0;
// used for counting wait40us delay
do{
for(wait40usCount = 0; wait40usCount < 24; wait40usCount++)
Wait40us();
}while((--milis) != 0);
return;
}
BLDC Motor Control Board for Industrial and Appliance Applications
MOTOROLA
Source Code
For More Information On This Product,
Go to: www.freescale.com
DRM007
149
Freescale Semiconductor, Inc.
Source Code
/*****************************************************************************\
* void wait40us(void): An instant of time of which the wait_ms() subroutine is*
*
based on.
*
*
*
* Parameters: None
*
*
*
*
*
* Return: None.
*
\*****************************************************************************/
Freescale Semiconductor, Inc...
void Wait40us(void)
{
UBYTE count = 103;
// Value for 40us delay at Fbus = 8 MHz
do{
}while(--count);
return;
}
/*****************************************************************************\
* End lcd.c
*
******************************************************************************/
;
DRM007
150
BLDC Motor Control Board for Industrial and Appliance Applications
Source Code
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
HOW TO REACH US:
USA/EUROPE/LOCATIONS NOT LISTED:
Motorola Literature Distribution;
P.O. Box 5405, Denver, Colorado 80217
1-303-675-2140 or 1-800-441-2447
JAPAN:
Motorola Japan Ltd.; SPS, Technical Information Center,
3-20-1, Minami-Azabu Minato-ku, Tokyo 106-8573 Japan
81-3-3440-3569
Freescale Semiconductor, Inc...
ASIA/PACIFIC:
Motorola Semiconductors H.K. Ltd.;
Silicon Harbour Centre, 2 Dai King Street,
Tai Po Industrial Estate, Tai Po, N.T., Hong Kong
852-26668334
Information in this document is provided solely to enable system and software
implementers to use Motorola products. There are no express or implied copyright
licenses granted hereunder to design or fabricate any integrated circuits or
integrated circuits based on the information in this document.
TECHNICAL INFORMATION CENTER:
Motorola reserves the right to make changes without further notice to any products
1-800-521-6274
herein. Motorola makes no warranty, representation or guarantee regarding the
suitability of its products for any particular purpose, nor does Motorola assume any
HOME PAGE:
http://motorola.com/semiconductors
liability arising out of the application or use of any product or circuit, and specifically
disclaims any and all liability, including without limitation consequential or incidental
damages. “Typical” parameters which may be provided in Motorola data sheets
and/or specifications can and do vary in different applications and actual
performance may vary over time. All operating parameters, including “Typicals”
must be validated for each customer application by customer’s technical experts.
Motorola does not convey any license under its patent rights nor the rights of
others. Motorola products are not designed, intended, or authorized for use as
components in systems intended for surgical implant into the body, or other
applications intended to support or sustain life, or for any other application in which
the failure of the Motorola product could create a situation where personal injury or
death may occur. Should Buyer purchase or use Motorola products for any such
unintended or unauthorized application, Buyer shall indemnify and hold Motorola
and its officers, employees, subsidiaries, affiliates, and distributors harmless
against all claims, costs, damages, and expenses, and reasonable attorney fees
arising out of, directly or indirectly, any claim of personal injury or death associated
with such unintended or unauthorized use, even if such claim alleges that Motorola
was negligent regarding the design or manufacture of the part.
Motorola and the Stylized M Logo are registered in the U.S. Patent and Trademark
Office. digital dna is a trademark of Motorola, Inc. All other product or service
names are the property of their respective owners. Motorola, Inc. is an Equal
Opportunity/Affirmative Action Employer.
© Motorola, Inc. 2003
DRM007/D
Rev. 0
2/2003
For More Information On This Product,
Go to: www.freescale.com