Is it the code you are referringHi,
If you use the 'zc' pulse you would not use the compare function.
You would use PORTB.0 on change interrupt.
E
Code:
unsigned char FlagReg;
sbit ZC at FlagReg.B0;
void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
INTCON.INTF = 0;
}
}
void main() {
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTD = 0;
TRISD = 0; //PORTD all output
OPTION_REG.INTEDG = 0; //interrupt on falling edge
INTCON.INTF = 0; //clear interrupt flag
INTCON.INTE = 1; //enable external interrupt
INTCON.GIE = 1; //enable global interrupt
while (1){
if (ZC){ //zero crossing occurred
PORTD.B0 = 1; //Send a 1ms pulse
delay_ms(1);
PORTD.B0 = 0;
ZC = 0;
}
}
}
Code:
void main()
{
TRISC = 0; //Configure PORTC as ouput
TRISA.RA0=1; // Configure as input pin for negative input of Comparator 1
TRISA.RA1=1; // Configure as input pin for negative input of Comparator 2
TRISA.RA2=1; // Configure as input pin for positive input of Comparator 1
TRISA.RA3=1; // Configure as input pin for positive input of Comparator 2
TRISA.RA4=0; // Configure as output pin for output of Comparator 1
TRISA.RA5=0; // Configure as output pin for output of Comparator 2
CMCON=0x05; // 'Two Common Reference Comparators with Outputs' Mode
while(1)
{
PORTC.F0 = CMCON.C2OUT; // Assigning output of comparator 2 to RC0
PORTC.F1 = CMCON.C1OUT; // Assigning output of comparator 2 to RC1
Delay_ms(100);
}
}
Last edited:
