cool.man
Full Member level 6
Hi Guys
I am trying to simulate a simple circuit called Dimmer Circuit. I wrote some lines for PIC16F877A microcontroller. I want to swtich Triac based on microcontroller output. Partially it is working fine. Negative portion of AC source is operating as desired but Positive portion of AC source is not operating, Can you look into the circuit and guide me where is the problem?
Channel A -> Zero Crossing Signal
Channel B -> AC Source
Channel C -> Microcontroller signal to TRIAC
Channel D -> Actual output
following is the code
Kindly have a look and guide me
Thanks
I am trying to simulate a simple circuit called Dimmer Circuit. I wrote some lines for PIC16F877A microcontroller. I want to swtich Triac based on microcontroller output. Partially it is working fine. Negative portion of AC source is operating as desired but Positive portion of AC source is not operating, Can you look into the circuit and guide me where is the problem?
Channel A -> Zero Crossing Signal
Channel B -> AC Source
Channel C -> Microcontroller signal to TRIAC
Channel D -> Actual output
following is the code
Code:
#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(crystal=20000000)
int increment_scr = 0;
#int_EXT // Zero Crossing Interrupt
void EXT_isr(void)
{
output_low(PIN_B2);
delay_ms(increment_scr);
output_high(PIN_B2);
delay_ms(1);
output_low(PIN_B2);
//delay_ms(increment_scr);
}
void main()
{
set_tris_b(0b0000001); // setting the I/O pins of port B --> 1 pin will be set as input --- 0 as digital output
enable_interrupts(INT_EXT); // enabling external interrupt
ext_int_edge(H_TO_L); // external interrupt raise when signal goes from high to low
enable_interrupts(GLOBAL); // all interrupt are enabled
while(1)
{
if(input(PIN_D0) != 1) // If push Button pressed then increment the value.
{
while(input(PIN_D0) != 1){}
if (increment_scr >=9) increment_scr = 9;
else increment_scr++;
}
if(input(PIN_D1) != 1) // If push Button pressed then decrement the value.
{
while(input(PIN_D1) != 1){}
if (increment_scr <=0) increment_scr = 0;
else increment_scr--;
}
}
}
Kindly have a look and guide me
Thanks