dattlara76
Junior Member level 2
I’m making a dimmer for 230V AC/50Hz bulbs. I use PIC12F675 with 1M ohm(from Neutral of AC230V) ZX detection on external interrupt pin.
When it comes to zero cross most people say that when it detects a ZX you turn on a timer & when timer expires you fire the triac. & invert the ZX edge on every half cycle. So you can catch the negative cycle as well.
For that i want to use timer1 as firing delay and INT Pin for ZC detection. MCU run internal 4MHZ. I want to use Timer0 and IOC for IR decoding.
1) ISR Init as below:
2) TIMER1 ISR as below::
Thanks
[code tags added by moderator]
When it comes to zero cross most people say that when it detects a ZX you turn on a timer & when timer expires you fire the triac. & invert the ZX edge on every half cycle. So you can catch the negative cycle as well.
For that i want to use timer1 as firing delay and INT Pin for ZC detection. MCU run internal 4MHZ. I want to use Timer0 and IOC for IR decoding.
1) ISR Init as below:
Code:
/////////////////initial ISR///////////////////
void interrupt tintr(void)
{
if(INTCONbits.INTF) //Check RB0 PIN INTERRUPT FOR ZC FLAG
{
//INT pin has detected falling
TMR1H = 0xF7;
TMR1L = 0xFF;
T1CONbits.TMR1ON=1; //timer1 on
dimmerdelay[0]=(DIMMER_MAX-dimmerspeed[0])<<1; //dimmerspeed has already updated in main()
timer1Isr();
//INT Edge change for next half cycle
if (ZERO_CROSS == 0) { OPTION_REGbits.INTEDG = 1;}
else OPTION_REGbits.INTEDG = 0;
INTCONbits.INTF =0;
}
else if(PIR1bits.TMR1IF) // check the timer1 over flow interrupt flag
{
timer1Isr(); //FLAG SET 2.048 mSec
PIR1bits.TMR1IF =0;
}
}
2) TIMER1 ISR as below::
Code:
//////////////////timer1 ISR//////////////////////////
void timer1Isr() // every 2 ms
{
if(dimmerdelay[0])
{
DIMMER_1=1;
if(!(dimmerdelay[0]&0x8000))//80
dimmerdelay[0]--;
}else
{
DIMMER_1=0;
dimmerdelay[0]=0xFFFF;
}
}
Thanks
[code tags added by moderator]
Attachments
Last edited by a moderator: