A/D tacho conversion

Introduction

At some point, the speedometer on my Honda CB250 began to make some weird whining noises. It still functioned correctly though, so I was reluctant to open it up as the clock is a closed unit (pressed shut). Not much later the needle began to lag so disassembly was inevitable...

The outer shell can be opened by plying it with a screwdriver. I'll never be able to close it as good as it was but hey, I had to fix it... Below is the fully dissembled speedo.

The speedo works by rotating a magnet inside an aluminium "cap". The cap holds the needle and is held in place with a small returning spring. When the magnet spins up, it induces Eddy currents in the cap which drags it along. If the magnet spins faster, the cap pulls harder on the spring and the needle moves further up. It's quite nice but very fragile when dirt gets inside. I attempted to fix it but to no avail.

Operating principle and development

Then I got the idea of fitting an RC servo in there that would move the needle. It would have to be a small one, but DX has some very cheap suitable micro servos. To measure the speed, I will use an IR-led/phototransistor that I ordered from Farnell.

To control a servo, you need to give it a PWM signal. Originally, I thought I could convert the pulses from the detector (sort of PPM) directly to a duty cycle of a PWM signal. In the end, I decided to implement it using an STM8S Discovery board. These microcontroller boards are very cheap and flexible, maybe even overkill for this application. The big downside to them is that there are no free compilers/tools available for them and that they are Windows-only.

So, the plan is to stick a white disk with black markings onto the spinning magnet. The phototransistor will see them pass by and generate pulses. The inverse of the time between the pulses is the rpm, which corresponds to a certain km/h. The rpm is then used to control the built-in PWM generator in the STM8SC105 uC.

To be able to easily develop and test the software, I took a small DC brushless motor from a cassette deck. The motor can be controlled with a PSU but I also attached the power carrying wires of an USB cable so I can use the power supply for the servo. I removed it later on as the STM8S board can power the servo itself.

At one side I have attached the phototransistor. It has to be at exactly the right distance to generate optimal pulses, but too close is worse than too far. The datasheet recommends 1mm.

Connecting the phototransistor to the uC is easy:

Also not unimportant is the level of black and reflectiveness of the marked disk. Initially I printed the markings on white paper with a laser printer but this did not gave very good results: the phototransistor's collector kept floating at 3 to 4V. When using black insulation tape, I got a nice 4.6V for the black level.

The video below shows the prototype at work:

Installing in the clock housing

12/11/2010: I received the micro servos from dealextreme. They are really tiny, I was quite impressed... until I connected them. Now I wasn't expecting great quality but the first one judders frequently, jumps around and finally overheats. Rubbish quality. The second one works fine although it's quite noisy. I jammed the gear compartment full of bearing grease but that didn't seem to make a difference. More worrying, the angle of rotation is only just over 90 degrees. That's too low for my application so I tried to put a new axle on another gear inside the servo. This proved too tricky and I had to give up in the end.

So for now I'm reconsidering my options. As there is not a lot of room inside the housing I cannot just put in a "decent" servo...

18/06/2011: After a lot of time trying to find a way to fit the servo inside with a minimal amount of modification (I want the servo to be easily swappable, in case the quality necessitates early replacement), I arrived at this:

However, due to the slow spinning rate of the detection wheel, the time between pulses is so high that at low speed, the needle is very jumpy. This could be solved with a better pattern on the detection wheel or with more sensors. Some averaging would also help.