CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC12F510 ADC Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
seanbb



Joined: 10 Jan 2007
Posts: 5

View user's profile Send private message

PIC12F510 ADC Problem
PostPosted: Wed Jan 10, 2007 3:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 10, 2007 3:45 am     Reply with quote

#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







PostPosted: Wed Jan 10, 2007 9:10 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group