Professional Documents
Culture Documents
Chapter 5
Chapter 5
CHAPTER 5
DC Motor Control
Tips ‘n Tricks
Digital
Output
A-D are digital outputs from a PIC® MCU.
MOSFET
Driver
The H-Bridge derived its name from the
common way the circuit is drawn. This is the
M only solid state way to operate a motor in both
directions.
Application notes that drive Brushed DC motors
are listed below and can be found on the
Microchip web site at: www.microchip.com.
This drive can control a Brushed DC motor in
one direction. This drive is often used in safety • AN847, “RC Model Aircraft Motor Control”
critical applications because a short circuit at (DS00847)
the motor terminals cannot turn the motor on. • AN893, “Low-cost Bidirectional Brushed DC
Motor Control Using the PIC16F684”
Figure 1-2: Low Side Drive (DS00893)
V+ • AN905, “Brushed DC Motor Fundamentals”
(DS00905)
PIC®
Microcontroller M
Digital
Output
MOSFET
Driver
Without sensors, another property of the OA-OF are digital outputs from a PIC® MCU.
Figure 2-3: Quadrature Decoder (Sensor Motor) TIP #3 Stepper Motor Drive Circuits
Stepper motors are similar to Brushless
PIC® MCU or dsPIC® DSC DC motors in that the control system must
commutate the motor through the entire rotation
Digital Digital
cycle. Unlike the brushless motor, the position
Outputs Inputs and speed of a stepping motor is predictable
and does not require the use of sensors.
Drive
There are two basic types of stepper motors,
Circuit although some motors are built to be used in
A B C
either mode. The simplest stepper motor is
the unipolar motor. This motor has four drive
connections and one or two center tap wires
Hall
Sensor
that are tied to ground or Vsupply, depending
Effect
Motor Motor Outputs on the implementation. Other motor types are
Position the bipolar stepper and various combinations
Sensor
of unipolar and bipolar, as shown in Figure 3-1
and Figure 3-2. When each drive connection
Application notes describing Brushless DC Motor is energized, one coil is driven and the motor
Control are listed below and can be found on the rotates one step. The process is repeated
Microchip web site at: www.microchip.com. until all the windings have been energized.
To increase the step rate, often the voltage is
• AN857, “Brushless DC Motor Control Made increased beyond the motors rated voltage.
Easy” (DS00857) If the voltage is increased, some method of
• AN885, “Brushless DC Motor Fundamentals” preventing an over current situation is required.
(DS00885) There are many ways to control the winding
• AN899, “Brushless DC Motor Control Using current, but the most popular is a chopper
PIC18FXX31” (DS00899) system that turns off current when it reaches
• AN901, “Using the dsPIC30F for Sensorless an upper limit and enables the current flow a
BLDC Control” (DS00901) short time later. Current sensor systems are
• AN957, “Sensored BLDC Motor Control Using discussed in Tip #6. Some systems are built
dsPIC30F2010” (DS00957) with a current chopper, but they do not detect
the current, rather the system is designed to
• AN992, “Sensorless BLDC Motor Control begin a fixed period chopping cycle after the
Using dsPIC30F2010” (DS00992) motor has stepped to the next position. These
• AN1017, “Sinusoidal Control of PMSM with are simpler systems to build, as they only
dsPIC30F DSC” (DS01017) require a change in the software.
• GS005, “Using the dsPIC30F Sensorless
Motor Tuning Interface” (DS93005)
Figure 3-1: 4 and 5 Wire Stepper Motors Figure 3-4: Bipolar Motor (4 Half-Bridges)
V V
A C
B D
Figure 3-2: 6 and 8 Wire Stepper Motors
Short for
Unipolar
Motor
V V
Individual coils E G
wire anyway
appropriate
Unipolar and Bipolar 8 Wire
6 Wire
01
02
03
04
TIP #5 Writing a PWM Value to the Example 5-2: Right Justified 16-Bit Macro
the CCP Registers With a pwm_tmp equ xxx ;this variable must be
Mid-Range PIC® Microcontroller ;allocated someplace
setPeriod macro a ;a is 2 bytes in
The two PWM LSb’s are located in the ;Low:High arrangement
CCPCON register of the CCP. This can make ;the 10 LSb’s are the
changing the PWM period frustrating for a ;desired PWM value
developer. Example 5-1 through Example 5-3 SWAPF a,w ;This macro will
;change w
show three macros written for the mid-range ANDLW 0x30
product family that can be used to set the PWM IORLW 0x0F
period. The first macro takes a 16-bit value and MOVWF CCP1CON
uses the 10 MSb’s to set the PWM period. The RLF a,w
IORLW 0x0F
second macro takes a 16-bit value and uses the MOVWF pwm_tmp
10 LSb’s to set the PWM period. The last macro RRF pwm_tmp,f
takes 8 bits and sets the PWM period. This RRF pwm_tmp,w
assumes that the CCP is configured for no more MOVWF CCPR1L
than 8 bits.
Example 5-3: 8-Bit Macro
Example 5-1: Left Justified 16-Bit Macro
pwm_tmp equ xxx ;this variable must be
pwm_tmp equ xxx ;this variable must be ;allocated someplace
;allocated someplace setPeriod macro a ;a is 1 SFR
setPeriod macro a ;a is 2 SFR’s in SWAPF a,w ;This macro will
;Low:High arrangement ;change w
;the 10 MSb’s are the ANDLW 0x30
;desired PWM value IORLW 0x0F
RRF a,w ;This macro will MOVWF CCP1CON
;change w RRF a,w
MOVWF pwm_tmp MOVWF pwm_tmp
RRF pwm_tmp,w RRF pwm_tmp,w
ANDLW 0x30 MOVWF CCPR1L
IORLW 0x0F
MOVWF CCP1CON
MOVF a+1,w
MOVWF CCPR1L
Ferrite
Toroid
ADC
Hall
PIC® MCU Effect
or Sensor
dsPIC® DSC M
CCP
NOTES:
NOTES:
www.microchip.com
Microchip Technology Inc. • 2355 W. Chandler Blvd. • Chandler, AZ 85224-6199
Information subject to change. The Microchip name and logo, the Microchip logo, dsPIC, MPLAB, PIC, PICmicro and PICSTART are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other countries. FilterLab, MXDEV and MXLAB are registered trademarks of Microchip Technology Incorporated
in the U.S.A. ICSP, MPASM, MPLIB, MPLINK, PICkit, PICDEM, PICDEM.net and PICtail are trademarks of Microchip Technology Incorporated in the U.S.A. and
other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective
companies. © 2008, Microchip Technology Incorporated. All Rights Reserved. Printed in the U.S.A. 2/08