Multiple analog inputs ?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2008
    Posts
    13

    Default Multiple analog inputs ?

    Hi,

    Im using a PIC 16F877A. I want to read multiple analog inputs at the same time and then compare their values. I have read somewhere that after the first ADCIN, I have to delay a few miliseconds before doing ADCIN again.

    Can someone explain this please ? How long should I have to delay and where should I delay ? Anyone have an example code ?

    Also, what else should I know about taking in multiple analog inputs, as in potential problems, etc ? I've read a bit about noise problems but there wasnt much explanation .. Any links will be very helpful. Thanks everyone.

    edit: Ive looked at the datasheet but couldnt find any useful info.

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


    Did you find this post helpful? Yes | No

    Default

    Go here for example code and it may also answer your question.
    http://www.rentron.com/PicBasic1.htm
    Then scroll to:
    A/D & Using The 8-Pin PIC™ Series
    bullet

    Click HERE for: How to build a 4-channel A/D converter using the PIC12C671.
    bullet

    Click HERE for: Using the 8-Pin PIC12C671 A/D Converter.
    bullet

    Click HERE for: Using the 8-Pin PIC12C671 with PicBasic.
    bullet

    Click HERE for: Using the PIC16F877 A/D Converter. This example displays 3-channels of analog input on an LCD display.
    Never had any problems with more than one myself.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    you can also see http://www.picbasic.co.uk/forum/showthread.php?t=1659 or search the forums, there's lots of good info here.

  4. #4
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Go here for example code and it may also answer your question.
    http://www.rentron.com/PicBasic1.htm
    Then scroll to:


    Never had any problems with more than one myself.
    Do you have any examples which use ADCIN and put the input directly into the variable (see below) ? T

    Quote Originally Posted by nomad View Post
    you can also see http://www.picbasic.co.uk/forum/showthread.php?t=1659 or search the forums, there's lots of good info here.
    Thanks ! Just to clarify, so my code below can work without problems ?


    define adc_bits 10 'define number of bits in result
    define adc_clock 3 'clock source3=RC
    define adc_sampleus 50 'set sampling time in microsec

    adcvar1 var word
    adcvar2 var word
    diff var byte



    start:
    adcin 0, adcvar1 'read channel 0 to adcvar1
    adcin 1, adcvar2 'read channel 1 to adcvar2

    diff = adcvar1-adcvar2

    select case diff
    ...


    Thanks guys. Any other links will be very helpful.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Cool

    Hi,

    IF you want "real same time" measurements ... simply use :

    1) slow variatons : RC Low pass on ADC inputs to filter and "damp" a bit

    2) quick variations : External LF398 ( i.e.) Sample and Hold circuits ...

    3) Use two external ADCs

    4) Use a differential OPA ...


    And then use the ADC ... or read the ext ADCs.

    remember The Pic can do ONE THING ONLY at a time .... but can drive many peripherals at the same time ....

    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 " !!!
    *****************************************

  6. #6
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    IF you want "real same time" measurements ... simply use :

    1) slow variatons : RC Low pass on ADC inputs to filter and "damp" a bit

    2) quick variations : External LF398 ( i.e.) Sample and Hold circuits ...

    3) Use two external ADCs

    4) Use a differential OPA ...


    And then use the ADC ... or read the ext ADCs.

    remember The Pic can do ONE THING ONLY at a time .... but can drive many peripherals at the same time ....

    Alain
    Thanks Alain, but I dont think I need 'same time' measurements.

    OK, so I have read the links. If my code is like this

    pair1:

    adcin 0, adc1 'read channel 0 to adc1
    adcin 1, adc2 'read channel 1 to adc2
    diff = abs(adc1-adc2)
    if diff>tolerance then
    ' run servo1 for x seconds
    goto pair1 'recheck values
    else
    return
    endif
    meaning I repeatedly check the analog input until 'diff' is less than 'tolerance', there will be no problems as I have

    DEFINE ADC_SAMPLEUS 50

    at the top, and this will add the delay between each ADCIN automatically. Am I correct ? Just want to confirm.

    ps. I also read that sampling at 8 bits instead of 10 will improve the speed and stability when using multiple analog inputs. Will reducing to 8 bits help a lot, or can it work just fine with 10 bits ?

Similar Threads

  1. Erratic analog inputs .
    By timseven in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th October 2009, 22:34
  2. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  3. Many Analog Inputs
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 10th July 2006, 08:15
  4. multiple serial inputs
    By Richardco in forum mel PIC BASIC
    Replies: 2
    Last Post: - 25th November 2005, 21:26
  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 : 0

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