View previous topic :: View next topic |
Author |
Message |
Onur Guest
|
ADC problem on 16F877 |
Posted: Sun Apr 11, 2004 9:57 am |
|
|
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
|
|
Posted: Sun Apr 11, 2004 10:02 am |
|
|
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
|
Re: ADC problem on 16F877 |
Posted: Sun Apr 11, 2004 11:01 am |
|
|
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
|
|
Posted: Sun Apr 11, 2004 1:31 pm |
|
|
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
|
|
Posted: Sun Apr 11, 2004 9:04 pm |
|
|
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 |
Posted: Mon Apr 12, 2004 3:05 am |
|
|
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 |
|
|
|