bicycle speedometer

ChrisRobson

New Member
I am struggling to program a speedometer. It is to work in the same way as a bicycle one where a reed switch is attached to one leg of the fork and a magnet is attached to the wheel. I am not sure on how to do the program that will convert the pulsing input into something which can be displayed on a seven segment display.
 

Rickharris

Senior Member
What are you unsure about - do you as yet know what you need the processor to do. You appear to have sorted out the input and the output areas.

How would you count pulses over a period, or count the interval between pulses so you can work out how many per second.

How is the number of pulses related to the circumference of the wheel and the distance traveled?

What processor do you intend to use, how far have you got to date? have you looked at the commands PDF to see what commands might work for you.
 

womai

Senior Member
As indicated in the previous post, your options are to (1) either the number of pulses within a specific time interval, or (2) measure the time between two pulses.

(1) has the downside that your worst-case error (uncertainty) is at least 1 count, so it's not good a counting slow rotation. E.g. to have a precision of 1% or better you'd need at least 100 rotations in your time interval. On the Picaxe you can use the "count" command (see Basic manual for details). It has a maximum interval of slightly over a minute (65535ms to be exact), so for 1% accuracy you'd need at least around 100 rpm for it to work (your necessary meaaurement interval would then be close to a minute).

(2) is better suited for slow rotation. On the Picaxe you'd use the "pulsin" command for that. It has the same maximum timeout as (1), but you get very fine resolution (10us at 4 MHz clock frequency), and you need only to wait a single revolution for a measurement. You probably want to measure the time the switch is closed, then measure the time the switch is open, and add those two numbers to know the rotation period. (you may get away with only measuring the open time if the close time is very short). Another option would be to set up a flip-flop as a 1:2 frequency divider, then you only need to measure either a high pulse or a low pulse which is then equal to your rotation period.

In most cases I would go with (2) because it gives you much shorter measurement time for the same accuracy, unless your rotation is REALLY fast (would have to be 1000s of RPM).

In the bebginning I would start out with using the sertxd command to send the data back to the PC and watch the results on the terminal that's included in the programming editor. Once your measurement works the next step would be to implement some sort of display (7-segment LED, or some LCD display). The AXE033 serial display is great and very easy to use, also needs only a single output pin on the Picaxe (it is much more effort to drive seven segment displays, both harware wise and programming wise).

Wolfgang
 

slurp

Senior Member
it's worth thinking about the options for ticks over time or time between pulses up front.

I'd a quick look on line at various wheel and tyre sizes and how they may affect circumference... it would appear that the average cyclist may travel at 12-15 miles per hour but 30-35 is still a reaonable speed for those pushing themselves

1mph leads to one tick every 4.5 - 5 second
and 5mph is where you start to see one tick per second.

Leading to 6 ticks per second at 30mph or one tick every 0.15-0.16 seconds. Breaking the problem down and looking at the time frame for action may direct your thought in the program design and how you might design your program and measurements of speed.

As said, how accurate do you want to be? whould a lost 0.05 sec kill your accuracy? what about a missed tick?

good luck

regards,
colin
 

hippy

Technical Support
Staff member
I suspect that as speed lowers, any instantaneous reading is likely to vary from one to the next and it may be necessary to add some averaging function. Get something working first then enhance is my recommended path.

To increase low-speed accuracy, one could simply add more magnets to the spokes and thus increase the number of pulses per revolution of the wheel, although this may then dictate a pulse counting algorithm if not spaced evenly.

There is no reason not to have more than one reed relay, on different radius, and there could be different numbers of magnets at each radius and the PICAXE could select which to use.

It might be possible to put a reed relay to the front of the fork and one to the back on the same radius, with one or more magnets, and time the period between one reed activating and the next. This might be the 'balanced' optimum, and the more magnets there are, the more accurate low speeds can be determined - I think this might be my prefered solution, but might need R-S flip-flop hardware to get a pulse to show the time of travel between the two reeds ( a large cap with one charge-up / one discharge reed switch may do the job ? )

The three options do seem to be measuring reed closure pulse widths (short), time between pulses or counting the number of pulses in a time period. It may be that each method is more suitable for a particular speed range than another, so being able to switch between each might be useful.

You should perhaps determine what speeds you are looking at measuring; are you 'parambulating', racing or both ? Then look at what pulse rates and times the various schemes would give you, and determine which would give you the results you want to see and are optimal for a PICAXE.

For racing, and to just dive in, a single reed and magnet is probably the best, will give you a feel for what you are doing which can be applied later. Build the hardware, bash out some code for pulse timing and pulse counting, with the results via SERTXD/SEROUT to a PC as suggested, then take it from there. Use the Mk I as a prototype, then expect to start Mk II software with what you've learned.

It looks like an interesting project with a lot of scope for enjoyable experimentation and learning. I don't do bikes, but you've set me off on a tangent of thought if I could measure walking speed with a pressure sensor / piezo placed on a heel. So many interesting projects, such little time.

Edited by - hippy on 20/06/2006 14:07:31
 

ChrisRobson

New Member
thanks everyone, I'm going to look into this method:
<i>(2) is better suited for slow rotation. On the Picaxe you'd use the &quot;pulsin&quot; command for that. It has the same maximum timeout as (1), but you get very fine resolution (10us at 4 MHz clock frequency), and you need only to wait a single revolution for a measurement. You probably want to measure the time the switch is closed, then measure the time the switch is open, and add those two numbers to know the rotation period. (you may get away with only measuring the open time if the close time is very short). Another option would be to set up a flip-flop as a 1:2 frequency divider, then you only need to measure either a high pulse or a low pulse which is then equal to your rotation period. </i>

Its going to be a race computer, therefore speeds can be anything up to 50mph, but mostly averaging at about 25mph.

I have just completed my AS exams, and this is going to be part of my A2 project. Its still in the research stages at the moment, and I'm trying to find a way of programming a pic to do the job. Therefore, my knowledge of pics is fairly basic. So far I have been using the flowchart method.

where do I find the 'pulsein' command? or can it only be used if you program it in basic?

<i>What processor do you intend to use, how far have you got to date? have you looked at the commands PDF to see what commands might work for you. </i>

I was going to use a pic18. what is the difference between the 18, 18A and 18X?




Edited by - Chris-meister on 20/06/2006 17:34:30
 

womai

Senior Member
Ooooops, watch out, major misunderstanding on the way :)

The Picaxe's are pre-programmed Microchip Pic's with a bootloader, and they have a Basic interpreter (!) burned in. You write programs for them in a simple Basic variant which gets converted into some compressed format - NOT machine code! more like P-code in Visual Basic - and downloaded onto the chip. There the interpreter executes those commands.

The Picaxe 18/18X/28X/40X are based on the Microchip 16F series (e.g. 28X is 16F873).

The fact that they run an interpreter makes them very slow (around 2000 commands per sec, or up to around 8000 with overclocking to 16 MHz) and they have limited code space, but they are super-simple, easy to use, hide all the complexity of the &quot;real&quot; PIC. Development tools (Programming editor) are free, and if you have a minimum of electronics knowledge chances are you have your first &quot;blinking LED&quot; setup in well below one hour. I'd recommend one of the starter kits for prototyping, but you don't have to use one to get going, it just makes for faster success.

Overall, Picaxes are actually able to perform a large variety of tasks pretty well, and for applications where they fit they are usually easier to use than a &quot;real&quot; Pic; I use them a lot for prototyping. Your bicycle speedmeter seems to me very feasable.

For documentation, go to www.picaxe.com and click on &quot;technical support&quot;. There you find the most important doecuments, among them the Basic command overview.

Wolfgang

 

eclectic

Moderator
Have a look at this program.

<A href='http://picaxe.orcon.net.nz/bikeodo.bas' Target=_Blank>External Web Link</a>
Although it's for an odometer, a lot of the principles might still apply.

It was found on Stan Swan's site.
You'll find it by going to the Picaxe Home page,
then Links.
e.

Edited by - eclectic on 20/06/2006 18:19:24
 

Rickharris

Senior Member
As a UK teacher of D&amp;T including Systems and Control Your project sounds interesting - Although you can and should research what and where you can find - including tapping expert opinion you should also start by doing some essential reading yourself.

I strongly reccomend you read all 3 of the basic PDF manuals you will find in the Help file that came with programme editor. In fact if more than one of you are using Picaxe micros I would ask your teacher to print them out for you.

PWM and The other pulse measuring commands are only available in the Basic commands for the Picaxe. I would think you would not be able to make your project using just the flow diagram programming system - Although this is a good start prior to writing any progrmme.
 

womai

Senior Member
Another thought. The 0.65sec max timeout for the pulsin command may be a bit of a stumbling block (for accurate average speed etc. you want to acquire times of slow speed even in a race where the bike rolls fast most of but not all the time). One solution could be to under-clock a 28X picaxe to 1MHz or (by using a different resonator) which gets you up to 2.6sec timeout - should be good enough down to very slow bike speeds. Of course you'd need to replace that with 4 MHz resonantor for program download.

Chances are the program execution at 1 MHz becomes too slow to do all the other necessary tasks, so you could use a master Picaxe running at 4 or even 16 MHz, which then talks to the slave Picaxe (running at 1 MHz) through a serial connection (using the serin/serout commands).

Wolfgang


Edited by - womai on 20/06/2006 21:49:39
 

slurp

Senior Member
Saw some interesting solutions to womia's suggestion for differing oscillator speeds - programmable oscillators

First saw these with PICs where you wanted a low current standby with program ticking over monitoring various functions. Depending on the input you then stepup the oscillator speed to do the fast processing required, before going back to the slower standby.

for a one off programming it's probably over kill solution

regards
colin
 
Top