PDA

View Full Version : Erratic analog inputs .



timseven
- 9th October 2009, 23:24
Hi, everybody. I am using the 16F88 pic for my first time and I want to read a voltage generated by four infrared leds as sensors into inputs (RA0-RA3). I have read somewhere that these analogs pins are limited to 240 mvolts and I don’t know if it’s true. I setup the hardware and ran a test program and after solving some initial problems I have the circuit working but not as I expected it to work. When I grounded (1k resistor) all four inputs I should have nothing as readings and I got something (about 45 to 5 mvolts) very erratic. Here is the test program for you to evaluate. Please, help me find where I am wrong.Thanks.


OSCCON = $68 'Sets the internal oscillator to 4 Mhz
ANSEL = %00001111 'set RA0-RA3 as analog inputs

DEFINE adc_sampling 50 'Set sampling time IN micro sec.
TRISB = 0 'TURN PORT B as outputs
TRISA = 255 'TURN PORT A as inputs

ti var BYTE
ti = 50 '50 MILLISECONDS DELAY

A VAR WORD
B VAR WORD
C VAR WORD
D VAR WORD

READCDS:
PAUSE 1000 ' One second delay

ADCIN PORTA.0, a ' Reads portA pin 0 into A variable.
PAUSE 50 '50 Milliseconds delay
ADCIN PORTA.1, b ' Reads portA pin 1 into B variable.
PAUSE 50 '50 Milliseconds delay
ADCIN PORTA.2, c ' Reads portA pin 2 into C variable.
PAUSE 50 '50 Milliseconds delay
ADCIN PORTA.3, d ' Reads portA pin 3 into D variable.

'* * * * * * * * * Display Serially the sensor readings * * * * * * * *
PAUSE 100
Serout PORTB.1, 0, [254,1] 'Clear display
Serout PORTB.1, 0, [254,2] 'Send cursor home

PAUSE 20 'Pause 20 mseconds delay
Serout PORTB.1, 0, ["A= " , #(A)] 'Print A on mvolts
PAUSE 20
Serout PORTB.1, 0, [" B= " , #(B)] 'Print B on mvolts
PAUSE 20
SEROUT PORTB.1, 0, [$FE,$C0] 'Jump to second line
PAUSE 20
Serout PORTB.1, 0, ["C= " , #(C)] 'Print C on mvolts
PAUSE 210
Serout PORTB.1, 0, [" D= " , #(D)] 'Print D on mvolts



GOTO READCDS '********** Provisional loop Sensors test ***********

END

Charles Linquis
- 10th October 2009, 01:10
A couple of things:

You need to set up your chip to have analog inputs, justification
and Vref by setting the bits in ADCON1

The A/D input range is basically 0 to Vref (which will give you counts
from 0 to 1023).

Your diodes will probably not produce enough output voltage to
be usable without first being amplified by an op-amp.

timseven
- 10th October 2009, 01:26
Thanks for your answer. I'll add the ADCON1 = 128. I think that's what I need.
The diodes puts out about 1 VDC max. at full exposure. I think it's enough to be amplified no? I'll do the changes and let you know. Thanks.

timseven
- 10th October 2009, 04:29
I added the ADCON1 right justified or bit 7 (1) with the four combination for bits 5-4. I got the same erratic result. Something that I want to point out is that the four channels show the same voltage no matter if they are grounded or not. Something here is odd. Any idea what should I do next? Thanks

mackrackit
- 10th October 2009, 13:53
When you measure the max voltage from the LEDs with a meter what do you have.

You will need an op amp like Charles said or move some things around and use the two VREFs. But that still might be a little tight with out an amp.

Acetronics2
- 10th October 2009, 14:08
Hi,

At first glance ...

Your Vref must be rock-stable ( Pic Decoupling ... What about ???) ... now result is +/- 1 digit ... = +/- 5 mv !!! ... a little HardWare scheme would be useful !!!

I'd recommend some external Vref ... if mV looked for !

Alain

timseven
- 10th October 2009, 18:58
Hi, I found a site that has a project that will help me setup mine. The project uses a potentiometer to vary the voltage to be read and display. It uses one port only ( portA.4) but for the test it’s good enough. I followed all the instructions and did the setup exactly as the program said. I copied the program and compiled it. The program describes that the displayed digital value will be from 0 to 1023. It worked as plan but the number displayed is a single digit not four as expected. This is the whole project site: C:\Documents and Settings\Dad\Desktop\mr k\adc2.pbp ,Please help me find what I am doing wrong. Thanks.

mackrackit
- 10th October 2009, 20:13
Hmmmmm.
For some reason I can not get into your "C" drive from here.
Could be a network problem. :)

Go over to rentron.com for some examples that work.
And what are your voltages?

timseven
- 10th October 2009, 22:34
I found the problem by chance. I mist the DEFINE ADC_BITS 10 that gives me the precision. Thanks any ways to Charles, Acetronics and Mackrackit that so gently help me figure it out. You guys out there are our best teachers ever. Thanks.