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

ADC problem on 16F877

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







ADC problem on 16F877
PostPosted: Sun Apr 11, 2004 9:57 am     Reply with quote

I wrote a adc program.. but cant understand some point...

I used 2 acd input.. first input for lm35
second inpur for 0 to 5v range ...

pic can measure lm35 out...I haven't got any problem abot this..

I connected other port potantiometer(pot)
pots wire connected +,- and adc input..

if I turn pot middle I see 0
it can measure 0v to 2.55 volt
an I continue turning I see 0 to 255

it can measure 0 to 255
I must measure 0V to 5v
it range 0-255
How to do it this?
Thank you

(I connected RA2 to gnd and RA3 to 5v)
#INCLUDE <16F877.h>
#DEVICE ADC=10
#use delay(clock=20000000)
#FUSES HS,NOWDT,NOPROTECT,NOLVP,noPUT, NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_E0, rcv=PIN_E1)

long number;
long number2;

set_tris_A(1);
void main(){


setup_port_a(RA0_RA1_ANALOG_RA3_RA2_REF);

setup_adc( ADC_CLOCK_DIV_32 );
SETUP_ADC(ADC_CLOCK_INTERNAL);



do{
set_adc_channel( 1 );
delay_ms(200);
number = Read_ADC();
delay_ms(200);

putc(number);

set_adc_channel( 0 );
delay_ms(200);
number2 = Read_ADC();
delay_ms(200);

putc(number2);


} while(true);

}
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

PostPosted: Sun Apr 11, 2004 10:02 am     Reply with quote

I think the problem is with your ADC reference voltage.

OR

I do not think the PIC ADC can measure upto +5v, if the supply to the PIC
is +5v


Hope this helps!!
_________________
Best Regards
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: ADC problem on 16F877
PostPosted: Sun Apr 11, 2004 11:01 am     Reply with quote

Onur wrote:
I wrote a adc program.. but cant understand some point...

putc(number);

putc(number2);

}


Change those lines to use a printF that can send two bytes.
Guest








PostPosted: Sun Apr 11, 2004 1:31 pm     Reply with quote

not sure what your looking for help on?

but with an 8bit a/d you get 255 levels
so you divide 5v by 255 = 20mv per level

so when it dsys 1 it is reading 20mv,
10 = 200mv
100 = 2v
.
....
......
.......
255 = 5v
Onur
Guest







PostPosted: Sun Apr 11, 2004 9:04 pm     Reply with quote

but when I turn pot I can read in the middle of the pot 0-255 and I contunue turning it starts 0 t0 255
Guest








Re: ADC problem on 16F877
PostPosted: Mon Apr 12, 2004 3:05 am     Reply with quote

Onur wrote:

#DEVICE ADC=10


You are sampling with 10 bit precision (0 to 1023).
As the others said, putc is for 8 bit only.
For the LM35 the output is 10mV/deg.C - if the temperature is below 25.5 deg. C putc will give the right number. Use printf to get the full range.

The measurement for the pot. is not in mV - it's a digital number in the range 0 to 1023. If you want to scale it to 0 to 500mV it can be done something like the following. It probably can be shortened without the compiler complaining.

int32 temp;
temp = (int32) read_adc();
temp *=500;
// Do rounding by adding half denominator
temp = (temp + 512)/1024;
printf(''Voltage is %3lu mV",temp);

HTH
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