Shop OBEX P1 Docs P2 Docs Learn Events
math help — Parallax Forums

math help

TCTC Posts: 1,019
edited 2008-08-20 01:21 in BASIC Stamp
I need a little math help. I am making a bike speedometer from leftover parts. I am using a BS2, a MAX7219, a three digit LED display, a Unipolar Hall-Effect switch, and 16 high power magnets. I would like to use all three digits of the display to display Mile per hour.· I was thinking of using the COUNT command for one second. I figured there is going to be 12293 pulse per mile· ((26.25” diameter *pi)/63360 inches in one mile)*16 magnets. I would like the output to show the 1/10 MPH, and I am using the code for the MAX7219 with some modifications for three digits.
Thanks TC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-17 22:58
    At 1 mph, if you could accumulate COUNTs for 1 hr (3600 sec) you'd get 12293 pulses.

    At 1mph, if you accumulated COUNTs for 1sec and divided by 3.414 you'd get mph.· So, if you accumulate COUNTs for 293 msec (1/3.414) the accumulated COUNTs will equal mph.· If you accumulate for 2930 msec, you will get mph*10 (your 1/10mph).
  • FranklinFranklin Posts: 4,747
    edited 2008-08-17 23:10
    Which would allow you to update your display approximately every three seconds.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-17 23:16
    More time to eat paste, man.· I just work with what I'm given.
  • FranklinFranklin Posts: 4,747
    edited 2008-08-17 23:26
    That comment wasn't pointed at you, your math is correct. It was to the OP just in case he thought he could get updates every second.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • TCTC Posts: 1,019
    edited 2008-08-17 23:29
    so I am going to have to do 2 COUNT commands. and dont you think updating the display every 3.2 seconds is a little slow?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • TCTC Posts: 1,019
    edited 2008-08-17 23:30
    but I could be wrong

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-17 23:32
    Dude, it's your design; I'm just the "math help."· I'm not suggesting that you do anything, in fact I purposely avoided doing so.
  • TCTC Posts: 1,019
    edited 2008-08-17 23:41
    point taken. was just making sure I understand what you were saying. the thing I dont understand 293 = MPH, and 2930 = one tenth (1/10) MPH. shoud it be 293 = 1/10 MPH and 2930 = MPH.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-17 23:51
    2930 would keep the window open long enough to accumulate COUNTs enough to approximate down to this 1/10 "precision".· So, 15.7 mph will show up as 157 counts.
  • TCTC Posts: 1,019
    edited 2008-08-17 23:53
    Now I get it, thanks alot. Got to quit eating the paste, I should switch to paint chips.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • SRLMSRLM Posts: 5,045
    edited 2008-08-18 06:16
    Why do you have 16 magnets? If you expect the display to update every 3 seconds, then one would work. Of course, you could just keep dividing the sample time until you get a good measurement. A good refresh rate would be about every quarter second. Otherwise, why not just go with a commercial model? I got mine for $20 and it's lasted 2500 miles with no battery replacement in sun and rain. It would be tough to design a better system from scratch.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-18 17:52
    Suppose you want both 1 second updates and also resolution to xx.x for the display.

    One way would be to average a series of 1 second readings and interpolate.

    COUNT 0,1000,result
    result = result ** 19192   ' multiply * 1/3.414
    '  that result will bobble between n and n+1 mph
    '  A moving average of 10 readings would be good here and allow interpolation to 0.1,
    ' but a low pass IIR smoothing filter is simpler:
    IF first THEN   ' initialize the accumulator the first time through
      accumulator = result * 16
    ELSE
      accumulator = accumulator ** 61441 + result           ' smoothing function y = y*15/16 + x
      result = accumulator */ 160
      debug DEC result/10, ".", DEC1 result   ' result interpolated to 0.1
    ENDIF
    



    Another way to approach this is to measure the time between magnets, rather than to COUNT the number per second.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • TCTC Posts: 1,019
    edited 2008-08-18 20:03
    SRLM said...
    Why do you have 16 magnets? If you expect the display to update every 3 seconds, then one would work. Of course, you could just keep dividing the sample time until you get a good measurement. A good refresh rate would be about every quarter second. Otherwise, why not just go with a commercial model? I got mine for $20 and it's lasted 2500 miles with no battery replacement in sun and rain. It would be tough to design a better system from scratch.
    They were from a pair of old speaker box grills. I would want a refresh rate faster than 3 seconds, but it is not that bad. commercial model = $20, mine = FREE + SOMETHING TO DO. I am not looking to build a beter system.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • TCTC Posts: 1,019
    edited 2008-08-18 20:06
    Tracy Allen said...
    Suppose you want both 1 second updates and also resolution to xx.x for the display.

    One way would be to average a series of 1 second readings and interpolate.

    COUNT 0,1000,result
    result = result ** 19192   ' multiply * 1/3.414
    '  that result will bobble between n and n+1 mph
    '  A moving average of 10 readings would be good here and allow interpolation to 0.1,
    ' but a low pass IIR smoothing filter is simpler:
    IF first THEN   ' initialize the accumulator the first time through
      accumulator = result * 16
    ELSE
      accumulator = accumulator ** 61441 + result           ' smoothing function y = y*15/16 + x
      result = accumulator */ 160
      debug DEC result/10, ".", DEC1 result   ' result interpolated to 0.1
    ENDIF
    



    Another way to approach this is to measure the time between magnets, rather than to COUNT the number per second.

    How would I be able to figure for time between magnets?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-18 23:27
    At 1 mph, the time between magnets would be around 0.293 second, and at 40 mph it would be around 0.00733 second.

    One way to measure times with the Stamp is with a PULSIN command. An external flip flop circuit could toggle from high to low as alternate magnets pass by, so that you would have a square wave cycle intead of a series of pulses. The PULSIN command on the BS2 has a resolution of microseconds. It will measure up to 0.131 second before it times out, but longer times for you would be an issue only for speeds under 2.3 mph, and there are ways around that. Once you have the pulse time (in units of 2 microseconds), a formula to convert to xx.x mph is,
    mph = 58570 / (result / 25 )   ' result from PULSIN command
    DEBUG CR,DEC mph/10, ".", DEC1 mph
    


    Something like that would call for a smoothing filtering to iron out the difference between magnets. The reed switches have to be debounced with RC circuits in any case.

    Alternatively, ithe PULSIN could measure the time high without an external filp flop. But that requires a bit of a fudge factor to account for the time the switch is closed, and a calibration too for the air in the tire.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ercoerco Posts: 20,256
    edited 2008-08-19 00:22
    I certainly understand the joy of rolling your own design, just to learn how things work. My favorite thing is to re-invent the wheel my way. Having said that, I'll put in a plug for an amazing little·$4.95 bike computer off eBay,·direct from Hong Kong. I ordered one just to see what it was like and it works great. Free shipping, and that's their full "Buy it Now" price, so it's less than $5 to get a bike computer shipped from Hong Kong. I work in the consumer products industry, and it's just unbelieveable to me that they can make any money doing that.·Using those factors, a BS-2 would cost under $2.

    http://cgi.ebay.com/New-LCD-Bike-Bicycle-Computer-Odometer-Speedometer-K53_W0QQitemZ260275460238QQcmdZViewItem?hash=item260275460238&_trkparms=39%3A1%7C66%3A2%7C65%3A15%7C240%3A1318&_trksid=p3286.c0.m14

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • TCTC Posts: 1,019
    edited 2008-08-19 13:58
    erco said...
    I certainly understand the joy of rolling your own design, just to learn how things work. My favorite thing is to re-invent the wheel my way. Having said that, I'll put in a plug for an amazing little·$4.95 bike computer off eBay,·direct from Hong Kong. I ordered one just to see what it was like and it works great. Free shipping, and that's their full "Buy it Now" price, so it's less than $5 to get a bike computer shipped from Hong Kong. I work in the consumer products industry, and it's just unbelieveable to me that they can make any money doing that.·Using those factors, a BS-2 would cost under $2.

    http://cgi.ebay.com/New-LCD-Bike-Bicycle-Computer-Odometer-Speedometer-K53_W0QQitemZ260275460238QQcmdZViewItem?hash=item260275460238&_trkparms=39%3A1%7C66%3A2%7C65%3A15%7C240%3A1318&_trksid=p3286.c0.m14
    That is wild!!! Leave it up to Hong Kong. I could not find anything about it displaying MPH.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • TCTC Posts: 1,019
    edited 2008-08-19 21:44
    well while riding out Fay, I installed the magnets to the rim. I think 16 magnets is a little to much. so I installed only 8 magnets. Would I just have to change the COUNT from 2930 to 1465? Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • TCTC Posts: 1,019
    edited 2008-08-19 22:15
    I just found out that will not work. if I am understanding the math, I need to count for 5857ms. I am not a math wizard so I might ask many questions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-19 23:37
    Why not dispense with the 1/10 "accuracy"?· I think that would not have been a highly credible reading anyway.·

    If you want "big numbers",·you could set up a push-button to alternate between mph or·feet/min readings or km/hr,·something like that.·
  • TCTC Posts: 1,019
    edited 2008-08-19 23:54
    I just wanted to use all of the digits. But you have gave me another idea,·MPH and a·trip odometer with a push of a button. Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!

    Post Edited (TC) : 8/20/2008 12:55:00 AM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-20 01:21
    You'll have to decide on one or the other or get a Propeller.

    Now I'll make a·suggestion.· Your idea is good, you've found that reality bites, but stay on track.
Sign In or Register to comment.