Erratic analog inputs .


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2009
    Posts
    33

    Unhappy Erratic analog inputs .

    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

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

  3. #3
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Talking OK

    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.

  4. #4
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Default No change..

    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

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by mackrackit; - 10th October 2009 at 14:10.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Cool For a test.

    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.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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?
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Smile Found it!!!

    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.

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. Multiple analog inputs ?
    By rngd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th February 2008, 15:13
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. Many Analog Inputs
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 10th July 2006, 08:15
  5. analog inputs on 16F716
    By schwinn_rider in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th October 2005, 04:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts