Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

2 analog input with PIC

Status
Not open for further replies.

meera83

New Member
i m using PIC16F877.. i write a program that will use two potentiometer as analog input..RA0,RA1

my problem is the range value show by RA0 is ok(mean that it can show from 000-1000) , but for the same program code, when i take as input at RA1, the range value become 000-994..

when i choose to change the both RA0 and RA1 to RA1 and RA2, the both range value result show 000-994 but not 000-1000 as initially..

i would like to know whether it is the source code problem or hardware problem..

or only 1st analog pin can show accurate result..

thanks..
 
It sounds like you're using too high a source impedance?, so you have to wait before you take a reading after you've switched inputs - assuming you're just feeding the sliders of the pots directly to the PIC, what values are the pots?.
 
Nigel Goodwin said:
It sounds like you're using too high a source impedance?, so you have to wait before you take a reading after you've switched inputs - assuming you're just feeding the sliders of the pots directly to the PIC, what values are the pots?.


for the circuit, i just directly connect the both 10k potentiometer wire to PIC pin..
the connection for RA0 and RA1 are the same, but just curious that the range value show by RA1 will not same with RA0..
RA2 also can't show the final value accurate..:(

the accurate value will only show at the input at RA0...:confused:
 
10K is too high, maximum source impedance should be 2K, how long a delay do you have after switching channels, before reading the ADC?.

If you check my tutorial it explains the problem.
 
Pots are not perfect either. As a test, use a resistor directly whatever you consider to be Vmax-measured. If you direct resistor (low value) does not reach the digital max, then you need to solve that first.
 
donniedj said:
Pots are not perfect either. As a test, use a resistor directly whatever you consider to be Vmax-measured. If you direct resistor (low value) does not reach the digital max, then you need to solve that first.


is it you mean that the port RA1-RA4 are not perfect??
and i need to change a little bit with the source code for port RA1-RA4??

the different range value can only be shown accurately when it is sent by RA0..
 
meera83 said:
is it you mean that the port RA1-RA4 are not perfect??
and i need to change a little bit with the source code for port RA1-RA4??

the different range value can only be shown accurately when it is sent by RA0..
I think he meant that the variable resistor is not prefect (called pot too).
 
Nigel Goodwin said:
10K is too high, maximum source impedance should be 2K, how long a delay do you have after switching channels, before reading the ADC?.

If you check my tutorial it explains the problem.


yap, i had try with your tutorial before that, it seen like can work as normal..

after i change to my source code, with the two ADC setting same with yours, it can't work as normal already..i didn't put any delay before reading ADC...
the concept is like this:

....
....
call LCD_Init
call LCD_CurOff

again
movlw B'01000001' ;channel RA0
movwf ADCON0
bsf STATUS,RP0
movlw B'00000101'
movwf ADCON1

movlw B'11000111' ;TMR0 prescaler,1:256
movwf OPTION_REG
bcf STATUS,RP0

call LCD_Line1
call Read_ADC
(Read_ADC
btfss INTCON,T0IF ;Wait for Timer0 to timeout
goto A2D

bcf INTCON,T0IF

bsf ADCON0,GO ;Start A/D conversion
btfsc ADCON0,GO
goto $-1
Wait
btfss PIR1,ADIF ;Wait for conversion to complete
goto Wait )

call (math calculation ~multiply, divide)
...
...
...

call (display on LCD)

;;2nd part
movlw B'01001001' ;channel RA1
movwf ADCON0
bsf STATUS,RP0
movlw B'00000101'
movwf ADCON1

movlw B'11000111' ;TMR0 prescaler,1:256
movwf OPTION_REG
bcf STATUS,RP0

call LCD_Line2
call Read_ADC
call (another math calculation ~multiply, divide)
...
...
...

call (display on LCD)

goto again
 
bananasiong said:
I think he meant that the variable resistor is not prefect (called pot too).


at first i also think like that, then i try to exchange the location of both variable resistor use by RA0 and RA1, the result still same(mean that RA0 accurate while RA1 can't get it)..

may i know that is it this kind of problem mostly cause by hardware that connect to PIC??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top