Shop OBEX P1 Docs P2 Docs Learn Events
Confused on result... — Parallax Forums

Confused on result...

jknightandkarrjknightandkarr Posts: 234
edited 2010-03-16 08:11 in Propeller 1
I'm trying to make a speedometer. I got the desired Mph result, but I'm adding a switch to switch to Kph.

vss:=67                                             'Temporary Speed sensor value
    If ina[noparse][[/noparse]13]==0                                       'Look for Pin13 for 1 or 0
       Mph:=vss*9                                       'Calibrate for 4000ppm sender if pin 13=Low
    else
       Mph:=vss*9/2                                     'Calibrate for 8000ppm Sensor if pin 13=High
    debug.str(fString.FloatToString(Mph))
    If ina[noparse][[/noparse]14]==1                                       'Check for Mph or Kph setting
       Kph:=Mph*1.609344
    else
       Kph:=Mph*1   
    debug.str(fString.FloatToString(Kph))
    myValue := Kph                                      'Copy Kph to myValue



My Mph readout is 0603 when ina[noparse][[/noparse]14] is Low, but when ina[noparse][[/noparse]14] is High instead of getting something like 0970 I end up with 8292. I tried to debug the Mph & Kph values to the serial terminal, don't match what I'm displayed. I've tried "Kph:=Mph**1.609344" and get 0150. What am I doing wrong? I looked up stuff on floating point math, but not much help it seams like.

Joe

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm going insaine. It's SOOOOOO much fun. lol

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-03-16 07:44
    Try:
    If ina[noparse][[/noparse]14]==1                                       'Check for Mph or Kph setting
           Kph := Mph * 1_609_344 / 1_000_000
        else
           Kph := Mph
    



    It looks like there is a problem though. To get MPH you multiply vss by nine? That makes for a very limited resolution, your results will be very coarse - may be okay if it is for a rocket. smile.gif

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 3/16/2010 7:55:26 AM GMT
  • jknightandkarrjknightandkarr Posts: 234
    edited 2010-03-16 07:55
    It's acctually for a car. My speed sensor is 4000 pulses per mile, so at 60 Mph, 4000 pules per minuite, & 66 2/3 per second, 67 gives me 60.3 Mph, so it should be good, thanks, I'll try your suggestion right now.

    Joe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol
  • jknightandkarrjknightandkarr Posts: 234
    edited 2010-03-16 07:57
    That made it PERFICT, Thanks!!! I'll remember that little trick. cool.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol
  • W9GFOW9GFO Posts: 4,010
    edited 2010-03-16 08:02
    jknightandkarr said...
    It's acctually for a car. My speed sensor is 4000 pulses per mile, so at 60 Mph, 4000 pules per minuite, & 66 2/3 per second, 67 gives me 60.3 Mph, so it should be good, thanks, I'll try your suggestion right now.

    Joe

    I see, the real MPH is MPH/10, makes sense now.

    Still, if your goal is to display MPH to the tenths I think you will not get good results. For example, here would be the progression; 0.9 mph, 1.8mph, 2.7mph, 3.6mph... and so on.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.

    Post Edited (W9GFO) : 3/16/2010 8:10:41 AM GMT
  • jknightandkarrjknightandkarr Posts: 234
    edited 2010-03-16 08:11
    No, it's not going to be used. I only use the 10ths for general calibration purposes, However the odometer on the other hand MUST be in 10ths & close to perfict as possable.

    Joe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol
Sign In or Register to comment.