You are on page 1of 15

Brushless DC Motor Control Using

PIC18Fxx31 Microcontrollers

Brushless DC (BLDC)
Motor Control

using

PIC18Fxx31
Microcontrollers

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 1

2003 Microchip Technology Inc. 1


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Agenda
Overview of motor control solutions from Microchip
PIC18Fxx31 peripherals for motor control
BLDC motor control using PIC18Fxx31
Open loop control
Closed loop control using Hall sensors
Closed loop control using Quadrature encoder
Sensorless control

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 2

The agenda for this discussion is:


First we will discuss an overview of motor control solutions from Microchip
PIC18Fxx31 has many peripherals that are useful for motor control application. We
will discuss the major peripherals that are helpful in developing motor control
application.
Then we will discuss the Brushless DC motor control using PIC18Fxx31 devices in
open loop, closed loop with Hall sensors and closed loop with Quadrature Encoder
or also known as optical encoder. Finally we will see how a sensorless control of
BLDC motor can be implemented using PIC18Fxx31
At the end of this discussion, we will show few references that would be helpful for
you to understand BLDC motors and controls using PIC18Fxx31

2003 Microchip Technology Inc. 2


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Motor Control from Microchip


Complete solutions for Stepper, Brushed DC,
BLDC, ACIM & SR motors utilizing PIC16, PIC18
and dsPIC devices
Microchip Op Amps and International Rectifier
drivers
Provide everything a design engineer needs:
Low-risk product development
Lower total system cost
Faster time to market
Outstanding technical support
Dependable delivery & quality
Visit us at www.microchip.com/motor
2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 3

Microchip Technology offers a broad product portfolio that provides a complete


system solution for your brushed DC motor, variable speed brushless DC motor,
AC induction motor, switched reluctance motor and stepper motor applications.
This includes the microcontroller with firmware to drive the motor, analog op amps
and comparators for sensors or feedback and power electronics from Microchip and
International Rectifier.
With our sophisticated development systems and technical documentation,
Microchip makes it easy for designers of all experience levels to complete a high
performance electronic motor control design quickly and cost effectively.
Microchip provides everything a motor control design engineer needs: low-risk
product development, lower total system cost, faster time-to-market, outstanding
technical support and dependable delivery and quality.

For access to Microchips complete motor control design resources,


visit the Motor Control Design Center at www.microchip.com/motor.

2003 Microchip Technology Inc. 3


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

PIC18Fxx31 overview

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 4

PIC18Fxx31 family of microcontrollers have 4 parts, having 28-pin and 40-pin


packages with 8Kbytes and 16Kbytes of program memory. The major peripherals that are useful
in motor control are Power Control PWM or PCPWM, High-speed Analog-to-Digital Converter
and Motion Feedback module. These peripherals simplify the motor control algorithm to a great
extent.
The main features of PCPWM include:
Up to 8 channels output with independent or 4 pairs complimentary outputs
Up to 14 bits PWM of resolution
Center aligned or edge aligned PWM operation. Also known as symmetrical PWM or
asymmetrical PWM operation
Programmable dead band control for complementary outputs
Hardware Fault interface pins for fast PWM shut down in the event of fault.
Main features of high-speed ADC include:
Up to 9 channels input, with 2 Sample and Hold circuits
Simultaneous and sequential conversion capabilities with multiple channel selection
4 word deep FIFO with flexible interrupt settings
Main features of Motion Feedback Modules are:
Multiplexed Input Capture and Quadrature Encoder Interface (QEI) modules
In QEI, A, B and Index signals interface for measuring, position velocity and direction of
rotation
3 Input Capture pins with multiple modes for pulse width and frequency measurements -
Interrupt on change feature used for Hall sensor interface.

2003 Microchip Technology Inc. 4


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

PIC18Fxx31 peripherals
Power control PWM
Up to 8 channels with up to 14-bit resolution
Center aligned and edge aligned operations
High-speed ADC
Up to 9 channels with up to 200 Ksps
4 word FIFO buffer with flexible interrupts
Motion feedback module
Quadrature Encoder Interface (QEI) - QEA, QEB, Index
Position and velocity measurement modes

3 Input Capture (IC) pins


Pulse width and frequency measurement modes

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 5

PIC18Fxx31 family of microcontrollers have 4 parts, having 28-pin and 40-pin packages with
8Kbytes and 16Kbytes of program memory.
The major peripheral that are useful in motor control are Power Control PWM or PCPWM, high-
speed Analog-to-Digital Converter and Motion Feedback module. These peripherals simplify the
motor control algorithm to a great extent.
Main features of PCPWM include:
Up to 8 channels output with independent or 4 pairs complimentary outputs
Up to 14 bits PWM of resolution
Center aligned or edge aligned PWM operation. Also known as symmetrical PWM or
asymmetrical PWM operation
Programmable dead band control for complementary outputs
Hardware Fault interface pins for fast PWM shut down in the event of fault.
Main features of high-speed ADC include:
Up to 9 channels input, with 2 Sample and Hold circuits
Simultaneous and sequential conversion capabilities with multiple channel selection
4 word deep FIFO with flexible interrupt settings
Main features of Motion Feedback Modules are:
Multiplexed Input Capture and Quadrature Encoder Interface modules
In QEI, A, B and Index signals interface for measuring, position velocity and direction of
rotation
3 Input Capture pins with multiple modes for pulse width and frequency measurements -
Interrupt on change feature used for Hall sensor interface.

2003 Microchip Technology Inc. 5


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Drive topology
VDC+

H1 H2 H3
Phase B

(5) (1)
(2) (4)

Phase A Phase C
(3) (6)

L1 L2 L3
VDC-

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 6

A brushless DC motor is a synchronous motor that finds numerous applications in


motion control. Appliance, automotive, aerospace, industrial automation, automation
are few industries to list. These come with different torque and voltage ratings. A
BLDC motor has windings on stator and alternate permanent magnets on rotor. BLDC
motors are electronically commutated based on the rotor position with respect to the
stator winding. This means, to run a BLDC motor an electronic drive is required.
Normally 3 Hall effect sensors mounted on the stator are used to determine the rotor
position. The Hall effect sensors give a combination of high and low signals when they
pass next to the rotor poles. With this combination, the commutation sequence is
determined.
A typical control circuit with 3 phase winding connection is shown in the figure
H1,H2, H3 and L1, L2,L3 make 3 phase voltage source inverter connected across the
power supply indicated by VDC+ and VDC-. Stator windings A, B and C are
connected in star to the inverter.
In coming slide we will see how these stator windings are energized in synchronous
with the Hall sensor inputs.

2003 Microchip Technology Inc.


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Switching Sequence
Step (1) (2) (3) (4) (5) (6) (1) (2) (3) (4) (5) (6)
Hall sensor 101 001 011 010 110 100 101 001 011 010 110
Hall A
Phase A
Hall B
Phase B
Hall C
Phase C
Hall Hall Hall Phase Phase Phase
High switch H3 H1 H1 H2 H2 H3 H3A1 H1B0 H1C1 H2NC
A H2 B
Vdc-
C
Vdc+
Low switch L2 L2 L3 L3 L1 L1 L21 L20 L30 L3Vdc+L1 Vdc- NC
1 1 0 Vdc+ NC Vdc-
0 1 0 NC Vdc+ Vdc-
0 1 1 Vdc- Vdc+ NC
Sequence table example 0 0 1 Vdc- NC Vdc+

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 7

With 3 Hall sensors on the motor, every 60 degrees of electrical cycle, a Hall sensor
makes transition either from low to high or from high to low. With this every
electrical cycle has 6 steps to complete one full cycle. The energizing sequence will
have 6 combinations of turning ON and Off of the 6 switches that we saw in the
previous slide. A typical switching sequence is shown on the table here.
The Hall sensor inputs are at 120 degrees phase shift to each other. Every sequence
has two windings connected across the power supply and third winding left open.
Considering the first step where the Hall sensor input is 101, Phase C is connected
to positive DC bus and phase B is connected to negative DC bus and phase A is left
open. In order to achieve this switch H3 and L2 should be closed and all other
switches should be open. This will turn the rotor by 60 degree electrical in the given
direction. This will make the Hall sensor to make another transition triggering the
next point on the sequence table and so on.
The electrical cycle and shaft rotation have a definite relation. The electrical cycle
repeats with every rotor pole pairs. So to complete one rotation on the shaft, these 6
steps should be repeated as many times as rotor pole pairs.
If the sequence is followed with rated motor voltage across the motor windings,
motor will run at rated speed. Speed can be controlled using PWMs, by PWMing
each switch according to the speed required.
The phase current waveform looks trapezoidal in shape with each phase current
having 120 degrees phase shift to each other.

2003 Microchip Technology Inc.


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Control using Hall Sensors


AC in
+ - DC bus
/MCLR 1 28 RB7/PGD
AN0 RB6/PGC
2 27
Potentiometer AN1/IC1 PWM4 B-Low
3 26
Hall sensors AN2/IC2
4 25 PWM5 B-High
AN3/IC3 Y-High

PIC18F2431
5 24 PWM3
Motor current AN4
6 23 PWM2 Y-Low 3 phase
AVdd
AVss
7 22 PWM1 R-High Inverter
PWM0 R-Low
OSC1
8
9
21
20 Vdd bridge
OSC2
10 19 Vss Motor
RC0
11 18 RC7/RX/DT current
Motor current /FLTA/CCP2 12 17 RC6/TX/CK

- /FLTB/CCP1 13 16 RC5/INT2 BLDC


Reference +
RC3/INT0 14 15 RC4/INT1 Motor
Hall
sensors

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 8

This slide shows the hardware interface used for controlling a BLDC motor. Hall
sensors are used for commutation. Hall sensors can be connected to either Interrupt on
change pins that are on port C or they can be connected to Input capture pins on
Motion feedback module.
The input capture module has a mode in which the module generates an interrupt on
transition on each pin, making it ideal for Hall sensor interface. Optionally, Timer5 can
be captured on each transition. This Timer5 value can be used for determining the
speed at which motor is running. This gives a low resolution speed measurement.
For the applications where high resolution of speed measurement is required,
quadrature encoder is used. The QE gives speed, position and direction of rotation.

2003 Microchip Technology Inc. 8


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

OVDCOND v/s PWM output


Step (1) (2) (3) (4) (5) (6)
Hall sensor 101 001 011 010 110 100
OVDCOND 00100100 00000110 00010010 00011000 00001001 00100001

PWM5 - H3

PWM4 - L3
PWM3 - H2

PWM2 - L2
PWM1 - H1
PWM0 - L1

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 9

Now let us see how to control the speed using PCPWM module. PCPWM module
has a feature of over riding the PWM outputs based on the value in OVDCOND
register. When the corresponding value in OVDCOND is set to 1, the PWM output
becomes active and vise versa. With this we can efficiently allow the required PWM
to appear on the pin, when required as per the sequence, and inhibit when not
required.
Speed variation is achieved by varying the duty cycle of each PWM. To increase the
speed, the active part on duty cycle needs to be increased and to reduce the speed,
the active time is reduced. By doing this the average voltage supplied across the
motor winding varies, thus controlling the motor speed.
This slide shows the relationship between the OVDCOND register and the PWM
output. PWM0 to PWM5 control on and off of 6 switches. The PWMs are passed
and inhibited according to the sequence discussed earlier.

2003 Microchip Technology Inc. 9


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Control Flow Chart


Initialization

Load new step sequence


Yes
Hall sensor to the OVDCOND
change?
register from Table
No

Yes Calculate new PWM


Change
Speed? duty cycle
Hall Hall Hall Phase Phase Phase
A B C A B C
No 1 0 1 NC Vdc- Vdc+
1 0 0 Vdc+ Vdc- NC
Key scan/ 1 1 0 Vdc+ NC Vdc-
0 1 0 NC Vdc+ Vdc-
Other application? 0 1 1 Vdc- Vdc+ NC
0 0 1 Vdc- NC Vdc+

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 10

This shows a simplified control flow chart for BLDC motor control. The sequence
table dictates the PWM channels that should be in active or inactive states, based on
the Hall sensor states. On every transition on Hall sensor input, new step from the
sequence is loaded to the OVDCOND register.
Any change in the speed command is read either using a potentiometer connected to
one of the AD channel or a digital value from another controller calculate a new
PWM duty cycle and load to the appropriate registers.

2003 Microchip Technology Inc.


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Control using Quadrature Encoder


Potentiometer
AC in
/MCLR 1 RB7/PGD
4
AN0 2 0 RB6/PGC
39
+ - DC bus
INDX 3 PWM4 B-Low
QEA 38
QE interface QEB
4
PWM5 B-High
37
5 Y-High
AN4 6 36 PWM3
PWM2 Y-Low

PIC18F4431
AN5 35
Motor current AN6
7
8 34 PWM1 R-High

Temp. sensor
AN7
AN8 9
10
33 PWM0 R-Low 3 phase
32 Vdd
Vdd 11 31 Vss Inverter
Vss 30 RD7
12
OSC2 13 29 RD6 bridge
OSC1 14 28 RD5 Motor
27 RD4
RC0 15 26 RC7/RX/DT current
FLTA/CCP2 16
Motor current FLTB/CCP1 25 RC6/TX/CK
- 17 24 RC5/INT2 BLDC
INT0/RC3 23 RC4/INT1
Reference + 18
Motor
RD0
19 22 RD3
RD1 21 RD2
INT0 Hall
20
Power factor sensors
QE
correction

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 11

With QE for speed, position and direction feedback and Hall sensors for commutation
can be interfaced as shown here.
Hall sensors connected to INT pins, and QE connected to motion feedback module.

2003 Microchip Technology Inc. 11


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Sensorless control
Potentiometer
AC in
/MCLR 1
4 RB7/PGD
AN0 2
IC1
0 RB6/PGC
39
+ - DC bus
3 PWM4 B-Low
IC2 38
Back EMF ZC detect IC3
4
B-High
37 PWM5
5 Y-High
AN4 6 36 PWM3
35 PWM2 Y-Low

PIC18F4431
AN5
Motor current AN6
7
BLDC
8 34 PWM1 R-High

Temp. sensor
AN7
AN8 9
10
33 PWM0 R-Low 3 phase Motor
32 Vdd
Vdd 11 31 Vss Inverter
Vss 30 RD7
OSC2
12
13 29 RD6 bridge
OSC1 14 28 RD5
RC0 27 RD4
15 26 RC7/RX/DT
FLTA/CCP2 16
Motor current FLTB/CCP1 25 RC6/TX/CK
- 17 24 RC5/INT2 Motor
INT0/RC3 23 RC4/INT1
Reference + 18
current
RD0
19 22 RD3
RD1
20 21 RD2
+
Power factor
correction Back EMF ZC detect -

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 12

Sensorless control of BLDC motor gives many advantages, most importantly lowered
system cost. Every phase develops a voltage called Back EMF, that opposes the power
applied to the phase. During the non energized phase of the sequence, this back EMF
crosses from positive voltage to negative voltage. From the the zero cross over point,
rotor position can be determined, and used for commutation. This method eliminates
the requirement of sensors for commutation.
However, this may require additional hardware on the drive side and additional
firmware overhead on the microcontroller.

2003 Microchip Technology Inc. 12


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Sensorless control schemes


1) Compare with DC bus/2 2) Compare with virtual neutral
+ +
DC+ DC+
_ To IC3 _ To IC3
A BZ_C A BZ_C
+ +
_ To IC1 _ To IC1
BZ_A BZ_A
Back EMF Back EMF

C
B +
DC- C DC-
B +
_ To IC2 _ To IC2
DC/2 BZ_B Virtual BZ_B
Neutral

AN0
A

Back EMF
3) Using ADC Channels
C B AN1

AN2

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 13

We will see three different methods of determining the Back EMF zero cross point.
1) Comparing WRT center point of DC bus: Every sequence has two windings
connected across power supply and third winding left open. The BEMF generated in
the non energized winding is compared with respect to the half of DC bus. This gives a
fairly good result, when the motor terminal voltage is approximately equal to the DC
bus voltage. If the DC bus voltage is disproportionately high, the cross over point may
drift away, making it difficult to determine a workable commutation sequence at all
speeds.
2) Comparing with a virtual neutral: A virtual neutral point can be generated using
resistor ladders as shown and the BEMF in the non-energized winding can be
compared with this neutral point. This makes it comparatively easy to determine the
zero cross point at all measurable speeds.
3) Using High speed ADCs: The BEMF signals are attenuated and read directly using
an on chip ADC on a PIC18Fxx31 can give a great flexibility in determining the zero
cross over point.

However, at low speeds, the BEMF developed is very low in amplitude, which makes
it difficult to determine a zero cross over point.

2003 Microchip Technology Inc.


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Summary
Overview of motor control solutions from Microchip
PIC18Fxx31 peripherals for motor control
BLDC motor control using PIC18Fxx31
Open loop control
Closed loop control using Hall sensors
Closed loop control using Quadrature encoder
Sensorless control

2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 14

2003 Microchip Technology Inc. 14


Brushless DC Motor Control Using
PIC18Fxx31 Microcontrollers

Resources
Application notes:
AN885 : Brushless DC motor fundamentals
AN899 : Brushless DC motor control using PIC18Fxx31
AN857 : Brushless motor control made easy

Demo and development board


PICDEMTM MC
Completely isolated, debug tools can be connected
when the board is live
Low cost design

Web design center: www.microchip.com/motor


2003 Microchip Technology Incorporated. All Rights Reserved. Brushless DC Motor Control Using PIC18Fxx31 Microcontrollers 15

These are additional resources for more information on Microchips Motor Control
solutions.

2003 Microchip Technology Inc. 15

You might also like