View previous topic :: View next topic |
Author |
Message |
seanbb
Joined: 10 Jan 2007 Posts: 5
|
PIC12F510 ADC Problem |
Posted: Wed Jan 10, 2007 3:42 am |
|
|
Hi, I use PIC12F510 and MCP9700 temperature sensor.
I have connect MCP9700 Vout to 12F510 GPIO2.
GPIO2 is configue as the analog input.
I could get some value in ADRES, but it's not stable, always change.
Do I get the correct data from the MCP9700? Anyone could give me a help?
Thanks |
|
|
seanbb
Joined: 10 Jan 2007 Posts: 5
|
|
Posted: Wed Jan 10, 2007 3:45 am |
|
|
#if defined(__PCB__)
#include <12f510.h>
#include <stdlib.h>
//#include <delay.c>
#fuses INTRC, NOWDT,NOPROTECT,NOMCLR
#use delay(clock=4000000)
#endif
void init(void);
char check_input(void);
char input_stat;
char adc_value; //sean
void main()
{
init();
while (TRUE)
{
if(INPUT(PIN_B3)==0)
{
check_input();
if(input_stat == 0) //no input signal
{
OUTPUT_HIGH(PIN_B2);
delay_ms(500);
OUTPUT_LOW(PIN_B2);
}
}
set_adc_channel(2);
delay_us(20);
adc_value = read_adc();
}
}
void init()
{
SET_TRIS_b(0x08);
#if defined(__PCB__)
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
#else
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
#endif
output_low(PIN_B2);
input_stat = 0;
setup_adc_ports(AN2); // Setup ADC to AN0
setup_adc(ADC_ON); // Set ADC On
}
char check_input()
{
char i;
for(i=0;i<10;i++)
{
delay_ms(100);
if(INPUT(PIN_B3) == 1)
{
input_stat=1;
return input_stat;
}
}
input_stat = 0;
return input_stat; //no input signal
} |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 10, 2007 9:10 am |
|
|
A number of comments:
1) Use the tick box 'disable HTML in this post', when posting code.
2) Use the code buttons when posting code.
3) I don't see you setting the ADC clock rate. Set this to meet the spec for Tad in the data sheet.
4) How stable is your supply, and the voltage coming in?. Have you got the decoupling capacitor recommended on the 9700 data sheet?.
Best Wishes |
|
|
|