bonhome
Newbie level 4
hello i h've been working on a phase control light dimmer project with pic 16f877 microcontroller with ccs pic c compiler driving a MOC3021 optotriac
controling a lamp 220 v 50 hz .i can say that i know the principle well ,so i wrote this c code,and for some reason it does not work.
well in this case i am trying to control the lamp at 3 defrents phases 100,75,50 %
int porcentage=100;
#int_EXT
EXT_isr()
{
if(porcentage==50)
{
delay_us(4990);
output_high(PIN_C0);
delay_us(100);
output_low(PIN_C0);
// set_timer1(5000);
}
else if(porcentage==75)
{
delay_us(2480);
output_high(PIN_C0);
delay_us(100);
output_low(PIN_C0);
// set_timer1(2500);
}
else if(porcentage==100)
{
output_high(PIN_C0);
delay_us(100);
output_low(PIN_C0);
}
}
void main()
{
port_b_pullups(FALSE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(INT_EXT);
ext_int_edge( H_TO_L );
enable_interrupts(GLOBAL);
set_tris_c(0b11111110);
while(1){
}
}
so if anyone could help me i would apretiate it. thank you.
controling a lamp 220 v 50 hz .i can say that i know the principle well ,so i wrote this c code,and for some reason it does not work.
well in this case i am trying to control the lamp at 3 defrents phases 100,75,50 %
int porcentage=100;
#int_EXT
EXT_isr()
{
if(porcentage==50)
{
delay_us(4990);
output_high(PIN_C0);
delay_us(100);
output_low(PIN_C0);
// set_timer1(5000);
}
else if(porcentage==75)
{
delay_us(2480);
output_high(PIN_C0);
delay_us(100);
output_low(PIN_C0);
// set_timer1(2500);
}
else if(porcentage==100)
{
output_high(PIN_C0);
delay_us(100);
output_low(PIN_C0);
}
}
void main()
{
port_b_pullups(FALSE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(INT_EXT);
ext_int_edge( H_TO_L );
enable_interrupts(GLOBAL);
set_tris_c(0b11111110);
while(1){
}
}
so if anyone could help me i would apretiate it. thank you.