Fast Engine Speed Sensor
Photo 1 A Mileage Marathon vehicle

Frequency to voltage conversion problem

Every racing car needs information about engine and vehicle during competition. Data is taken to a PC for examination. One piece of information is engine speed and other vehicle speed. Both are measured by Hall sensors, which give pulse output. Counting pulses over time gives a speed, but there is not enough time to count them. In my case a engine of the Mileage Marathon vehicle runs at maximum 4500 rpm or 75Hz. Electric starter runs 300 rpm or 5Hz. If measuring must be taken 5 times per a second, there is only one pulse to count. This is not accurate enough.

Some may suggest to use a voltage to frequency converter ICs like National Semiconductor LM331 or similar Exar part RC4151. These ICs work converting input pulses to constant current, constant time charges. The current charges a capacitor with has a leaking resistor. When the leaking and charging are balanced, a voltage at the capacitor indicates a pulse frequency. These ICs has a problem at low frequencies, they has a high ripple voltage or a slow response time.


Photo 2. A VF-prototype with HALL-simulator

A better solution is measuring time between pulses. This gives the fastest possible indication of speed. Time is however reciprocal to frequency, which means 1/x dividing operation. I do not know any IC, which takes pulses in and gives reciprocal voltage out. Fortunately a modern micro controller like Microchip PIC16F872 (Reference 4) has everything but program built in for this kind of task.


Figure 1 . A VF-software conversion principle
The solution

Pulse output waveform is unsymmetrical so we must count periods, not a pulse on or off time. The CPU TIMER0 is used in continuous count mode. A rising edge of a external input catches pulse counter value to further calculation. The result is pulse period time. After reading time, we reset pulse counter for next cycle. The 1 divided by a pulse period time gives a pulse frequency. This operation needs a 32-bit mathematics routine, which is available in PIC C-compiler supplied by Custom Computer Systems. The frequency is then used to set PIC 10 bit hardware PWM. The PWM counter runs at clock/4 or 3MHz. 10 bits means 1024:1 divider and PWM cycle time is them about 3kHz. Using RC-filter PWM works like 10 bit DA-converter. A 10 ms filter time constant plus a sample time 1/75Hz = 13.3ms will give us the fastest time constant 23 ms. The time constant was verified also by field tests. See a figure 1 for block diagram of hardware and software operation.

Hardware and testing


Figure 2. A VF- hardware principle diagram

As seen in a figure 2, VF-hardware is extremely simple. Besides the processor,
only a 12MHz resonator and RC-filter components are needed.
The circuit needs less than 5 mA 5V. A optional LED indicator takes more current than other circuits. A photo 1 shows a prototype. The D9-type connector is used as a interface to sensor and data logger output. For testing a HALL simulator was used. The rise time of the output was 22 ms as expected. In the tests I found one problem, if simulator was switched off, the output remains at last sample voltage value forever although there is no pulses and output should be zero.
My HALL simulator has a stop-button which slowly decreased frequency to zero.
This verifies the normal operation of frequency to voltage converter. After finding a possible failure mode, I added a new function to software. If the pulse counter counts more than 10138 pulses i.e. 1Hz or 60 rpm, TIMER0 interrupt routine sets a flag to main routine to calculate a new PWM value. Without the simulator this function may not be found in first tests. The measuring range is now 1 Hz to 75Hz or 60.. 4500 rpm, and the resolution is 1/1024. A test pushbutton ramps voltage up and down for testing purposes. A more detailed schematic diagram shows all the components. Input and output led gives some degree of operation in otherwise back box.



Picture 3 A Schematic diagram of the frequency to voltage converter

A processor hardware set up includes a TIMER0 mode and prescaler 8:1 selection, enabling a TIMER0 and a External Interrupts. A TIMER2 is set to PWM mode using the fastest 10 bit resolution. The I/O-port data directions are set in B- and C-ports.
The TIMER0 overflows in 98 us periods and generates an interrupt, which counts increment a 16-bit pulse counter.
The positive edge of the input signal at external interrupt (RB.0) latches a pulse counter value to out counter and sets a new value flag.
The main routine waits a flag from external interrupt routine, divide time pulses to frequency and do a scaling to PWM. This function needs a 32 bit divider software routine.
A full source code listing is shown in VF.C file. A compiled version VF.HEX is ready for programming a PIC16F872.


A new kind of voltage to frequency converter worked well in a Mileage Marathon vehicle with PRO98 car data logger. The engine speed converter has worked as required. It has many times faster response than previous used LM331. I am sure that Bob Pease from National Semiconductor makes LM331 work faster. Because everybody is not a genius, we must use microprocessor instead analog circuits. The next version will have a 2 channel, one for a engine and for a vehicle speed plus a temperature software amplifier. The hardware is so simple that I have not included a PCB-file. This voltage to frequency converter is mainly done inside a software i.e. a virtual peripheral speed sensor.


Shell Mileage Marathon

BS Mileage Marathon team in Finland

A source code

VF.HEX code

Pekka OH3GDO

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License