Shop OBEX P1 Docs P2 Docs Learn Events
probably more of a math question... — Parallax Forums

probably more of a math question...

Bobb FwedBobb Fwed Posts: 1,119
edited 2008-09-23 19:19 in Propeller 1
I am running an RC Time to measure voltage. I have a few data points, but I do not have the math know how to convert it to a readable voltage (I have a similar problem with a rctime temperature measurement).
Here is the info (collected off my own RC Time object). This is the voltage range I need to read, but reading beyond 10.41 and 15.85V would be great too. It doesn't have to be perfectly accurate (but within 0.2V would be great across the range below), and for ease of programming I can use integers with a 10x multiplier (e.g. an output of 123 is representative of 12.3V).
@0.1µF, >2ms low
26000 = 10.41V
24249 = 11.00V
21673 = 12.00V
19585 = 13.00V
17785 = 14.00V
16241 = 15.00V
15073 = 15.85V

Obviously having something written in spin, or some instruction on how I would do it would be great.

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-23 16:16
    Here is the best I can do... 2546050/rctime. This gives me exactly 130 (13.0V), but is 0.3V and 0.7V high at 14V and 15V respectively and the same difference going to a lower voltage. I know it is going to have something to do with exponents and whatnot. I'm just running off trial and error to get these answers. Any help would be nice.
  • lonesocklonesock Posts: 917
    edited 2008-09-23 16:35
    Well, I just used Excel's "solver" to optimize the equation:

    Voltage = A/counts + B

    A = 195598.0736
    B = 2.9486494

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-23 16:45
    thanks! is that part of excel? or is that some type of extension? I have excel 2002 (10) does it have that feature, if so, where can I find it?
  • lonesocklonesock Posts: 917
    edited 2008-09-23 16:50
    Bobb Fwed said...
    thanks! is that part of excel? or is that some type of extension? I have excel 2002 (10) does it have that feature, if so, where can I find it?
    You are welcome. The solver is an Add-In. It comes with Excel, but is not available by default. Go to the Tools->Add-Ins menu, then check the "Solver Add-In" box and hit OK. It will install for you, then "Solver..." will be available under the Tools menu.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • Tracy AllenTracy Allen Posts: 6,663
    edited 2008-09-23 16:52
    This just came up a day ago in another thread:
    http://forums.parallax.com/showthread.php?p=753026

    I plugged your values into the formulas:
    V1: HIGH voltage applied to circuit = 15.85
    RCT1: corresponding raw RCtime value = 15073
    V2: LOW voltage applied to circuit = 10.42
    RCT2: corresponding raw RCtime value = 26000

    K1 = 10 * (V1 - V2) * ( RCT1 * RCT2 ) / ( RCT2 - RCT1 ) = 1951062
    K2 = 10 * V1 - ( K1 / RCT1) = 29

    The spin code should be then,

    Voltage := 1951062 / RCT + 29 ' corrected typo, 1951062 not 21951062

    This is the explicit solution of two equations in two unknowns:
    V1 = K1 / RCT1 + K2
    V2 = K1 / RTC2 + K2
    and applies whenever V1 and V2 are sufficiently greater than the Prop threshold (~1.65 volts).

    edit:
    These values are close to the ones that lonesock found from the EXCEL solver, which I think uses a least squares fit. The above formula fits the curve exactly at two points.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 9/23/2008 5:33:45 PM GMT
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-23 16:59
    What worked much more accurately: 1978085 / RCT + 29
    run the numbers...this is much better (within 0.1 -- it looks like -- until you get above 15.5V).
    (It only give 1 decimal value, but that is good enough for me)
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-23 17:06
    actually... 21951062 / RCT + 29 isn't very good at all....
    ... 24249 == 11V ... 21951062 / RCT + 29 gives me 934 (9.34V?)
    ... 17785 == 14V ... 1263 (12.63?)
  • Tracy AllenTracy Allen Posts: 6,663
    edited 2008-09-23 17:28
    Sorry, a typo, an extra 2 in front of the number. Corrected now.
    Voltage := 1951062 / RCT + 29 ' not 21951062

    1951062 / 26000 + 29 = 104 (10.41 volt ' reference point)
    1951062 / 24249 + 29 = 109 (11 volts)
    1951062 / 17785+29 = 138 (14 volts)
    1951062 / 15073 + 29 = 158 (15.85 volt ' reference point)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-23 19:19
    With enough data points, you could also use linear interpolation, without needing floating point.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
Sign In or Register to comment.