2004 Microchip Technology Inc.
DS00908A-page 23
AN908
}
// zero out i sums
PIParmD.qdSum = 0;
PIParmQ.qdSum = 0;
PIParmQref.qdSum = 0;
iMaxLoopCnt = 0;
Wrt_S_LCD("Vector Control ", 0 , 0);
Wrt_S_LCD("S4-Run/Stop ", 0, 1);
// Enable ADC interrupt and begin main loop timing
IFS0bits.ADIF = 0;
IEC0bits.ADIE = 1;
if(!uGF.bit.RunMotor)
{
// Initialize current offset compensation
while(!pinButton1) //wait here until button 1 is pressed
{
ClrWdt();
// Start offset accumulation //and accumulate current offset while waiting
MeasCompCurr();
}
while(pinButton1); //when button 1 is released
uGF.bit.RunMotor = 1; //then start motor
}
// Run the motor
uGF.bit.ChangeMode = 1;
// Enable the driver IC on the motor control PCB
pinPWMOutputEnable_ = 0;
Wrt_S_LCD("RPM= ", 0, 0);
Wrt_S_LCD("S5-Cls. Lp S6-2x", 0, 1);
//Run Motor loop
while(1)
{
ClrWdt();
// If using OC7 and OC8 to display vector control variables,
// call the update code.
#ifdefDIAGNOSTICS
DiagnosticsOutput();
#endif
// The code that updates the LCD display and polls the buttons
// executes every 50 msec.
if(iDispLoopCnt >= dDispLoopCnt)
{
//Display RPM
Dis_RPM(5,0);
// Button 1 starts or stops the motor
if(pinButton1)
{
if( !uGF.bit.Btn1Pressed )
uGF.bit.Btn1Pressed = 1;
}
else