DC Motor Control 3
DC Motor Control 3
This application note describes the creation of an Finally, the pattern in which the armature is winded may
intelligent 4-wire fan. This design incorporates a PIC® vary. A two-phase fan will have two separate windings
microcontroller directly inside of the fan, enabling the which can be individually energized. These windings
fan to provide closed loop speed control, speed are always energized with current flowing in the same
feedback, and additional safety features. direction. Another option is a single-phase system in
which a single winding is constantly energized, but the
Topics covered will include: direction of the current is reversed.
• Brushless DC fan basics The two-phase method is lower cost, requiring one
• Necessary microcontroller peripherals MOSFET device per phase. However, since this
• Hardware, and software control techniques. method only utilizes half of the armature windings at
any given time, it is not suitable for higher power appli-
This application note is targeted toward the PIC16F616
cations. Since the single phase method energizes
and PIC12F615, however it can be adapted to many
every winding on the armature simultaneously, it is bet-
PIC® microcontrollers.
ter suited for higher power fan applications. However,
this method requires a total of 4 MOSFET devices.
BRUSHLESS DC THEORY The fan determines which phase to energize (or which
Since brushless DC fans are variants of basic brush- way to energize the single phase) by using a Hall
less DC motors, all of the same brushless DC motor sensor. These sensors are able to detect the magnetic
basics apply. There are several Microchip application poles of the ring magnet and provide the necessary
notes that cover brushless DC basics, and a listing of information to determine how to energize the armature.
these application notes can be found in the references These sensors will be discussed in more detail in the
section of this document. following sections.
Armature
Ring Magnet
Time
Hall Sensor Output
(volts)
Time
Hall
Element Output
log [ 4 ( PR2 + 1 ) ]
Resolution = ------------------------------------------ bits
P1B in Idle log ( 2 )
state
The frequency choice can affect the PWM resolution so
P1B some frequencies may not yield an integer number of
bits of PWM resolution. For example, a 20 kHz PWM
frequency with an 8 MHz oscillator yields a PR2 value
of 99 and a PWM resolution of 8.6438 bits (numbers
calculated using the equations in the CCP chapter of
P1D the data sheet which have been reproduced here as
Equation 1 and Equation 2). This means that the pos-
sible duty cycle values range from 0 to 399. Depending
on the output of the control loop software, the duty
cycle may have to be scaled up or down.
Scaling up from a value with less resolution to a value
PWM direction change with more resolution is undesirable. Doing this will
cause the duty cycle steps to be unequal, and this
method does not take full advantage of the available
With each commutation it is necessary to change the PWM resolution. Therefore a better choice is to scale
direction of the ECCP module. If we use the ECCP from a value with more resolution to a value with less
module in this method, it will ensure that both outputs resolution.
will never be active simultaneously.
In this case a range of 0 to 511 (9 bits) is scaled to
produce a range of 0 to 399 (8.6438 bits). The scaling
Choosing a PWM frequency is performed by taking the 9-bit control loop output,
One important constraint in choosing the PWM fre- multiplying by an 8-bit scaling factor, and discarding the
quency for the fan windings is to ensure the frequency low byte of the result. The formula for determining the
is above the audible 20 kHz. Given this constraint there scaling factor is shown in Equation 3 below.
are still multiple ways of deciding on a frequency.
EQUATION 3: DETERMINING THE
The frequency may be chosen such that the resulting
PWM resolution is an integer number of bits. For exam- SCALING FACTOR
ple, with an 8 MHz oscillator, a PWM resolution of
31.25 kHz will provide exactly 8 bits of resolution. Hav-
(maxoutput) • 256
Scaling Factor = --------------------------------------------
ing an integer number of bits of resolution will simplify (maxinput)
math routines. In this example, however, the higher
switching frequency may cause thermal problems with In determining the scaling factor, maxoutput is the
the fan MOSFETs. In this case it may be better to use maximum desired output of the scaling routine and
a lower frequency. maxinput is the maximum value for the input to the
It is also possible to choose the PWM frequency based scaling routine.
on other fan characteristics, such as fan winding char- When scaling from 9 bits to 8.6438 bits the scaling
acteristics, or to minimize switching losses. If in keep- factor will be 200 (decimal). Table 1 shows the input
ing the PWM resolution at an integer number of bits of and output of the scaling routine. As you can see, the
resolution is not a constraint. Choosing the lowest input value of 511, a full-scale 9-bit input, corresponds
frequency possible will minimize switching losses while to the maximum duty cycle of 399.
simultaneously maximizing PWM resolution.
TABLE 1: RESULTS OF SCALING
EQUATION 1: PWM PERIOD ROUTINE
PWM Period = [ ( PR2 ) + 1 ] • 4 • T OSC • 9 bit value High bytes of
Multiply by 200
(TMR2 Prescale Value) (0 - 511) result
127 25400 99
255 51000 199
383 76600 299
511 102200 399
One register is used as an accumulator, and another as FIGURE 9: TIMER1 GATE DIAGRAM
the offset. Every n PWM periods, the offset is added to
the accumulator. If the accumulator overflows, the
PWM period is increased by one for the next n PWM
periods. For example, with an 8-bit accumulator and
the offset loaded with 128, the accumulator would over-
flow every other cycle. If the offset was loaded with 1, Timer1 Timer1
then the accumulator would overflow 1 out of every 256 Clock Source Counter
cycles, and so on.
Timer1
Gate
R Measurement No
Low Freq. in Progress?
PWM To ADC
C Yes
Increment Counter
300
54
64
250
74
82
Routine Output
200 92
99
150 110
120
100 128
138
50
0
0 200 400 600 800 1000 1200 1400
Timer2 Counts
Yes
GENERATING AN ALARM OUTPUT
While a tachometer is one very common speed sense Set Alarm
output, the alarm signal is another.
VDD
FIGURE 18: FAN #2 RESPONSE
C
VSS 5000
(RPM)
Speed (RPM)
4000
1000
voltage to other components.
0
FAN RESPONSE CHARACTERISTICS 0% 50% 100% 150%
EQUATION 7: I CONTROLLER
Output = ΣK i ⋅ Error
3500
3000
2500
2000
RPM
1500
1000
500
0
0 100 200 300 400 500 600
Sample
88000
0 00
77000
0 00
66000
0 00
55000
0 00
RPM
RPM
44000
0 00
33000
0 00
22000
0 00
11000
0 00
0
0%
0% 20%
20 % 40%
4 0% 60%
60 % 80%
80 % 100%
10 0%
DDuty
u ty Cycle
C y cle
REFERENCES
AN847 “RC Model Aircraft Motor Control”
(DS00847)
AN857 “Brushless DC Motor Control Made Easy”
(DS00857)
AN893 “Low-Cost Bidirectional Brushed DC Motor
Control Using the PIC16F684” (DS00893)
AN894 “Motor Control Sensor Feedback Circuits”
(DS00984)
AN898 “Determining MOSFET Driver Needs for
Motor Drive Applications” (DS00898)
AN905 “Brushed DC Motor Fundamentals”
(DS00905)
TP1 (BLK)
APPENDIX A:
1G 6 9 HW-300B
SENSE 2N7002LT1 P1D RC4 RC1 ISENSE
S 7
100 2N7002LT1GOSCT-ND 8
2 RC3 RC2 P1B +5V
PIC16HV616/SL R9
10K
RC0
R10
THERMISTOR
TP7 +12V PICkit™ 2 PLUNGE HEADER
J1
VPP 1 VPP VDD 2 +5V
DC FAN MOTOR 3 GND 4
GND DAT ICSPDATA
5 CLK 6
ICSPCLK NC NO CONNECT
PK2
TP5 TP6
3 3
D D
Q1
R2 + C1 C2 + 1 R3
1 G ZXMN6A07F G
P1B 2.2 UF 2.2 UF P1D
S S
100 ZXMN6A07FCT-ND 35V 35V 100
R5 2 ZXMN6A07FCT-ND 2 R6
10K 10K
ISENSE
R1
2
1/2W
DS01178A-page 17
AN1178
AN1178
NOTES:
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
01/02/08