Can ATtiny45 be used for this application?

I need to create a precise speedometer for a bicycle. The idea is to mount several magnets for a Schmidt trigger on the rear hub. I need to know could a ATtiny45 be capable of measuring this speed and sending PWM signal result to an Arduino Duemillanove at the same time?

One of my friends said it might have some problems with "interrupt" or something. I am not really so keen on microcontrolers.

Thanks in advance!

Kris

I'm going to say... probably... :smiley:

But, if you are using a Duemillanove (or Uno), what's the ATtiny45 for?

One of my friends said it might have some problems with "interrupt" or something. I am not really so keen on microcontrolers.

Probably right...

A microprocessor/microcontroller can only do one thing at a time.* So in your case, it needs to switch between timing the wheel rotations and updating a display (or sending out PWM, or whatever).

If it's updating the display when the wheel sensor gets triggered, you need to interrupt the display process (for perhaps several microseconds) and "grab" the time before too much time goes by and the timing/speed gets fouled-up.

The idea is to mount several magnets...

I think it's "traditional' to trigger once per revolution. The more magnets you use, the more chance there is for a problem. Maybe go with two if you want to keep the wheel perfectly balanced. If you have 10 magnets, and one gets knocked out of position or fails for some reason, you'll be off 10% and you may never know... More readings isn't going to make it more accurate. It's just going to give you more data/readings. How many times per wheel revolution can you read the speed display? :smiley: For the microprocessor & firmware, it's no problem... Several triggers per revolution is s-l-o-w for the processor.

...for a Schmidt trigger on the rear hub.

You're going to need a hall-effect sensor too. :wink:

  • Your computer is multitasking all of the time, even when you're only running one application. It's constantly updating the display and monitoring/updating the mouse, and a bunch of other stuff, etc. But, (assuming a single core) it's really only doing one thing at a time, rapidly switching between tasks and handling interrupts.

DVDdoug:
I'm going to say... probably... :smiley:

But, if you are using a Duemillanove (or Uno), what's the ATtiny45 for?

One of my friends said it might have some problems with "interrupt" or something. I am not really so keen on microcontrolers.

Probably right...

A microprocessor/microcontroller can only do one thing at a time.* So in your case, it needs to switch between timing the wheel rotations and updating a display (or sending out PWM, or whatever).

If it's updating the display when the wheel sensor gets triggered, you need to interrupt the display process (for perhaps several microseconds) and "grab" the time before too much time goes by and the timing/speed gets fouled-up.

The idea is to mount several magnets...

I think it's "traditional' to trigger once per revolution. The more magnets you use, the more chance there is for a problem. Maybe go with two if you want to keep the wheel perfectly balanced. If you have 10 magnets, and one gets knocked out of position or fails for some reason, you'll be off 10% and you may never know... More readings isn't going to make it more accurate. It's just going to give you more data/readings. How many times per wheel revolution can you read the speed display? :smiley: For the microprocessor & firmware, it's no problem... Several triggers per revolution is s-l-o-w for the processor.

...for a Schmidt trigger on the rear hub.

You're going to need a hall-effect sensor too. :wink:

  • Your computer is multitasking all of the time, even when you're only running one application. It's constantly updating the display and monitoring/updating the mouse, and a bunch of other stuff, etc. But, (assuming a single core) it's really only doing one thing at a time, rapidly switching between tasks and handling interrupts.

The precision is more for the turning/not turning than the actual value of the speed. So I think the hall effect sensor(forgot to mention) and Schmidt trigger would do the job.

So PWM is probably not a good idea right? should I maybe use ATtiny2313 with Rx/Tx to communicate with the arduino?

So PWM is probably not a good idea right?

Right.

should I maybe use ATtiny2313 with Rx/Tx to communicate with the arduino?

Good choice. SPI or I2C are also good choices.

If the ATtiny will only be reading the sensor(s) and reporting the results, you may be better served by using a 1-Wire counter.

If you do use an ATtiny, get the model with the most memory. Instead of using an ATtiny45, use an ATtiny85; instead of an ATtiny2313, use an ATtiny4313. The difference in price is generally very small and no one has ever complained about having too much memory.

Is there any major difference in complexity or speed comparing the 3 different serial types mentioned?

Which vould be the smallest/cheapest? ATtiny85 with SPI?

I suspect constraining your questions will garner more responses.

I need to create a precise speedometer for a bicycle.

How precise? If you measure at the wheel you will measure how many revolutions it made. So the errors in your measurement will originate from deviations in the diameter of the wheel which is usually not constant.

If you measure with GPS there are other sources for errors.

So the first question is how precise does it really need to be?

The precision is more for the turning/not turning than the actual value of the speed.

So the only "precision" is maybe the response time in making the decision. You can't have precision in the value of yes/no piece of data.

If you do in fact need precise speed then using more than one magnet will only improve the response time of the sampling not the precision of the readings, and in return it may introduce errors if the magnets aren't exactly placed.

So what's it to be, turning detection or exact speedo? And if so how exact, over what speed range, and what response time is needed?


Rob

If you only use 1 event per wheel revolution then you'd better not want precision for any time you are changing speed. And as Udo points out, wheel diameter does change. Think not? Check your tire wear and air pressure and weight of rider(s) and baggage -- but the difference will be a few % at most if you don't ride on flats.

If your speedometer is a solid roller that contacts the tire tread then you can get the real speed. If the roller is a timing wheel (has holes or spokes) then you can use a light bridge and measure movement in a small fraction of a wheel turn. If your roller generates even a small electric current you can measure that as an analog to your speed in about 1/10th of a millisecond (the ADC is that slow, yes, slow). Any of that would beat hell out of getting 1 read per about 4 meter wheel turn.

I've been wondering if having a magnet near the wheel rim (conductive rim only) would generate enough eddy current to measure as the wheel turns... sensing parts list: bracket, magnet, Hall sensor; zero moving parts. Or maybe... send a little juice to a coil next to the rim and as it induces current in the rim there will be a change in either the current draw in the coil or in the field it generates, nothing is free!

As to missing a sensor event, it's possible but do some math. At 63-64 kph a 700 cm bicycle wheel turns 4 times a second. That's 250 ms per turn. You can -easily- check a digital sensor 10x per millisecond and still do some math and bit-bang pins or ports if you use small, non-blocking code and stay away from slow operations. With interrupts you can get that event even more sure but do you need to? A magnet on a hub can be be sensed long enough to give several reads before it passes, even at speed.

Interrupts have an effect on the timers, they stop while the ISR is running. If it's just a few microseconds then the effect is less than 1% but there it is, nothing's perfect.

Maybe the best would be to use 2 Tinys. One to watch the wheel and one to run the LCD. But don't use regular serial between them for communication, they do support SPI and I2C. Send digital data 1 byte at a time and the watcher will not have to look away for more than a few microseconds at a time.

Why bother with the ATtiny at all? It's overkill. All you need is a Hall sensor such as the US1881. It can easily drive a few metres of cable to the Arduino, although you may need to use an external pullup resistor instead of the internal high resistance one.

As for the number of magnets to use, the US1881 switches on when it see a N pole and off when it sees a S pole. So you need at least 2 magnets. More magnets will give you faster update of the speed reading at low speeds, but they need to be alternating N and S poles.

And you go from Hall sensor to driving a meaningful display how?

GoForSmoke:
And you go from Hall sensor to driving a meaningful display how?

Using the Arduino Duemillanove of course - see the original post.

Why a whole board? A 328P would do and if the LCD is serial, a single tiny might do.