static unsigned char Qa = 0;
static unsigned char Qb = 0;
static unsigned int ChanA [] = { 1500, 1500, 1500, 1500,
1500, 1500, 1500, 1500,
1500, 20000 };
static unsigned int ChanB [] = { 1500, 1500, 1500, 1500,
1500, 1500, 1500, 1500,
1500, 20000 };
void isr_hi ()
{
/****************************************************************
* K8LH Crazy-18 Hi-Rez 18-chan Dual 74HC4017 Servo Algorithm *
****************************************************************/
if (PIR1bits.CCP1IF == 1) // if CCP1 "compare" interrupt
{
CCPR1H++; // avoid false update "match"
CCPR1 += ChanA[Qa]; // update "compare" int value
CCPR1H--; // fix CCPR1H
LATCbits.LATC2 = 0; // clear CCP1 "CLK" line
PIR1bits.CCP1IF = 0; // clear CCP1 interrupt flag
ChanA[9] -= ChanA[Qa++]; // adjust end-of-period off time
if (Qa = 10) // if end-of-period
{ Qa = 0; // reset Qa array index
ChanA[9] = 20000; // reset 20.0-msec period and
LATAbits.LATA0 = 1; // toggle 74HC4017 "CLR" line
LATAbits.LATA0 = 0; // to force Q0 output sync'
}
}
if (PIR2bits.CCP2IF == 1) // if CCP2 "compare" interrupt
{
CCPR2H++; // avoid false update "match"
CCPR2 += ChanB[Qb]; // update "compare" int value
CCPR2H--; // fix CCPR2H
LATCbits.LATC1 = 0; // clear CCP2 "CLK" line
PIR2bits.CCP2IF = 0; // clear CCP2 interrupt flag
ChanB[9] -= ChanB[Qb++]; // adjust end-of-period off time
if (Qb = 10) // if end-of-period
{ Qb = 0; // reset Qb array index
ChanB[9] = 20000; // reset 20.0-msec period and
LATAbits.LATA1 = 1; // toggle 74HC4017 "CLR" line
LATAbits.LATA1 = 0; // to force Q0 output sync'
}
}
}