Shop OBEX P1 Docs P2 Docs Learn Events
Basic analog to digital conversion projects — Parallax Forums

Basic analog to digital conversion projects

ArchiverArchiver Posts: 46,084
edited 2003-06-19 05:16 in General Discussion
>
Original Message
> From: Hudson T Clark [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=0-UcxQyx2nFEVM-mGv2-oXJm7o6uIViGcKkB8eFqdTIjv5702xCmjnzgT7xIOo_gI0wl5rd2dIsWbc2haA]dark_archon1@j...[/url
> This last challenge is to modify the original program to calculate the
> voltage as if the maximum (supplied) wasn't exactly 5v but if it was 4.96
> volts. The challenge says to make a sub routine to adjust the
> calculations.

Do you mean Vref for the A/D is 4.96 and not 5V?

Let's say you have an 8-bit A/D. So it's max reading would be 255

Simplistically, if Vref were 5V then 255 would correspond to 5V.

If Vref were 4.96V then 255 would correspond to 4.96V.

i.e. "Voltage measured" = "A/D output" times "Vref" divided by "A/D output
at Vref"

V = ( AD * Vref ) / ADMaxScale

This doesn't address the issue of A/D non-monotonicity, non-linearity, or
offsets in readings at the low or high end, but you get the idea.

Marc Reinig
System Solutions

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-04-08 03:00
    Check out Tracy Allen's notes on integer math at

    http://www.emesystems.com/BS2index.htm




    Larry Bradley
    Orleans (Ottawa), Ontario, CANADA
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-08 14:30
    The solutions are simple. You have to multiply and divide. The problem is
    that integer math won't let you do 4.96/5.00.

    This isn't limited to your A/D problem, it is a general problem with any
    processor that doesn't have floating point math. If you carry on with PICs
    and other micros, you will run across this kind of thing on a daily basis

    Remember, you are studying this stuff in school - they are trying to make
    you solve problems, not just come up with canned solutions, so that when
    you encounter similar problems later, you will know how to solve them.

    Integer math problems are solved by suitable ordering of the operations,
    and by scaling in order to maintain precision.

    For example, to compute 2/9 of a number, you can't compute 2/9 , then
    multiply, since 2/9 is 0 in integer math.

    If you want to compute y=x * (2/9), you need to order it as x*2/9. But if x
    is a small number (say 5), and you want the answer to 2 decimal places, you
    need to do some scaling.

    if you just do y = 5*2/9, you will get 1 as your answer - not very precise.
    However, if you do y=5*200/9, you will get 111.
    You can consider this to be 1.11 - you just have to remember where the
    decimal point has to go.

    Tracy's site has a lot of useful integer math information - study it and
    play with it some - you will find it very handy.

    Good luck.

    Larry


    At 09:16 PM 6/18/2003 -0700, you wrote:
    >Thanks I will look threw the site.
    >
    >So there isn't anyone that knows of the solutions? That's shocking I
    >wonder if parallax has them? I don't think people will learn very much
    >because when they get stuck its like ah what do I do now?
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and
    >Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

    Larry Bradley
    Orleans (Ottawa), Ontario, CANADA
  • ArchiverArchiver Posts: 46,084
    edited 2003-04-08 15:11
    In a message dated 4/8/2003 6:33:11 AM Pacific Daylight Time,
    lhbradley@i... writes:

    > The solutions are simple. You have to multiply and divide. The problem is
    > that integer math won't let you do 4.96/5.00.
    >
    > This isn't limited to your A/D problem, it is a general problem with any
    > processor that doesn't have floating point math. If you carry on with PICs
    > and other micros, you will run across this kind of thing on a daily basis
    >
    > Remember, you are studying this stuff in school - they are trying to make
    > you solve problems, not just come up with canned solutions, so that when
    > you encounter similar problems later, you will know how to solve them.
    >
    > Integer math problems are solved by suitable ordering of the operations,
    > and by scaling in order to maintain precision.
    >
    > For example, to compute 2/9 of a number, you can't compute 2/9 , then
    > multiply, since 2/9 is 0 in integer math.
    >
    > If you want to compute y=x * (2/9), you need to order it as x*2/9. But if x
    >
    > is a small number (say 5), and you want the answer to 2 decimal places, you
    >
    > need to do some scaling.
    >
    > if you just do y = 5*2/9, you will get 1 as your answer - not very precise.
    >
    > However, if you do y=5*200/9, you will get 111.
    > You can consider this to be 1.11 - you just have to remember where the
    > decimal point has to go.
    >
    > Tracy's site has a lot of useful integer math information - study it and
    > play with it some - you will find it very handy.
    >
    > Good luck.
    >
    > Larry
    >

    Well said!!!!!!!!


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-18 21:59
    I'm doing this series of projects from parallax called "Basic analog to
    digital conversion" for my direct studies course at college. I got threw
    everything up until experiment number 3 which is making a dvm with a
    lm0831 and the basic stamp (of course heh). The one problem I have
    seriously been having is figuring out a way to finish the last challenge.
    This last challenge is to modify the original program to calculate the
    voltage as if the maximum (supplied) wasn't exactly 5v but if it was 4.96
    volts. The challenge says to make a sub routine to adjust the
    calculations. I went to school today and asked my teacher and he said he
    didn't have the solution he hasn't done this series yet. I went around on
    the internet and wasn't really successful in finding a solution but he
    said to just keep looking so I figured this is a good place to look. If
    anyone has the pbasic code thats modified for it please help. Or at least
    just some ideas.
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-19 04:11
    The whole problem is that you can only do integer math. In the code
    already there from other parts of the project this value is simply "5"
    there is no special math really they just use the number "5". So I don't
    know that there is really anything to get from the code to help me out in
    this specific exercise. Here is the routine to calculate the voltage, it
    also near the end will round off. I will probably rip apart the below
    math tonight and figure it out I was very frustrated earlier. Ok so this
    is what I was talking about v2 and v3 are used to calculate what's after
    the decimal point, and v is what's before it (I believe). Then the if
    statement near the end is used to figure out if it should round or not
    based on what's after the decimal point.

    CALC_VOLTS: 'subroutine named CALC_VOLTS
    v = 5*adcbits/255
    R = 5*adcbits//255
    v2 = 100*R/255
    v3 = 100*R//255
    v3 = 10*v3/255
    if v3 < 5 then skip_out 'if v3 is less then 5 go to the skip_out label
    v = v + 1
    v2 = 0
    skip_out: 'label named skip_out
    return
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-19 05:16
    Thanks I will look threw the site.

    So there isn't anyone that knows of the solutions? That's shocking I
    wonder if parallax has them? I don't think people will learn very much
    because when they get stuck its like ah what do I do now?
Sign In or Register to comment.