Go Down

Topic: Bike Computer (Read 2345 times) previous topic - next topic

winner10920

You can always spend the extra time optimizing, never hurt to have a more effecient code
or do you know what died? If its the 8/16u2 you can still communicate if you can get a usb to serial converter or use an rs232 port
if its the atmega328 then you need a new one
if its a part on the board itself, perhaps it can me removed and replaced/jumped out

Graynomad

I've done all sorts of speedo  and tacho designs over the years and never needed floating point.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Jase_MK

Nobody seems to have pointed out the obvious yet that your original maths/measurement isn't correct. You're saying it's a 26inch wheel, then dividing that by 36 spokes to get the distance between spokes. Well 26 inches refers to the DIAMETER of the wheel and you are dividing by 36, suggesting you thought it referred to the circumference. You need to be dividing the circumference of the wheel by 36, not the diameter.

I'd measure the circumference manually as it will vary depending on what tyre you have fitted, but an approximation using pi would give:
3.14*660.4 = 2075mm

So you're speed calculation is out by a factor of about 3, taking your calculation of 5mph up to around 15mph which is what you wanted. Problem solved  ;)


Techylah

Heres the math for diameter in inches (26) and transforming the count N of 1 sec worth of spokes into MPH.
So,
Diameter = 26 and
T = 1.0

miles/hour  =  (N spokes / T seconds)  *  (1 revolution / 36 spokes)  *  (Diameter * Pi   inch/ revolution)  *  (1 ft / 12 inch) * (1 mile / 5280 ft) *
                    (60 seconds / 1 minute)  *  (60 minutes / 1 hour) 

MPH = N * 0.12892

You might want to update faster than 1 sec.  Since you are counting spokes (as opposed to a magnetic, once per revolution sensor) you have that luxury.
Just multiply the above constant by the number of times per second you are updating.  Ex. twice a second makes T = 0.5, effectively multiply the constant by 2 giving:

MPH = N * 0.2578

You should probably round MPH to the nearest tenth MPH with something like:

roundedMPH = (float)((int)(MPH * 10.0 + 0.5)) / 10.0;

Say N is 57 for one interval,
then MPH = 14.6946 and you display
rounded MPH = 14.7

#19
Jun 29, 2012, 09:07 am Last Edit: Jun 29, 2012, 09:29 am by MegaGamerGuy Reason: 1

You can always spend the extra time optimizing, never hurt to have a more effecient code
or do you know what died? If its the 8/16u2 you can still communicate if you can get a usb to serial converter or use an rs232 port
if its the atmega328 then you need a new one
if its a part on the board itself, perhaps it can me removed and replaced/jumped out


it is an atmega328.
after having it powered off for a few days, i plugged it into usb. it stayed on, led blinked twice. i hit reset led blinded twice again.
then power led faded away, and usb device went away. and atmega328 gets hot when pluggin into ext power supply. i can upload new code
until power led fades. the sketch runs as well. it gets hot enough to burn my finger and i think its shutting down because of thermal shutdown
Peace, Love, Light, Infinity

Go Up