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 support@ccsinfo.com

A/D problem

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



Joined: 24 Apr 2010
Posts: 75
Location: Islamabad

View user's profile Send private message Send e-mail

A/D problem
PostPosted: Thu Oct 21, 2010 11:12 pm     Reply with quote

Hi. I am using PIC16F877A. I want to use 2 A/d channels at the same time. One for temp sensor and other for voltage measurements (simple a variable resistor).
The problem is one both are not independent (I guess).
Voltmeter value is changing with temp sensor value.

This is my code
Code:

void main()
{
float value;
float volts;
int decic,TC,TF,decif;
float tempc,read,tempf;

setup_port_A( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
   
lcd_init();

do{
set_adc_channel(1);
read = Read_ADC();

tempc=read*1.5;

tempf=(1.8*tempc)+32;

lcd_gotoxy(1,2);
printf(lcd_putc,"Temp %f C",tempc);

set_adc_channel(0);
value = Read_ADC();
volts= value/51;

lcd_gotoxy(1,1);
printf(lcd_putc,"Volts %f",volts);

   } while (TRUE);
}

Please kindly help me with this problem.
thanks
_________________
...
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Oct 22, 2010 1:45 am     Reply with quote

if you look at CCS help it will tell you what is wrong!

You need a 10us delay after switching channels :-

Code:

set_adc_channel(2);

delay_us(10);

value = read_adc();


The delay may need tweaking depending on your hardware.
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