zeroskj1988
Member level 2
hello i am using this code to detect ac voltage in pic16f676.but it is not working properly.but it working properly on 684.please spot error thanks in advance
#include <main.h>
#define mains_ok PIN_C4
#define phase_seq PIN_A2
#rom 0x2100={255,170,0}
int1 voltage_check();
void switch_check();
int16 r_volt,y_volt,b_volt,high_cutoff,low_cutoff;
int8 i,ebfail=1;
void main()
{
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(sAN5|sAN6|sAN4|VSS_VDD);
high_cutoff=read_eeprom(0);
high_cutoff=high_cutoff+10;
low_cutoff=read_eeprom(1);
while(1)
{
if(voltage_check())
//{
//if(ebfail)
//{
output_high(mains_ok);
//ebfail=0;
//}
//}
else
//{
//if(!ebfail)
//{
//for(i=0;i<15;i++)
//delay_ms(1000);
//if(!voltage_check())
//{
output_low(mains_ok);
//ebfail=1;
}
}
// }
// }
//}
int1 voltage_check()
{
int16 adc_volt;
if(!input(phase_seq))
return(0);
set_adc_channel(4);
delay_us(10);
adc_volt=read_adc();
r_volt=(adc_volt*.5635)+1;
set_adc_channel(5);
delay_us(10);
adc_volt=read_adc();
y_volt=(adc_volt*.5635)+1;
set_adc_channel(6);
delay_us(10);
adc_volt=read_adc();
b_volt=(adc_volt*.5635)+1;
if((r_volt<high_cutoff) & (y_volt<high_cutoff) & (b_volt<high_cutoff) &(r_volt>low_cutoff) & (y_volt>low_cutoff) &( b_volt>low_cutoff))
return(1);
else
return(0);
}
#include <main.h>
#define mains_ok PIN_C4
#define phase_seq PIN_A2
#rom 0x2100={255,170,0}
int1 voltage_check();
void switch_check();
int16 r_volt,y_volt,b_volt,high_cutoff,low_cutoff;
int8 i,ebfail=1;
void main()
{
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(sAN5|sAN6|sAN4|VSS_VDD);
high_cutoff=read_eeprom(0);
high_cutoff=high_cutoff+10;
low_cutoff=read_eeprom(1);
while(1)
{
if(voltage_check())
//{
//if(ebfail)
//{
output_high(mains_ok);
//ebfail=0;
//}
//}
else
//{
//if(!ebfail)
//{
//for(i=0;i<15;i++)
//delay_ms(1000);
//if(!voltage_check())
//{
output_low(mains_ok);
//ebfail=1;
}
}
// }
// }
//}
int1 voltage_check()
{
int16 adc_volt;
if(!input(phase_seq))
return(0);
set_adc_channel(4);
delay_us(10);
adc_volt=read_adc();
r_volt=(adc_volt*.5635)+1;
set_adc_channel(5);
delay_us(10);
adc_volt=read_adc();
y_volt=(adc_volt*.5635)+1;
set_adc_channel(6);
delay_us(10);
adc_volt=read_adc();
b_volt=(adc_volt*.5635)+1;
if((r_volt<high_cutoff) & (y_volt<high_cutoff) & (b_volt<high_cutoff) &(r_volt>low_cutoff) & (y_volt>low_cutoff) &( b_volt>low_cutoff))
return(1);
else
return(0);
}