
2004 Microchip Technology Inc. DS00900A-page 5
AN900
FIRMWARE OVERVIEW
In this section, we will see in greater detail how the
three control approaches discussed above are
implemented in firmware. The firmware structure can
be viewed in the flow diagrams shown in Figures 6
and 7. Keep in mind that these descriptions apply to the
specific control applications written for Microchip’s
PICDEM MC demonstration board, particularly with
regards to motor control and Fault display.
Initialization
The initialization routine sets the port pins to the
desired states and initializes the peripherals. The
High-Speed ADC, Power Control PWM, hardware
Fault inputs and Quadrature Encoder Interface are
initialized according to the control strategy that is being
implemented (i.e., V/f, V/f with current feedback, V/f
with current and position feedback). Initialization of
these peripherals is discussed in detail below.
Main Loop
The main loop (see Figure 6) continuously checks
Fault status and for key activity. Faults are handled by
the Fault service routine; status is indicated by blinking
LEDs 1 through 3.
Motor control is handled by the key service routine. Two
push button switches toggle the motor between Run and
Stop states and forward and reverse direction. When
switching directions, the motor is first allowed to coast
from its present angular velocity to zero and then accel-
erated to the reference speed in the opposite direction.
This controlled manner of changing directions prevents
high-current transients that could cause a Fault,
provided that the acceleration rate is set appropriately
for the motor. If PID control is being used, some of the
PID functions may be calculated in this loop.
Key Activity Monitoring
SW1 and SW2 are monitored and debounced in firm-
ware. SW1 is used to toggle between Run and Stop.
SW2 is used to toggle between forward and reverse.
(Figure 6). This is a subroutine within the main loop.
Fault Signals
Three Fault signals are monitored: overcurrent, over-
voltage and overtemperature. The overcurrent and
overvoltage Faults use the hardware Fault inputs to
directly inhibit the PCPWM outputs on a cycle-by-cycle
basis.
OVERCURRENT FAULT
A shunt resistor in the negative DC bus gives a voltage
proportional to the current flowing through the three
motor phases. This voltage is amplified and compared
with a reference signal using an external comparator.
On the PICDEM MC board, the reference signal may
be adjusted for a current up to 6.3A. If the DC bus
current signal exceeds the reference level, the Fault A
pin is driven low, indicating an overcurrent Fault.
Channel A is configured in Cycle-by-Cycle Fault mode.
If the Fault occurs more than 20 times in 256 PWM
cycles, then the motor is stopped and an overcurrent
Fault is indicated by blinking LED1.
OVERVOLTAGE FAULT
The DC bus voltage is attenuated using a voltage
divider and compared with a fixed reference signal
using an external comparator. On the PICDEM MC
board, when jumper JP5 is open, the overvoltage is set
to 200V on the DC bus. If jumper JP5 is shorted, then
the overvoltage limit is 400V. The Fault B pin is used to
monitor the overvoltage condition. If the Fault occurs
more than 20 times in 256 PWM cycles, the motor is
stopped and an overvoltage Fault is indicated by
blinking LED2.
OVERTEMPERATURE FAULT
The power module on the PICDEM MC board has a
Negative Temperature Coefficient (NTC) thermal sen-
sor that monitors the junction temperature of the IGBTs.
It gives a 3.3V output for a 110°C junction temperature.
The NTC is connected to AN8 through an analog opto-
coupler and is continuously measured. If it exceeds
80°C, the motor is stopped and an overtemperature
Fault is indicated by blinking LED3.
ISR Loop
The ISR loop handles interrupts from the HSADC, Fault
inputs, QEI and time-base interrupts for three-phase
waveform synthesis and PID control loop.
A/D Channel Conversion
AN0, AN1 and AN8 are converted sequentially using
the high-speed ADC. AN0 is used to measure the DC
bus current. AN1 is used as the input for the speed ref-
erence. AN8 is used to measure the power module
junction temperature for detecting the overtemperature
Fault condition.
Comentarios a estos manuales