Re: Potentiometer reading
Hi, Tacbanon,
What does the PIC datasheet say about the source impedance for ADC ???
if no other pot value ... just use a voltage follower ( rail-to-rail OPA or use a special supply ... )
Also try to have only the A/D used inputs as inputs ( or ground them ) and tie pot case to ground ...
Alain
Re: Potentiometer reading
I can never remember which one to use but I see you have the result, left-justified. Try right-justifying it instead and see if that helps (ADCON1.7=1).
The resistance of your pot is 5 times the recommeded maximum impedance but I don't think it should make the readings unstable. Try increasing the sample time by changing the DEFINE ADC_SAMPLEUS 50 to something higher and see what happends.
By the way, what do you mean by jumping from value to another? Is that a count or two or how much is it "jumping"? A little filtering might be all that is needed.
And finally, since you have the ADC configured for external VRef, make sure you have proper decoupling on your VRef input.
/Henrik.
1 Attachment(s)
Re: Potentiometer reading
Thanks Alain and thanks Henrik for the reply. I'm still new to ADC and so far I was able to make my LM35 work based on that code. As I understood in ADCON1 the four least significant bits controls the 8 A to D ports. ADCON1 = 000011 gives me
PORTA.0,1,2,5 = A/D, PortA.3 = +Vref. Which now I think is not really what I need. I need only 3 ADC inputs and I don't have an external VRef for ADC..please correct me if I'm wrong, I should set it to either ADCON1 = 000010. But I still have the same results, please see the attached image to make it clear how the response look like and my pin connections.
Quote:
Henrik:
Try right-justifying it instead and see if that helps (ADCON1.7=1).
I tried that but as I slide to the fullest i have 3-4 reading only.
Attachment 6211
Thanks and regards,
tacbanon
Re: Potentiometer reading
Hi,
Ah, so you had it configured for external VRef but didn't use that - that would explain it. Strange it didn't help when you reconfigured...
Have you verified the pot and connections, does the voltage at RA1 actually change when you sweep the wiper of the pot? Don't you have ANY other pot with lower resistance you can try with? If not just try with a simple resisotr divider.
Since the forum messes up displaying binary numbers I'm going to write them in decimal instead.
If you set the lower four bits to 0100 you'll get 3 analog inputs on AN0, AN1 & AN3 with Vdd/Vss as VRef.
Re: Potentiometer reading
Hi Henrik, I will try it to play it some more later tonight...and give feedback..
Quote:
If not just try with a simple resistor divider.
Okay, I will try that later if nothing came up positive...
Thanks and regards,
tacbanon
Re: Potentiometer reading
Hi, tacbanon
You should check that ...
Quote:
Define 20 OSC
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
... I just see 5 errors ... :surprise:
Alain
Re: Potentiometer reading
what is your reference voltage?
Ioannis
Re: Potentiometer reading
i use this and work
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3 'Uses internal RC clock
DEFINE ADC_SAMPLEUS 10 'Microsecond sample time
Re: Potentiometer reading
Hi tacbanon
Define 20 OSC
This should read
Define OSC 20
Phil
Re: Potentiometer reading
Hi again
Read 'Selecting the A/D conversion clock' in the datasheet
It says R/C clock source not recommended at frequencies above 1mHz
For 20mHz clock source should be %010 or %110 (2 decimal or 6 decimal) ie
Define ADC_CLOCK 2
or
Define ADC_CLOCK 6
Phil
Re: Potentiometer reading
Hi jetpr and Sherbrook, I tried your suggestions but did not work for me...I will try to get another pot today and try it again...thanks for sharing your ideas.
Regards,
tacbanon
1 Attachment(s)
Potentiometer reading(solved)
Hi everyone, I got the code to work but on 10K pot... Thanks for the inputs everyone.
I used the same connections and the codes from forum's input.
Code:
DEFINE OSC 20
' Define ADCIN parameters
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
adval Var Byte ' Create adval to store result(slider)
TRISA = %11111111
ADCON1 = %00000100
mainloop:
ADCIN 0, adval ' Read channel 0 to adval
Serout2 PORTD.2, 84, [$1B,$45] ' Clear
Serout2 PORTD.2, 84, [" Slider: ",#adval]'
Pause 150 ' Wait .15 second
Goto mainloop ' Do it forever
End
Attachment 6219
regards,
tacbanon