Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic16f676 adc problem no problem with pic16f684

Status
Not open for further replies.

zeroskj1988

Member level 2
Joined
Jul 7, 2011
Messages
46
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,588
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);
}
 

Which compiler is this? I'm guessing Hi-Tech C.

Did you select the device properly in the compiler? Did you select the appropriate configuration bits?

---------- Post added at 02:39 ---------- Previous post was at 02:38 ----------

Make sure you have 16F676 selected in the compiler rather than 16F684.
 

i am using ccs compiler.program is working some times.but not every time.can u spot any error on program or any special difference in program from 684
 

If it works all the time for 16F684, then code isn't wrong. There might be a problem in the settings you selected. What configuration settings did you use?
 

i am using this cofiguration

#include <16F676.h>
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection

#use delay(clock=20000000)//,RESTART_WDT)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top