Help with the conversion math


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    Hi Ed,
    You may need to change both the offset and the gain value.
    Just because the voltage at the low end is off by 37mV doesn't mean the high end is off by the same amount.

    Numbers within () are example numbers.

    Step 1, Take a bunch of readings at 0 pressure, write down the reported numbers, then calculate the average. (345)
    Step 2, Take a bunch of readings at max pressure, write down the reported numbers then calculate the average. (3591)
    Step 3, Figure out what you want the final range of values to be. 0-1000, 0-5000, 0-7000 etc? (0-1000)
    Step 4, Calculate the "offset" and the "gain":
    The "offset" is simply the value calculated in step 1. (345)
    The "gain" is [whatever value you want max to be] divided by ( [value at step 2] minus [value at step 1] ) times 256 ie. 1000 / (3591 - 345) * 256 = 79

    What's that 79?
    Again, it's like multiplying by units of 1/256. So when our value returned by ADC routine is 3591 (max pressure) we first subtract the offset of 345 and then multiplies with 79/256, what's the result?
    (3591-345) * 79 / 256 = 1001, not perfect but pretty close.


    If you're using the routine I posted earlier, with the 4 times oversampling, then look at the result directly from the ADC (110 in your case), look at the result at the end of the routine. It it might be 438 or 441 and, as long as the sensor isn't super stable and "slient", it'll give you a better over all resolution.

    /Henrik.
    Last edited by HenrikOlsson; - 28th November 2014 at 16:55.

  2. #2
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    One of the things I wanted to do is pubicly thank everyone especially Henrik! After finally receiving replacement sensors (I blew up the last 3 due to over pressure) I got a chance to play! One thing I noticed when firing up the code in Microcode Studio Plus and using the ICD was that the ICD display made room at the bottom to actually display the results! The HSEROUT line of code made eveything so much easier! Again many, many thanks!

    Sincerely, Ed

Similar Threads

  1. AD conversion
    By CipiCips in forum mel PIC BASIC
    Replies: 8
    Last Post: - 19th May 2011, 02:09
  2. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 02:48
  3. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 11:22
  4. conversion
    By pramodsinha in forum Forum Requests
    Replies: 2
    Last Post: - 19th January 2006, 16:58
  5. ºC -> ºF Conversion
    By CocaColaKid in forum General
    Replies: 6
    Last Post: - 15th March 2005, 10:42

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