# Frequency to PWM output

I am trying to convert the mechanical speedo in my car to run from the vehicle speed sensor that's fitted to the gearbox. I need a method to covert the pulses from the sensor (0 to +5v) to drive a 12v motor that will drive the speedo. I've calculated that the VSS outputs 7Hz at 10MPH linearly up to 87HZ at 120MPH. From this, the speedo requires a rotational input from the motor of 167RPM at 10MPH, linearly up to 2000RPM at 120MPH

I've looked at frequency to voltage converters and frequency to PWM converters but am unsure of the best way to do this. Ideally the motor should be accurately controlled so was erring towards a PWM output.

Can someone point me in the right direction? A simple circuit with some adjustability so it can be calibrated.

Apologies if this is a little short on info, I'm a newbie at this!

Thanks in advance :)

## 2 Answers

A DC motor has a voltage rating and maximum RPM which is linear above some threshold to get it started due to stiction. It is linear when there is no load on the motor. However when mechanically loaded , current will rise and the RPM will drop so another speed sensor on the motor is necessary to keep it regulated while voltage must be increased a bit to generate power to match the mechanical power.

• Are you dictating your answers into some sort of speech to text application? This is gibberish. – Dave Tweed May 16 '18 at 12:57
• Yes using an iPod SIRI . Sawwee – Sunnyskyguy EE75 May 16 '18 at 13:00
• Please don't. There is enough gibberish on this site as is. – winny May 16 '18 at 14:03
• I corrected it before I saw Dave’s note OK and please don’t compare my answers to gibberish on the site – Sunnyskyguy EE75 May 16 '18 at 14:43

You've told us nothing about your level of skill or experience — not here and not in your profile — so it's hard to know where to begin.

There are two basic approaches: open-loop and closed-loop.

If your motor's voltage-to-speed characteristic is linear enough over the range of speeds you require, open loop would be the simplest approach. It basically boils down to converting the input frequency to a variable duty cycle digital signal.

There are two simple ways to create a variable duty cycle: you can generate pulses with a constant period and vary the pulse width (called PWM, or Pulse Width Modulation for obvious reasons), or you can hold the pulse width constant and vary the period (called PPM — Pulse Position Modulation). Since you're starting with a variable frequency/period, the latter can be applied directly.

You just need a timer (such as the ubiquitous 555) that is triggered by the rising (or falling) edges of the input signal and has a period slightly shorter than the shortest input period. 87 Hz would imply something on the order of 10 to 11 ms. You calibrate it by varying the pulse width.

On the other hand, if your motor isn't linear enough, you'll have to use closed-loop control, which basically means that you need to measure the actual speed of the motor and adjust its power input to get the exact speed you want for a given input frequency. There are many ways to go about this, but the simplest hardware would be to use a small microcontroller. Let me know if you want me to expand on this.

OK, you basically need a small microcontroller that has three hardware timers. You're going to use one to measure the period of your input signal, one to measure the period of your motor rotation (gotten from something like an opto interrupter), and the third to generate a PWM signal to control the power to the motor.

You measure the input period and apply some math to determine what the corresponding motor period should be. You compare this with the actual measured period of the motor, and use the difference (error) to drive a control algorithm (e.g., ) that adjusts the power going to the motor.

• Hi apologies.... so I've built some simple 555 based circuits before, to control a heater valve on a car, and various other bits, its all been what I've been able to glean on forums like this, and not from from first principles. I havent yet bought the motor, but my thinking was that if I got one that maxed out at 2000rpm and use PWM or PPM (whichever is easiest/better) to control it. – tomedee May 16 '18 at 13:27
• If you can expand on how I could use a microcontroller, that would be appreciated :) – tomedee May 16 '18 at 14:02