This project came about as a friend builds and restores vintage cars, he has a passion for racing them. The problem he had with his latest project car that for racing in this country he must wear a full face helmet and then he cannot hear the engine. If he goes over 2000RPM he will destroy the engine. These are the sort of engine that tick over a lot slower than our modern turbo charged cars.
The brief was to have a light come on when he got to 2000RPM. After discussion a number of things came out and I came up with a slightly broader spec. The unit would monitor the engine revs and start flashing a light when it got close and flash faster when it got closer. I have a small reflective opto sensor which is used to monitor the flywheel. This is a vintage car, no contact breaker. It has 2 large magnetos. I could try a electronic pickup - a couple of turns round an HT lead may work.
For the hardware a small PIC will surfice, I had a PIC16F88 in my store of parts. And a spare olimex prototype board to build it on. If this works well we can turn it into a PCB later.
Some more pictures. http://theoldmotor.com/?p=66419 http://www.flickr.com/photos/stefanmarjoram/sets/72157632291143542
Software:
I actually tried using both mplabx with the 16f c compiler and Forest Developments WizC (http://www.fored.co.uk). WizC that I had used before when working on the Webbrick home automation system.
In MPLABx there is very little in the way of support libraries to help you along and I found that it is very easy to overflow the 16F hardware stack.
WizC provides a load of support code and manages it well for you. To the point that I had to write circa 100 lines of C code. It also does quite a lot of code optimisation, I feel this is a better buy (£50) than a commercial version of the MPLAB compilers.
The basic structure is to use the capture compare channel and Timer 1 to measure the rotation speed of the fly wheel. Using a 20Mhz clock the timer overflows in just over 100mS, this would correspond to around 600RPM. We need a Crystal clock as we need a clock that is reasonably stable over time and temperature. I average the time ovr 3 readings, this gives an update time at 2000RPM of circa a tenth of a second, it needs to be more often than once a second for this sort of use.
WizC primarily uses a polling loop to run your code, and I only used the interrupt handler to handle a the serial interface. For diagnostic purposes readings are logged out over the hardware serial port. As an enhancement the rev thresholds could be adjusted, they are stored in the EEPROM.
Here is a picture of the prototype board in a plastic box.
The sensor is soldered to the end of a screened lead, I expect a lot of electrical noise and will need to put some good filtering on the battary supply from the car.
Found a nice little dashboard warning light from Merlin motor sports, has 2 sets of LEDs, 8 green and 6 red. I was not sure if this is going to be bright enough for this use as there is no roof on the car. It was mounted in part of an old brass telescope using the eyepiece lens and it was very visible.
The code drives up to 4 LEDs but we shall use 2, by just moving the leads can chnage the thresholds without a laptop. I used some little black connectors are like the ribbon cable connectors for keyboards and cameras. pull plastic to release push down to lock. I think they came in a large box of surplus from Greenweld in Southampton - thats a long time ago!
Conclusions
The software caused me more headaches than I expected, the 16F PICs have a few wrinkles, the ReadModifyWrite of the IO ports for one and the limited hardware stack.