Scaling and offset of a sensor


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807

    Default Scaling and offset of a sensor

    I am a bit stuck in this offset and span measure of a pressure sensor.

    I use the MPXV5004DP differential sensor and it gives and offsset around 1 volt at 0 differential pressure with max 4.92 volts for 39.22 mbar differential pressure.

    So the span is 3.92 volts for 0-39.2 mbar, the offset depends on the device and may range from 0.75 up to 1.25 volts.

    I would like to make an semi-automatic offset calculation on first program execution. Then arrange the 0-39.2 mbar to 0-5 volts but am confussed on the maths.

    My A/D converter is 10bits. Any tip appreciated,

    Ioannis
    Last edited by Ioannis; - 13th March 2023 at 16:17. Reason: semi to semi-automatic and some syntax mambo-jumbo

  2. #2
    Join Date
    Feb 2023
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: Scaling and offset of a sensor

    Here is something I have used in the past.

    '************************************************* ***************
    '* Name : SCALE15W.BAS *
    '* Notes : TO BE USED FOR SCALING 15 BIT VALUES (USING WORDS)*
    ' Input : INVALUE is the 15-bit value to scale
    ' : INMIN is the 15-bit lower bound of the value's current range
    ' : INMAX is the 15-bit upper bound of the value's current range
    ' : OUTMIN is the 15-bit lower bound of the value's target range
    ' : OUTMAX is the 15-bit upper bound of the value's target range
    ' Output : OUTVALUE holds the 16-bit result
    '************************************************* ***************
    INVALUE VAR WORD
    OUTVALUE VAR WORD
    INMIN VAR WORD
    OUTMIN VAR WORD
    INMAX VAR WORD
    OUTMAX VAR WORD


    SCLTEMP0 VAR WORD
    SCLTEMP1 VAR WORD
    SCLTEMP2 VAR WORD
    SCLTEMP3 VAR WORD


    '************************************************* ***************
    SCALE_16W:
    '************************************************* ***************
    SCLTEMP1 = INVALUE - INMIN
    SCLTEMP2 = OUTMAX - OUTMIN
    SCLTEMP3 = INMAX - INMIN
    SCLTEMP0 = SCLTEMP1 * SCLTEMP2
    SCLTEMP2 = DIV32 SCLTEMP3
    SCLTEMP0 = SCLTEMP2 + OUTMIN
    OUTVALUE = SCLTEMP0

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Scaling and offset of a sensor

    how wil you find the accurate 'offset' of the .75 to 1.25 volt. Do you need to know the mbar's presently at startup ?

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Scaling and offset of a sensor

    Since there are some diferencies between sensor devices, on program startup or by user intervention, the offset will be stored in a variable. At this stage no other than the atmospheric pressure is applied, so this can be measured very easy.

    Then in normal operation this will be the reference level.

    So say that the offset is about 1.2 volts at 0 pressure. The max say it is 5 volts. The span is 3.8 volts for a pressure range of 0-39 mbar. I'd like to normalize this as 0 to 1023 counts.

    In the above example I would first take the offset of 1.2 volts that is 246 count and store it in var offset (and EEPROM).

    Then in normal operation say the A/D reads more then 1.2 volts, so it subtracts from the count the offset. But I would like to expand the count to match 0-1023 and not 1023-offset only. There is where I am confused.

    I can ditch the floating point and just accept integers.

    Ioannis

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Scaling and offset of a sensor

    I think I got it.

    My sensor is read at channel 0. So:

    Code:
    offset    var    word
    sensor    var    word
    
    offset_store:         'offset processing
        adcin 0,offset
        write 0,word offset
    return
    
    read_pressure:
        adcin 0,sensor
        sensor=sensor-offset
        sensor=sensor*1023/(1023-offset)
    return
    the problem is how to manage the sensor*1023 since the result might be more than a word and I'd prefer not to use LONG.

    But the 1023/(1023-offset) ends up in a small number like 1.62 or similar. It is not known untill the offset is measured and cannot be substituted as a constant and use */ operator.

    Ioannis
    Last edited by Ioannis; - 13th March 2023 at 20:08.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Scaling and offset of a sensor

    RTFM once again.

    Well, DIV32 is the magic trick.

    I used a dummy var to make the sensor*1023 multiplication, saved the 1023-offset to range variable and did a div32 range.

    Solved.

    Ioannis

Similar Threads

  1. Help with scaling math..
    By ardhuru in forum General
    Replies: 4
    Last Post: - 15th May 2017, 23:41
  2. Offset to variable howto ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 3rd October 2008, 09:36
  3. Scaling ADC values
    By purkolator in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th November 2007, 05:14
  4. Help scaling voltage...
    By sirvo in forum Schematics
    Replies: 6
    Last Post: - 30th July 2007, 19:35
  5. Need help with scaling
    By champion in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 13th November 2006, 03:20

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