Project: Tachometer (part 1 – The Basics)

I’ve recently gotten an interesting job: build a custom tachometer for a custom trike. The bike is an usual VW-engined threewheeler, with (I think) a Yamaha front-end. I asked why they aren’t using an aftermarket tacho thats sold from online retailers – ‘They are all ugly.’ (And you expect from me what exactly? 😀 ) Basically the builder complained that all aftermarket tachos are either ugly plastic, and he would not go through the trouble to fabricate a speed pickup for an old-style Smiths gauge. Upon my insistence on some prefabricated solution he told me that he already asked another programmer to do it for him (uh-oh) but that guy was unable to work out the kinks in his design. OK, let me take a look.

Wow. Now I understand why this contraption wasn’t able to do a halfway decent job (on powerup the trip counter would randomly increment itself with ~20000 – I’m not sure this bike travelled that much since it was built.) Let’s see here… loose wires, the panel holding the Microchip uC was cut out of a bigger panel, no filtering on the power lines, plus the hotglue used to hold the graphic LCD to the uC-board was melted away by the sun. Somebody was not thinking here, this guy was able to program a character generator with two charsets (the speed and the mileage were different characters), do the eeprom read/write, but he mucked up the speed calculations. Without looking into the Microchip’s software, I’m absolutely certain that he didn’t use any interrupts for sampling the speed sensor (magnets on the front wheel with a reed pickup) but chose to poll it from a program loop – the random 20000km ‘jump’ at powerup was nicely observed when I shut the unit off with a magnet being right next to the pickup. Natch!

I gave my rundown: this unit is unusable for me, for example if I have to code a character generator, this will go out of budget; the wiring and build are not even up to my low standards (you’ll see); plus the owner complained about difficulties seeing the display – not surprising given the 2.5″ display with the speed lettering barely bigger than 1/2″ and it being at least 3 foot away on the forks. My suggestion: I’ll build a preliminary display with a 4-line LCD screen, work out the bugs, then build a 2nd version with the displays I intended to use in the finished product: a large 3 1/2 digit LCD for speed, and a 2-line alphanumeric LCD for various data. If everything works as designed, I’ll get the boards made by a professional PCB manufacturer, and build a finished version. We said ok, I took some money in advance for the initial expenses; and mentally prepared that I will not do this for the money, but for the experience.

First, let’s get the logic right! It is foolish not to use interrupts for this type of job, my first thought: use an edge-triggered INT1 to reset one of the Timer/Counters in the Mega88, then calculate the speed from the Timer/Counter’s TCNTx value on the next interrupt. Set up the Timer/Counter so, that the granularity can be used to distinguish between 180 and 181 km/h, and begin slewing above this value (my arbitrary decision – later you’ll see that using only this method, it is actually the slowest speeds that cause headache). To avoid false speed calculations, use the Timer/Counter’s compare match interrupt (TIMERx_COMPA_vect) to disable the Timer (speed too slow). As for the trip odometer, store that in the EEPROM.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s