Help with the conversion math


Closed Thread
Results 1 to 31 of 31

Hybrid View

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

    Question Help with the conversion math

    Hi All!
    So I have a pressure sensor that output a voltage reading based upon the pressure applied. How would I convert the voltage reading to actual pressure? I know that at zero PSI the A/D gives 7040 and divided by 16 should be a voltage of .440 volts. Thanks!

    '************************************************* ******************
    '* Name : XXXXSPEEDT2.bas *
    '* Author : Ed Cannady *
    '* Notice : Copyright (c) 2011 *
    '* : All Rights Reserved *
    '* Date : 8/29/2014 *
    '* Version : 1.0 *
    '* Notes : For a 18F1320 and 54AL07H2210 *
    '************************************************* *******************

    Define OSC 20
    Define LOADER_USED 1
    Include "Modedefs.bas"
    include "hpwm10L.pbp"
    ENABLE DEBUG

    #CONFIG
    __CONFIG _CONFIG1H, _HS_OSC_1H & _FSCM_OFF_1H
    __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_8K_2H
    __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_27_2L
    __CONFIG _CONFIG3H, _MCLRE_OFF_3H
    __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_ON_4L
    __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    __CONFIG _CONFIG7H, _EBTRB_OFF_7H
    #ENDCONFIG


    Define ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 1000

    ADCON1 = %11101111
    TRISB = %11111111

    VOLTS VAR WORD ' Volts reading
    Reading var long ' What we are really reading

    VOLTS = 0 ' Start with a Volts value of zero

    GETVOLTS:

    ADCIN 4, VOLTS

    Reading = VOLTS

    VOLTS = VOLTS/16
    Pause 1000
    GOTO GETVOLTS

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    There is not enough information to answer your question. You must know minimum pressure, voltage for minimum pressure, maximum pressure, and output voltage at max pressure.
    Sensor output is probably ratiometric 0.5V to 4.5V. But what is maximum pressure? Or give us sensor type and datasheet.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    Yes, what pedja089 said. The only clue you provided is 54AL07H2210 which returns nothing on Google.

    And, I have a feeling we've been thru this before..... The PIC ADC has a resolution of 10 bits, it returns values ranging from 0 to 1023.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Question Re: Help with the conversion math

    Sorry guys. The PDF was too large (22 pages as it had all the devices in the series) so to upload so I had to make it smaller! Yes it is a 0.5 - 4.5v type ratiometric device. My A/D is showing a reading of 7040 at zero psi and when I do a divide by 16 I get 440 which I am assuming means .440 volts? With a voltmeter I see .541 volts so now I have not been able to make any sense of all of this. My best guess is that this would indicate a voltage range of .440 to 4.440? Where .440 is zero and 4.440 would be at .07psi? If the A/D were 10 bit and giving 1023 as a maximum value then a reading of 7040 could not be possible. I am just so totally lost and confused with so many numbers! I just completely do not understand! Thanks!
    Attached Images Attached Images

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    Quote Originally Posted by HenrikOlsson View Post
    Yes, what pedja089 said. The only clue you provided is 54AL07H2210 which returns nothing on Google.

    And, I have a feeling we've been thru this before..... The PIC ADC has a resolution of 10 bits, it returns values ranging from 0 to 1023.

    /Henrik.
    its just like de ja vou again
    http://www.picbasic.co.uk/forum/show...578#post128578

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    Yeah, deja vu indeed....

    Ed,
    * The resolution of the ADC is 10 bits.
    * It does not return a reading directly in Volts.
    * Basically it takes the difference between Vref+ and VRef- and divides that by 1024 (2^10, the resolution of the ADC). Each "count" in the value is then "worth" that amount.

    So, if VRef- is GND (0V) and VRef+ is 5V the difference between the two is 5V. Each "count" in the ADC result is then "worth" 5/1024=4.88mV.
    If the ADC returns 745 the voltage at its input is 5/1024*745=3.638V

    I can't make out anything from that datasheet, it's just garbage numbers when viewed on my machine. I managed to find this one. And, I'm guessing you've got the 7psi sensor, correct? If so then something like this might work. I have not tested it though so all bets are off....

    Of course you need to configure pins etc as usual (!)

    Code:
    Accumulator VAR WORD
    i VAR BYTE
    ADResult VAR WORD
    
    Accumulator = 0
    
    Main:
    
    For i = 0 to 39
      ADCIN 4, ADResult  
      Accumulator = Accumulator + ADResult
      PauseUs 500
    NEXT
    
    ADResult = Accumulator / 10   ' Psuedo 12bit resolution, ADResult is now 0-4092
    
    ' Sensor outputs 0.5V (ADResult=409 ) at 0psi (nominal)
    ' Sensor outputs 4.5V (ADResult=3683) at 7psi (nominal)
    
    ADResult = ADResult - 409   ' Offset for zero output, ADResult is now 0 to 3274 for 0 to 7psi
    ADResult = ADResult */ 547  ' Scale up, ADResult is now 0 to 6995 for 0 to 7psi 
    
    ' Display Pressure: x.xx psi
    HSEROUT["Pressure: ", DEC ADResult/1000, ".", DEC2 ADResult//1000, "psi", 13]
    
    PAUSE 1000
    
    Goto Main
    /Henrik.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    Quote Originally Posted by HenrikOlsson View Post
    Yeah, deja vu indeed....


    I can't make out anything from that datasheet, it's just garbage numbers when viewed on my machine.

    /Henrik.

    ditto for the pdf
    do we have a 54A L07H2210 or a 54ALL07H2210 or a 54AL007H2210 or a 54A 007H2210 ?
    they are all different animals and the 54ALxxx are 3.3v devices

  8. #8
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Help with the conversion math

    Is this not a repeat of the left and right output justification as on the previous thread in Richard's link.

    7040 left justified is 110 right justified using Henrik's 4.88mV then

    110*4.88/1000=0.5368 V

    Or put another way 7040/64=110 which shifts the 10 bit left justified result 6 bits to the right making the result the same as a right justified result.

Similar Threads

  1. AD conversion
    By CipiCips in forum mel PIC BASIC
    Replies: 8
    Last Post: - 19th May 2011, 01:09
  2. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01: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, 10:22
  4. conversion
    By pramodsinha in forum Forum Requests
    Replies: 2
    Last Post: - 19th January 2006, 15:58
  5. ºC -> ºF Conversion
    By CocaColaKid in forum General
    Replies: 6
    Last Post: - 15th March 2005, 09:42

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