Shop OBEX P1 Docs P2 Docs Learn Events
Formula for MPH for Given Time and Wheel Circumference — Parallax Forums

Formula for MPH for Given Time and Wheel Circumference

MikerocontrollerMikerocontroller Posts: 310
edited 2010-04-12 03:38 in General Discussion
· Hi, I'm putting together a bike odometer/speedometer using a Malexis Hall-effect sensor and magnet.· I'm using a BS2 and sampling the sensor output in one second increments using the COUNT function.· I've determined the wheel circumference is 88 inches.· Can someone show me a formula to convert this information to MPH?· Can we do this with one word sized variable?· Accuracy of about 10% is OK.· Thank you

Comments

  • SRLMSRLM Posts: 5,045
    edited 2010-04-10 06:48
    This kind of problem is called dimensional analysis. You simply multiply and convert numbers, working from what you have to what you want:

    (x inches/sec) * (1 foot / 12 inches) * (1 mile / 5280 feet) * (60 sec / minute) * (60 minutes / hour) = 60^2/(12*5280) mph.

    BTW, the accuracy rating you gave isn't much use. Since the BS2 works only with integers, your error will be in units of 1 mph.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • W9GFOW9GFO Posts: 4,010
    edited 2010-04-10 07:13
    1 mile is 63,360 inches or 720 wheel rotations. 1 mph would be .2 revolutions per second. One revolution per second would be 5mph. So mph = counts * 5.

    If you used a total of 5 magnets each pulse per second would be equal to 1 mph, then your equation is mph = counts.

    You could also use only two magnets spaced 72 degrees apart. The time between the two pulses would be in milliseconds - so that mph = 1,000/count. Or if you want accuracy to the tenth use mph = 10,000/count.

    If you just timed how long apart the pulses were in milliseconds (using just the one magnet) then your equation is mph = 5000/count.

    Rich H

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

    Post Edited (W9GFO) : 4/10/2010 8:00:21 AM GMT
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2010-04-10 08:06
    Thank you for the replies. I've got the prototype unit taped to the headstock now. When I get excited I forget simple math. Thanks for not calling it a class project and telling me to look it up myself. Off I go again.....Thanks!
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2010-04-10 08:37
    I just took a test drive and realized the current configuration gives very coarse readings: 0-5-10-15-20 MPH. I can't see a way to increase resolution using the COUNT function unless I add more magnets or reduce the displayed speed update. Maybe the commercial units with one magnet use some form of pulse width measurement. Oh well, back to the drawing board....
  • P!-RoP!-Ro Posts: 1,189
    edited 2010-04-10 13:34
    You would need to find the time between pulses then divide 88 by that number. If you used seconds now you have the distance in inches traveled per second. Then just convert it to inches a mile then divide the top number for mph. Hope this helps and I'm sorry I can't explain it better, I'm actually headed down to take the act right now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pi aren't squared, pi are round. Cornbread are squared!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-04-10 13:49
    someone said...
    Since the BS2 works only with integers, your error will be in units of 1 mph.
    

    Review the //, */, ** operators, take a look at all the math Tracy Allen has done for you, too.
  • W9GFOW9GFO Posts: 4,010
    edited 2010-04-10 17:11
    Mikerocontroller said...
    I just took a test drive and realized the current configuration gives very coarse readings: 0-5-10-15-20 MPH. I can't see a way to increase resolution using the COUNT function unless I add more magnets or reduce the displayed speed update. Maybe the commercial units with one magnet use some form of pulse width measurement. Oh well, back to the drawing board....
    I'll say it again in cased you missed it;

    If you just timed how long apart the pulses were in milliseconds (using just the one magnet) then your equation is mph = 5000/count.

    Something like this:

    DO
    repeat while pulse = 1 ' do nothing while waiting for magnet to pass

    repeat while pulse = zero ' start timing
    count = count + 1
    PAUSE 1

    mph = 5000/count
    count = zero
    DEBUG mph
    LOOP

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-04-10 19:55
    Timing to milliseconds really has to depend on tight program loops without PAUSEs. If it is exactly milliseconds, then as Rich says the conversion on the Stamp will be
    mph = 5000 / trev
    That is, if it takes 1/2 second for one revolution, you are going 10 mph. Here is some more tutorial on Stamp timer loops:
    www.emesystems.com/BS2speed.htm#longpulse that shows how to convert the Stamp's loop timing into milliseconds that you could plug into trev. If you want to display to units of 0.1 mph, then,
    mph1 = 50000 / trev ' one more digit in answer.
    DEBUG DEC mph1/10, ".", DEC1 mph1, " mph",CR ' displays as xx.x mph

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ercoerco Posts: 20,260
    edited 2010-04-11 04:27
    Now I love reinventing the (bicycle) wheel, but of course you can just buy one of these for $2.70· ...· smile.gif

    http://cgi.ebay.com/LCD-Bike-Bicycle-Computer-Odometer-Speedometer-9704_W0QQitemZ200442731209QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item2eab515ac9


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • kwinnkwinn Posts: 8,697
    edited 2010-04-11 14:06
    Mikerocontroller, measuring speed for low pulse rate applications like this is more easily and accurately done by measuring the time between pulses than the number of pulses per unit time as Tracy suggested. The timing does not have to be in any particular units (mSec, uSec, etc.) as long as it is stable and repeatable. It could be the number of times a program loop is executed provided the cpu has a stable time base. All that is needed is a calibration factor to convert the loop count to time.

    A few years back I built a bicycle speedometer using an 8051, a reflective opto sensor, and 2 retro reflectors mounted 180 degrees apart on the rear wheel. For half of a rotation it incremented a counter, for the other half rotation it calculated and displayed speed based on the count, and recorded the speed along with several other readings. The initial calibration was done by measuring the frequency of the count loop with a meter and verified with a sports radar gun and elapsed timer.
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2010-04-12 00:29
    Thanks for the input.· I ran with my first idea and then realized I would be better off using your suggestions.· I modified the program and it displays better and is more responsive.· It needs a little more tweaking· for accuracy.· Yes erco those bike computers are so much more capable but MY system is bigger, slower, more expensive and tempermental.· It was fun building, though!

    Post Edited (Mikerocontroller) : 4/12/2010 12:38:08 AM GMT
    640 x 480 - 64K
  • ercoerco Posts: 20,260
    edited 2010-04-12 03:38
    XLNT! We learn by doing, and you did it. Well done & congrats on gittin' 'er done!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
Sign In or Register to comment.