
2004 Microchip Technology Inc. DS00900A-page 9
AN900
INITIALIZING THE QUADRATURE ENCODER
INTERFACE
When implementing closed-loop V/f control, a form of
velocity feedback is required. The Quadrature Encoder
Interface can be used in conjunction with Timer5 to
provide very accurate velocity feedback and direction
information. In Velocity Measurement mode, velocity
event pulses are generated on each edge of the QEA
signal. Timer5 counts upward and its value is captured
on each velocity pulse when it is reset to zero. The
captured Timer5 value is stored in the Velocity registers
(VELRH:VELRL), which is used by V/f control with
Velocity Feedback mode.
To enable velocity measurement:
1. Configure the QEI module for Velocity mode
measurement:
a) Enable Velocity mode (clear the VELM
bit).
b) Set the QEI module mode to one of the 2x
capture configurations.
c) Set the pulse reduction ratio to 1:1.
2. Configure Timer5 as the QEI time base:
a) Disable the Timer5 special event Reset.
b) Enable Continuous Count mode.
c) Set the input clock prescaler to 1:1.
d) Enable Synchronous Timer mode.
e) Enable the timer.
3. Enable the Timer5 interrupt and set as low priority
V/f CONTROL FIRMWARE
The heart of the ACIM control is accomplished with the
PCPWM peripheral operated in Complimentary mode.
The duty cycle of the three PWM channels are changed
in a regular manner using a Timer0 interrupt to
synthesize the three-phase waveforms that drive the
motor.
A sine table is stored in program memory. It is trans-
ferred to data memory during initialization for faster
access. Three registers are used as offsets to the table
through indirect addressing. Each of the offset values
points to one of the values in the table, such that there
is always a 120-degree phase shift between the
phases. (Each of the waveforms in Figure 3 is created
by an offset register associated with its PWM.) The
code sample in Example 1 shows how the table is read
using the indirect addressing registers.
In this application, the potentiometer determines the
target motor speed reference signal. Waveform synthe-
sis is identical for open-loop V/f and V/f with velocity
feedback. The difference lies in how the motor drive
frequency is generated from the target frequency.
Depending upon the control strategy, the reference
signal from AN1 is used in one of two ways:
DRIVE FREQUENCY CALCULATION FOR
OPEN-LOOP V/f CONTROL
In this method, the motor drive frequency is directly
calculated from the potentiometer input. Specifically, the
upper byte of the A/D Result register is divided by four to
give the target drive frequency f in Hz. In this application,
the target speed has a lower boundary of 12 Hz and an
upper boundary of 60 Hz. The V/f function determines
the drive amplitude corresponding to that frequency.
Since the synchronous speed (in RPM) for an induction
motor is 120 f/p, where p is the number of stator poles,
the target drive speed (in RPM) can be directly calcu-
lated as 30 times the value of ADRESH (120 divided by
times ADRESH divided by 4), divided by p. For the
current application, a motor with two stator poles is
assumed. This reduces to a motor speed equal to 15
times ADRESH.
EQUATION 1: CALCULATING DRIVE
FREQUENCY AND SPEED
EXAMPLE 1: ACCESSING THE SINE TABLE THROUGH INDIRECT ADDRESSING
f
target
= (ADRESH/4)
(5 ≤ f
target
≤ 60)
Drive Frequency:
N
s
= (120/f • p) × (ADRESH/4) = (30 • ADRESH)/p
Calculated Speed:
UPDATE_PWM_DUTYCYCLES ;first update PWM1
MOVF TABLE_OFFSET1,W ;place offset for first sine value inWREG
MOVF PLUSW0,W ;use the value in WREG as an offset to FSR0
;FSR0 points to beginning of sine table
;value at sine_table + table_offset1
;is copied to WREG
BZ PWM1_IS_0 ;check to see if value is 0
MULWF FREQUENCY ;multiply the table value times the frequency
MOVFF PRODH,PDC0H_TEMP ;copy the result to the duty cycle register
MOVFF PRODL,PDC0L_TEMP
BRA UPDATE_PWM2 ;continue on to update PWM2
PWM1_IS_0 ;If table value is zero,
MOVLW 0x02 ; make the duty-cycle a small non-zero value
MOVWF PDC0L_TEMP
;continue on to update PWM2
Comentarios a estos manuales