PDA

View Full Version : math help

TC
08-18-2008, 05:21 AM
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!

PJ Allen
08-18-2008, 05:58 AM
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).

Franklin
08-18-2008, 06:10 AM
Which would allow you to update your display approximately every three seconds.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

PJ Allen
08-18-2008, 06:16 AM
More time to eat paste, man.· I just work with what I'm given.

Franklin
08-18-2008, 06:26 AM
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

TC
08-18-2008, 06:29 AM
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!

TC
08-18-2008, 06:30 AM
but I could be wrong

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

PJ Allen
08-18-2008, 06:32 AM
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.

TC
08-18-2008, 06:41 AM
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!

PJ Allen
08-18-2008, 06:51 AM
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.

TC
08-18-2008, 06:53 AM
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!

SRLM
08-18-2008, 01:16 PM
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 Allen
08-19-2008, 12:52 AM
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 (http://www.emesystems.com)

TC
08-19-2008, 03:03 AM
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!

TC
08-19-2008, 03:06 AM
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 Allen
08-19-2008, 06:27 AM
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 (http://www.emesystems.com)

erco
08-19-2008, 07:22 AM
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=item2 60275460238&_trkparms=39%3A1%7C66%3A2%7C65%3A15%7C240%3A1318&_trksid=p3286.c0.m14

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."

TC
08-19-2008, 08:58 PM
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=item2 60275460238&_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!

TC
08-20-2008, 04:44 AM
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!

TC
08-20-2008, 05:15 AM
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!

PJ Allen
08-20-2008, 06:37 AM
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.·

TC
08-20-2008, 06:54 AM
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

PJ Allen
08-20-2008, 08:21 AM
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.