emufambirwi
Member
Hello Forum members,
I am implementing a slow starter circuit for AC inductive loads. For this, I am using a Zero Crossing Detection scheme with a Pic 16f887. The zero crossing is detected as an external interrupt on RB0 and voltage across the load is reduced by firing a TRIAC just after the zero crossing. My problem is that I need to bypass the TRIAC after counting 100 zero crossings but it's not happening with my code. I need you to assist me in correcting the code
I am implementing a slow starter circuit for AC inductive loads. For this, I am using a Zero Crossing Detection scheme with a Pic 16f887. The zero crossing is detected as an external interrupt on RB0 and voltage across the load is reduced by firing a TRIAC just after the zero crossing. My problem is that I need to bypass the TRIAC after counting 100 zero crossings but it's not happening with my code. I need you to assist me in correcting the code
C++:
int cnt; // counter variable to store zero crossing count
unsigned char FlagReg;
sbit ZC at FlagReg.B0;
void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
cnt++;
INTCON.INTF = 0;
}
}
void fire() {
PORTD.B0 = 1; //Send a 1ms pulse
delay_us(500);
PORTD.B0 = 0;
}
void main() {
TRISA = 0;
PORTA = 0;
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTD = 0;
TRISD = 0; //PORTD all output
ANSEL = 0; // make ports digital (lower order)
ANSELH = 0; // make ports digital (higher order)
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
cnt =0;
do {
if (ZC){ //zero crossing occurred
delay_ms(1);
fire();
ZC = 0;
}
} while(cnt<=100);
PORTD = 0b00000010;
}