Shop OBEX P1 Docs P2 Docs Learn Events
Float32 f.exp — Parallax Forums

Float32 f.exp

bunkerush5bunkerush5 Posts: 10
edited 2014-03-04 20:19 in Propeller 1
The rangefinder I am using for a project is connected to an ADC and I need to use the equation below to get the proper range values from the ADC. There is little documentation for float32 especially the exp.

my equation is dist=66.928e^(-0.01*ADC value)

obj
f: "float32"

pub
f.start
f.exp( this is where I am lost)

Do I need to do just the e^( ) portion and save that as one variable and then multiply that by the 66.928 and do everything in pieces or can I do it all as one?
I would appreciate any help with the equation.

Thanks

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2014-03-03 20:07
    exp just does the exponent bit (ea). IOW you calculate -0.01*ADC first (as float), pass that to exp and finally mulitply the result by 66.928.

    untested, getADC returns an integer
    r := f.fmul(66.928, f.exp(f.fmul(-0.01, f.ffloat(getADC))))
    
  • bunkerush5bunkerush5 Posts: 10
    edited 2014-03-04 19:47
    Thank you. This was very helpful. Now I am trying to round the variable r and it does not appear to function properly. I have tried it two different ways with no success.

    [code]

    r := f.fround(f.fmul(66.928, f.exp(f.fmul(-0.01, f.ffloat(getADC)))))

    'or
    r := f.fmul(66.928, f.exp(f.fmul(-0.01, f.ffloat(getADC))))
    r:=f.fround(r)
  • kuronekokuroneko Posts: 3,623
    edited 2014-03-04 20:02
    Why do you say that? IOW what do you expect and what does in fact happen?
    CON
      _clkmode = XTAl1|PLL16X
      _xinfreq = 5_000_000
      
    OBJ
      serial: "FullDuplexSerial"
           f: "Float32"
           s: "FloatString"
           
    PUB null | r
    
      serial.start(31, 30, %0000, 115200)
      f.start
      waitcnt(clkfreq*3 + cnt)
      
      r := f.fmul(66.928, f.exp(f.fmul(-0.01, f.ffloat(getADC))))
    
      serial.str(s.FloatToString(r))
      serial.tx(13)
      serial.dec(f.fround(r))
      serial.tx(13)
      
    PRI getADC
    
      return 42
      
    DAT
    
    gives me:
    43.97484
    44
    
  • bunkerush5bunkerush5 Posts: 10
    edited 2014-03-04 20:12
    when I do the following equation
       r:=f.fmul(2427.0,f.pow(f.ffloat(adcOut),-1.095))
        r:=f.fround(r)
        pst.str(fstring.floattostring(r))
    

    I get 1.401299e-44 and I am expecting a value from 6-48 depending on the adc value. Is there a way to only show 1 decimal? Without the rounding function I get 10.27675 at a set range.
  • kuronekokuroneko Posts: 3,623
    edited 2014-03-04 20:14
    FRound returns an integer value which should be printed with e.g. pst.dec(f.fround(r)).
    PUB FRound(a)
    {{Convert floating point to integer (with rounding).
      Parameters:
        a        32-bit floating point value
      Returns:   32-bit integer value }}
    
  • bunkerush5bunkerush5 Posts: 10
    edited 2014-03-04 20:19
    perfect. Thanks for your help.
Sign In or Register to comment.