Help with A/D math!


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    10

    Default Help with A/D math!

    Hi all,

    I am building a small system to read a laser distance finder. This sensor outputs a 0-10 volt signal based on the distance from the object.
    I am reducing the voltage to 0-5v with a voltage divider so that i get 0-5 v to AD0 on my PIC16F876.

    Here are some examples of the data I'm getting back

    Distance AD count
    42.9 820
    36.3 675
    33.3 600
    19.7 270
    11.2 60

    What i need to do is come up with a formula to convert the A/D readings into distance. So far I am failing miserably! The sensor can be adjusted to select where 0 is in distance and where 10v is. I currently have it set so that 6" is 0v and 50" is 10V I figure that I will have to provide a calibration routine that samples a near point (known distance) and a far point (known distance).

    I REALLY need help with the math here to make this silly thing work.

    Thanks in Advance,

    Dave

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Dave

    You can try :

    distance = 8573 + 41*AdResult + ( AdResult / 2 )

    with Distance ( use a WORD ) = 1000 * actual distance in " ...

    Alain

    PS; SURE it is a laser distance finder ??? I'd Better bet a laser pointer on a U.Sonic distance finder ... overall if measuring as short as 6" ... and no more than 40 or 50" ...

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

  3. #3
    Join Date
    Jul 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Alain,

    Wow, works like a charm... now can you tell me how you got to those numbers? <grin>
    I'm sure when I install this in the field I will have different numbers, so I will need to know how to recalculate.

    You are a lifesaver!

    Dave

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dbodenheimer View Post
    Alain,

    Wow, works like a charm... now can you tell me how you got to those numbers? <GRIN>
    I'm sure when I install this in the field I will have different numbers, so I will need to know how to recalculate.

    You are a lifesaver!

    Dave
    Very simple, Dave ... no miracle !

    just need to check what is PBP compatible , as an operation, and avoiding any overflow when calculating ...

    Have a look here ...
    http://curveexpert.webhop.net/

    really a very handy tool

    Alain
    Last edited by Acetronics2; - 20th August 2010 at 17:43.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  5. #5
    Join Date
    Jul 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Got the tool. Yes it looks very handy!
    Can you tell me the setup you used to calculate the data i sent?

    I want to make sure i understand how to set things up

    Thanks!

  6. #6
    Join Date
    Jul 2010
    Posts
    1


    Did you find this post helpful? Yes | No

    Lightbulb

    Enter data into “CurveExpert” chart:

    X is distance, Y is A/D data

    Select ‘Apply Fit”, select ‘Linear” from drop down menu.

    A graph will pop up, press the ‘info’ button and you’ll get your equation and the coefficients to use.


    I will never admit how long that took me to figure out.

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