Shop OBEX P1 Docs P2 Docs Learn Events
Sensor Math Help - VDC to Kpa — Parallax Forums

Sensor Math Help - VDC to Kpa

skynuggetskynugget Posts: 172
edited 2009-05-01 23:14 in General Discussion
Hey all, I'm having a completer brain lapse on this, and cant seem to get my math to work out attempting to scale a pressure sensor reading.

Linear Scale:

MIN : at 15 Kpa the sensor outputs 0.2Vdc
MAX: at 115 Kpa the sensor outputs 4.7Vdc

Can anyone help me out with the proper SX/B math to make it happen?

Thanks in advance!

Post Edited (skynugget) : 5/1/2009 7:28:13 PM GMT

Comments

  • pmrobertpmrobert Posts: 677
    edited 2009-05-01 19:40
    4.7-0.2 = 4.5; 115-15 = 100; 4.5/100 = 0.045 volts per kPa; so: (((volts measured-0.2)/0.045)+15):=kPa
    I don't know SX/B syntax so you'll have to translate the equation into understandable code.

    Post Edited (pmrobert) : 5/1/2009 7:46:12 PM GMT
  • ZootZoot Posts: 2,227
    edited 2009-05-01 19:43
    .2 - 4.7 = 15-115

    right?

    So a range of 4.5 = range of 100 (subtracting offsets)

    Scale would be 100/4.5 * 256 if using */ (or 5,688.88888888889)

    So.... lets presume in my sample below that 2 = .2 and 47 = 4.7 from your sensor reading... not sure how you are reading input values here so I can't do more than that. With that in mind the above would be 100/45 * 256 or 568.888888888889

    
    inputVal = inputVal - 2 ' subtract offset so that input range is 0-45 (e.g. 0.0 to 4.5)
    outputVal = inputVal */ 569  ' scale up range of 0-100
    outputVal = outputVal + 15 ' add the output offset
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • skynuggetskynugget Posts: 172
    edited 2009-05-01 19:50
    thanks pmrobert :> i get the algebra, but my problem is trying to figure it out without the floating point, given im starting with a word value of 200 to 4700.


    thanks zoot! just what i needed.

    Post Edited (skynugget) : 5/1/2009 8:25:01 PM GMT
  • pmrobertpmrobert Posts: 677
    edited 2009-05-01 23:14
    Zoot!s the man! I bow to his integer intellect smile.gif My apologies for neglecting this *minor* lack of FP detail.
Sign In or Register to comment.