ADCIN question


Closed Thread
Results 1 to 5 of 5

Thread: ADCIN question

  1. #1

    Default ADCIN question

    Pardon the newbie question. I was searching and never came across an answer that I understood to this question. For reference, I am working with a 10F222 chip running at 5V Vdd.

    If I read in a voltage using ADCIN from gpio.0, and store that value as a byte variable, I am trying to figure out what that value will be for various voltages at the gpio.0 pin.

    Specifically, the voltage will vary. slowly, from 2.5VDC to 0.7VDC before the pic shuts down due to the boost regulator not being able to take in anything lower than 0.7VDC and convert to 5VDC to drive the pic.

    This is the chunk of code I am curious about. One of my friends tossed me the front end information to get me started (and so I can hopefully figure it out).

    @ device pic10F222, iofscs_8mhz, wdt_on, mclr_off, protect_off
    ADCON0 = 0 'better disable the A/D module so PBP can config it right
    osccal = %00000000 'turn off clockout!
    OPTION_REG = %00000000 'bit5 is critical here for GPIO.2 TOCS = FOSC/4 I don't yet understand this one either....

    DEFINE OSC 8 '8MHz
    DEFINE ADC_BITS 8 ' set adcin to 8 bit

    Vin var BYTE
    gpio.0 = 1 'this is the a/d input
    ADCIN 0,Vin


    and if Vin in real life is 2.5V, 1V, or 0.7V... how do I figure out what value will get placed in the Vin variable?

    thanks a lot
    Greg

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    If you are reading an 8-bit a/d converter, then your input will be from 0 to 255. The scaling depends on your reference. typically, for cheap setups, this is Vin. If your Vin is 3.0 volts, you divide that by 256 to see how many volts each bit is worth. 3/256=.0117. So, if you get a reading of 200, your voltage is just over 2.3. Just plug the math in to convert it in code, or for more compact code, simply use precalculated constants.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    IOFSCS_8MHZ     Hmmm, dyslexia day at Microchip

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2858&stc=1&d=122145428 7" /><!-- Name:  IOSCFS.gif
Views: 433
Size:  2.1 KB -->

    Your device line is OK, just pointing out an oddity.
    <hr>

    > how do I figure out what value will get placed in the Vin variable?

    1 decimal place ...
    Code:
    Volts = (Vin+1) */ 50
    2 decimals ...
    Code:
    Volts = (Vin+1) */ 500
    DT

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I read that question again, and maybe you want the other way around.

    > how do I figure out what value will get placed in the Vin variable?

    With 8-bit resolution, the values will range from 0 to 255.

    If the input is 2.5 volts, then the value that gets placed in Vin will be ...

    255 / (5 / 2.5) = 127

    For 0.7v that's ...

    255 / (5 / 0.7) = 35

    hth,
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    thanks! all!. This is all quite new to me. the last thing I programed was some cfd in fortran 95, so the hardware side of things is different.

    I think I may end up going to a PIC12F683 just for flexibility, as I can still (barely) fit it on the circuit board I am making.

Similar Threads

  1. ADCIN and PIC18F4331 Arghhhhh !
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th December 2010, 20:27
  2. ADCIN Sampleus time question
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th February 2009, 18:28
  3. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  4. really simple adcin question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 21st April 2006, 09:06
  5. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 07:46

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