Continue to Site

# Problem with reading two ADCs together with PIC16F877A

Status
Not open for further replies.

#### sush

##### Member level 4
simple adc problem pic

hi
m trying to read two adcs together using PIC16F877A ( 6 adc inputs

have to be read at a time so i have taken adcon1 = 10001001) . but for

testing purpose only intitailly m giving +5v to AN0 and 0V to AN1 and

on display m getting 05 for AN0 and 0000 for AN1. if i give +5 v to

both the input pins of adc ...i get 1023 and 1023.

help me out to find tHe error.

Re: simple adc problem pic

Hope to not be blind. When I start writing the message it was a sample code.
Now it's lost. I don't know why.

if i give +5 v to
both the input pins of adc ...i get 1023 and 1023.

There is no error here.
Because you set adcon1 = 10001001 VREF+ and VREF- are tied to VDD respectively to VSS.
Thus for 10bits resolution and +5v applied to AN0 and AN1, ADRESH = 00000011 and ADRSL = 11111111 that is 1023 after conversion hex to decimal (www.piclist.com)
I know that you're expecting to receive 5v on display as a result of +5V applied on AN0 rather than 1023.
The conversion formula is ADRESH:ADDRESL = 1023 * (AN0 / VREF+) assuming VREF- tied to VSS.
Now if you fill the variable in formula you'll get for VREF+ = VDD = +5V
- for AN0 = +5.000v ADRESH=00000011 and ADRESL=11111111 on display 1023
- for AN0 = 0.000v ADRESH=00000000 and ADRESL=00000000 on display 0000
- for AN0 = +2.502v ADRESH=00000001 and ADRESL=00000000 on display 0512
- for AN0 = +0.004v ADRESH=00000000 and ADRESL=00000001 on display 0001
and so on....

If you knew about these conversion and you've defined an error :
intitailly m giving +5v to AN0 and 0V to AN1 and
on display m getting 05 for AN0 and 0000 for AN1
then indeed you should get 1023 for AN0 and 0000 for AN1
As you probably notice in my conversion results examples I've kept the display according to your prefference LEADZ flag set.
You said "getting 05 for AN0". I don't see leading zeros. You mean 0005 or 0050 ? Anyway it should be 1023 for AN0 tied to +5v

Re: simple adc problem pic

Since the ADC of pic is 10-bit which has 1024 steps and if ur Vref is 5 volts then for an input of 5 V the ADC register will have the value of 1023.

V
Points: 2