Controlling DC Brushless Motors with PIC17C756A (Microchip AN718, 1999).pdf
(
769 KB
)
Pobierz
AN718
Brush-DC Servomotor Implementation using PIC17C756A
An RS-232 interface is the primary means of communi-
cation with the MCU. One of the two available USARTs
on the MCU is used for this purpose. The operation of
the motor is controlled and monitored from a host sys-
tem using ASCII commands.
One of the three available pulse-width modulation
(PWM) modules on the MCU is used to generate the
motor drive signal. The PWM frequency is 32.2 kHz at
a device operating frequency of 33 MHz and the mod-
ule provides 10 bits of resolution. The torque applied to
the motor is determined by the PWM duty cycle. The
PWM signal is connected to a ‘H’-bridge power ampli-
fier capable of delivering up to 3A to the DC motor.
A Pittman Inc. 9234 series motor is used in this design.
The motor has a no-load speed of 6151 RPM at 24
volts input and a torque constant of 5.17 oz-in/A (with-
out gearbox). The peak stall current is 8.11A. A 5.9:1
ratio gearbox is installed on the output shaft.
A Hewlett Packard HEDS-9140 rotary optical encoder
is mounted on the rear of the motor with a 500 count-
per-revolution (CPR) encoder wheel mounted on the
shaft. The encoder provides two pulse outputs that are
in phase quadrature and a third index output that can
be used to align the motor shaft to a reference position.
To save space, a stackable printed circuit board (PCB)
system was designed that allows two PCBs to be
mounted on top of the motor (see Figure 1). The bot-
tom PCB contains a 5V regulator, motor driver, encoder
interface, and limit switch buffer circuitry. The upper
PCB contains the PIC17C756A MCU, crystal, RS-232
interface, and reset button.
Author:
Stephen Bowling
Microchip Technology Inc.
INTRODUCTION
This application note demonstrates the use of a
PIC17C756A microcontroller (MCU) in a brush-DC ser-
vomotor application. The PIC17CXXX family of micro-
controllers makes an excellent choice for cost-effective
embedded servomotor control applications. Some of
the benefits of the PIC17CXXX MCU family include fast
instruction cycle execution (up to 120 ns), an 8 x 8
hardware multiplier, and many useful hardware periph-
erals. The application hardware is shown in Figure 1.
FIGURE 1:
DC SERVOMOTOR
APPLICATION HARDWARE
HARDWARE DESCRIPTION
SYSTEM OVERVIEW
The design makes extensive use of the hardware
peripherals available on the PIC17C756A. The periph-
erals used in this application are summarized in
Ta bl e 1 .
A complete schematic diagram for the application is
given in Appendix A.
A block diagram of the servomotor system is provided
in Figure 2. The system is comprised of the following
elements:
• PIC17C756A MCU
• RS-232 Interface
• Power Amplifier
• Brush-DC Motor & Rotary Encoder
The MCU is responsible for communications with the
host system, measuring the motor position, calculating
the compensation algorithm and motion profile, and
producing the drive signal sent to the power amplifier.
ã
1999 Microchip Technology Inc.
DS00718A-page 1
AN718
TABLE 1:
PIC17C756A PERIPHERAL
USAGE FOR DC SERVOMOTOR
APPLICATION
Peripheral
Function
TMR0
Used as a counter to maintain the
incremental up-count from the motor
position encoder
TMR1
PWM1 time-base
TMR2
Servo update time-base
TMR3
Used as a counter to maintain the
incremental down-count from the
motor position encoder
PWM1
Generates drive signal for DC motor
USART1
Terminal communications
I/O
Encoder index signal, PWM ampli-
fier enable, limit switch inputs
FIGURE 2:
DC SERVOMOTOR BLOCK DIAGRAM
V
+
Power Amplifier
PIC 17C756A MCU
RX
TX
RS-232
Transceiver
PWM1
T0CKI
TCLK3
Encoder
Interface
Position Feedback
DC Motor/Encoder
DS00718A-page 2
ã
1999 Microchip Technology Inc.
AN718
Motor Position Feedback
Referring to the schematic diagrams (Figure A-1 to
Figure A-3), the outputs of the rotary encoder are con-
nected to 2.7k pull-up resistors, filtered using RC net-
works, and buffered by Schmidt trigger inverters
U5A - U5C. The outputs of the rotary encoder include
two quadrature outputs and a third index output that is
used to align the shaft of the motor to a known refer-
ence position. The conditioned index signal is con-
nected to I/O pin RF0 of the MCU.
The conditioned quadrature outputs from the rotary
encoder are connected to D flip-flops U6A and U6B.
These D flip-flops decode the quadrature pulse train
into up and down pulse outputs. A timing diagram indi-
cating the operation of the decoder circuit is shown in
Figure 3.
A simplified schematic diagram of the encoder inter-
face is shown in Figure 4. The MCU accumulates the
total distance traveled between servo updates based
on the up and down pulse outputs from U6A and U6B.
To accomplish this, Timer0 and Timer3 are configured
as counters with external clock inputs. The output of D
flip-flop U6A (up pulses) is connected to the Timer0
external clock input and the output of D flip-flop U6B
(down pulses) is connected to the Timer3 external
clock input. Each of these timer registers is 16 bits
wide.
Three external logic inputs are provided at connector
J4 on the motor driver PCB and are intended for
mechanical limit switch sensing. These inputs could
also be used to activate certain motor functions. The
inputs are filtered and buffered by U5D – U5F similar to
the encoder interface circuitry. The conditioned limit
switch signals are connected to I/O pins RF1, RF2, and
RF3 of the MCU.
PWM Amplifier
Integrated circuit U1 is an H-bridge driver that uses
DMOS output devices and can deliver up to 3A output
current at supply voltages up to 52V. The device has an
internal charge pump for driving the high-side transis-
tors and dead-time circuitry to prevent cross-conduc-
tion of the output devices. Each side of the bridge may
be driven independently and the inputs are TTL com-
patible. An enable input and automatic thermal shut-
down are also provided. A transient voltage suppressor
is connected across the motor terminals to prevent volt-
age spikes generated by the motor inductance from
damaging the bridge.
The PWM1 output from the MCU is buffered through
inverters U3A, U3B, and U3D and connected to both
sides of the H-bridge driver IC. One side of the bridge
is driven with a inverted PWM signal. By driving the
bridge in this manner, the motor may be turned in either
direction depending on the PWM duty cycle. A 50%
PWM duty cycle will produce zero motor torque. A
100% duty cycle will produce maximum motor torque in
the forward direction, while a 0% duty cycle will pro-
duce maximum motor torque in the opposite direction.
An enable signal from I/O pin RF4 of the MCU is con-
nected to the bridge driver through inverter U3C. This
signal turns the output of the PWM amplifier on or off.
FIGURE 3:
ENCODER TIMING
Motor Reverses Direction Here
ENC. CH. A
ENC. CH. B
Up Count
Down Count
ã
1999 Microchip Technology Inc.
DS00718A-page 3
AN718
FIGURE 4:
SIMPLIFIED ENCODER INTERFACE SCHEMATIC
PIC17C756A
U6A
+5
ENCODER
PR
Up
A
Q
D
RA1/T0CKI
Timer0
74HC74
B
C
Q
CLR
+5
U6B
PR
Down
D
Q
Timer3
RB5/TCLK3
74HC74
C
Q
CLR
Servo Update Timing
The servo update calculations are performed in an
interrupt service routine and are synchronized with the
output of PWM1. This is desirable because the duty
cycle is updated at multiples of the PWM period. The
PWM1 output is connected to the TCLK12/RB4 pin and
is used as a clock source for Timer2. Timer2 has an
associated period register, PR2. When the value of
Timer2 is equal to the value loaded in PR2, Timer2 is
reset to 0 and an interrupt is generated. By adjusting
the value in PR2, the servo update frequency may be
adjusted to any ratio of the PWM1 output. At a device
operating frequency of 33 MHz, the frequency of
PWM1 is 32.2 kHz. A 3.9 kHz servo update frequency
will be achieved with the value in PR2 set to 8.
RS-232 Transceiver
The TX and RX pins of USART1 are connected to a
Dallas Semiconductor DS275 RS-232 transceiver. The
chip was selected for its small size and because it is
line-powered. The chip uses power from the receive
input to generate the correct RS-232 voltage levels
while transmitting. To save space, RS-232 connections
are made through a RJ-11 connector on the MCU PCB.
Power Supply
Voltage regulator VR1 provides 5 volts to the MCU, RS-
232 driver, interface logic, and the rotary encoder. The
system is designed to operate at any supply voltage
between 10 volts and 24 volts. The supply voltage is
connected directly to the PWM amplifier.
DS00718A-page 4
ã
1999 Microchip Technology Inc.
AN718
SOURCE CODE
The source code is written in the C programming lan-
guage for ease of implementation and was compiled
using the MPLAB-C17™ compiler. A complete source
code listing for the application has been provided in
Appendix B.
The source code performs four basic functions:
• RS-232 communication
• Motor position measurement
• Compensator algorithm calculation
• Motion profile calculation
All functions, except the RS-232 communications are
performed in an interrupt service routine.
RS-232 Communications
The DC motor software allows control of the motor
operating mode and parameter changes via a remote
terminal with a RS-232 link operating at 19.2 kbaud. All
RS-232 communication takes place in the main pro-
gram loop. The USART1 reception interrupt flag
(RC1IF) is polled to detect when a character has been
received. Each received character is stored in a buffer,
echoed to the USART, and the buffer index is incre-
mented. This continues until the buffer is full or a
<CR> is received. After a <CR> is received, the buffer
contents are checked for numerical or command data
and a ‘READY>’ prompt is sent to the terminal. If the
command is not recognized, an error message is sent
out.
Servo Updates
The servo calculations are performed each time a
Timer2 interrupt occurs. A flowchart of the servo inter-
rupt service routine (ISR) is shown in Figure 5.
32-bit Operations
This application makes extensive use of 32-bit values.
Since MPLAB-C17 does not provide direct support for
32-bit variable types, the 32-bit variables used in the
program are declared as unions. The use of a union in
the C programming language allows multiple variable
types to share the same data space. A union with the
name of ‘LONG’ has been declared in the source code.
The union LONG consists of an array of four characters
and an array of two integers. Therefore, any variables
that are declared with this data type may be manipu-
lated as four bytes or two integers. Additionally, the
contents of the entire union may be copied to another
location by simply assigning it to another union of the
same type.
Position Updates
During each servo update period, the function
UpdatePosition()
is called. The count values in
Timer0 and Timer3 are used to find the total motor dis-
tance traveled during the previous servo update period.
The counters are never cleared to avoid the possibility
of losing count information. Instead, the values of the
Timer0 and Timer3 registers saved during the previous
sample period are subtracted from the present values
using two’s-complement signed arithmetic. This calcu-
lation provides the total number of up and down pulses
accumulated during the servo update period. The use
of two’s complement arithmetic accounts for a timer
overflow that may have occurred since the last read.
The down pulse count is then subtracted from the up
pulse count, which provides a signed result indicating
the total distance (and direction) traveled during the
sample period. This value also represents the mea-
sured velocity of the motor in encoder counts per servo
update period and is stored in the variable
mvelocity
.
The measured position of the motor is stored in the
union
mposition
. The upper 24 bits of
mposition
holds the position of the motor in encoder counts. The
lower eight bits of
mposition
represent fractional
encoder counts. The value of
mvelocity
is added to
mposition
at each servo update period to find the
new position of the motor. With 24 bits, the absolute
position of the motor may be tracked through 33,554
shaft revolutions using a 500 CPR encoder. The size of
mposition
can be increased as necessary to track
greater distances.
ã
1999 Microchip Technology Inc.
DS00718A-page 5
Plik z chomika:
gasma
Inne pliki z tego folderu:
Controlling DC Brushless Motors with PIC17C756A (Microchip AN718, 1999).pdf
(769 KB)
PIC16c84 Programmer (Schematic).pdf
(81 KB)
PIC16F876 DMX512 to Analog Voltage Converter (Schematic).pdf
(328 KB)
Inne foldery tego chomika:
PIC_Microcontroller_Book__2
Zgłoś jeśli
naruszono regulamin