Hello
I have a PIC18F2420 with 20MHz crystal and c18 compiler.
I have successfully performed the simple transformer coupled halogen lamp dimming via my PIC. The PIC achieves this by controlling the firing angle of the 230V 50Hz AC waveform on the transformer HT side. The TRIAC is snubberless BTB16600BW. Below is my code sample. The method of coding works and i get very good results....that is the bulb starts from very low level dim and then brightens up gradually all the way to MAX intensity. Also the transformer NEVER heats up and everything is smooth operation. However it is not good practice to stay inside an ISR for too long as can be seen in my TMR0 Interrupt routine where the program stays for 200us for the TRIAC latching. Anything less than 200us...and the halogen lamp flickers.
To improve the efficiency, I then re-did my TMR0 Interrupt routine and optimized it so that the program does not stay inside for that long and yet the TRIAC can still be latched for the desired time. This TMR0 interrupt routine is given below. Sadly this version of the TMR0 Interrupt routine produces not a very good low level dimming result...meaning the bulb never dims too little as it SHOULD to get an overall effect of dimming.....AND the transformer heats up too quickly clearly indicating that the PIC is not in symmetry with the AC waveform.
Please can someone explain this and help me to improve the above TMR0 interrupt routine to achieve perfect dim low to high level bulb intensity without the transformer heating up?
Thank you
Haseeb
I have a PIC18F2420 with 20MHz crystal and c18 compiler.
I have successfully performed the simple transformer coupled halogen lamp dimming via my PIC. The PIC achieves this by controlling the firing angle of the 230V 50Hz AC waveform on the transformer HT side. The TRIAC is snubberless BTB16600BW. Below is my code sample. The method of coding works and i get very good results....that is the bulb starts from very low level dim and then brightens up gradually all the way to MAX intensity. Also the transformer NEVER heats up and everything is smooth operation. However it is not good practice to stay inside an ISR for too long as can be seen in my TMR0 Interrupt routine where the program stays for 200us for the TRIAC latching. Anything less than 200us...and the halogen lamp flickers.
Code:
unsigned char bulbdim = 107; //initiallize at MIN intensity
//TMR0 is prescaled to 1:256
void main()
{
while(1); //loop forever
}
void LowInterrupt (void)
{
if(INTCONbits.INT0IF == 1) //if INT0 (ZERO CROSSing) interrupt
{
bulbdim++; //brighten up intensity
if(bulbdim == 215)//MAX intensity attained
bulbdim = 107; //reset to MIN intensity
TMR0L = bulbdim; //TRIAC firing time initiallize
T0CONbits.TMR0ON = 1; //Enables Timer0
INTCONbits.INT0IF = 0; //Reset the INT0 External Interrupt Flag bit
}
if(INTCONbits.TMR0IF == 1) //If TMR0 interrupt
{
LATBbits.LATB1 = 1; //turn on TRIAC
Delay10KTCYx(1); //200us TRIAC latching delay
LATBbits.LATB1 = 0; //turn off TRIAC
T0CONbits.TMR0ON = 1; //Disable Timer0
INTCONbits.TMR0IF = 0; //Reset the TMR0 Interrupt Flag bit
}
}//end of LowInterrupt ISR
To improve the efficiency, I then re-did my TMR0 Interrupt routine and optimized it so that the program does not stay inside for that long and yet the TRIAC can still be latched for the desired time. This TMR0 interrupt routine is given below. Sadly this version of the TMR0 Interrupt routine produces not a very good low level dimming result...meaning the bulb never dims too little as it SHOULD to get an overall effect of dimming.....AND the transformer heats up too quickly clearly indicating that the PIC is not in symmetry with the AC waveform.
Code:
if(INTCONbits.TMR0IF == 1) //If TMR0 interrupt
{
if(flag == 0) //200us will lapse
{
LATBbits.LATB1 = 1; //turn on TRIAC
flag = 1; //200us will lapse
TMR0L = 4; //initiallize for 200us TRIAC latching delay
//TMR0 is prescaled to 1:256
T0CONbits.TMR0ON = 1; //Enables Timer0
}
else //200us have lapsed
{
LATBbits.LATB1 = 0; //turn off TRIAC
flag = 0; //200us have lapsed
T0CONbits.TMR0ON = 0; //Disable Timer0
}
INTCONbits.TMR0IF = 0; //Reset the TMR0 Interrupt Flag bit
}
Please can someone explain this and help me to improve the above TMR0 interrupt routine to achieve perfect dim low to high level bulb intensity without the transformer heating up?
Thank you
Haseeb