Frequency "modifier"

Hi guys and gals.

Excuse the title, but that’s the only way I can think of describing what I need to do. Ok, the project I am busy with is going to require me to measure a frequency then change it and send it back out on another pin. This is to calibrate a car’s speedometer.

On the measuring side I thought of using FreqMeasure, but what do you guys think will be the best way to take that frequency measured, change it (for example 100Hz in and 144Hz out) and then send it out via another digital pin? I was thinking something along the lines of blink without delay style? Not sure if that is the best idea or even possible!

Currently the frequency @ 120 KPH is about 226Hz but the speedometer unit requires something like 86HZ @ that speed.

To sum up I need to measure a frequency, change it and send it out again and it will be linear. So if Frequency measured doubles so would the frequency that’s being sent out.

I hope this makes sense. Some ideas and guidance from seasoned programmers would really be appreciated!

Thanks in advance :slight_smile:

At those low frequencies, it wouldn't be too hard at all. You could possibly use a pin change interrupt to time the interval between the input pulses, convert to frequency, divide by 2.628, then output the result, possibly using a library like the "PWM Frequency Library", or directly using timers if you feel confident to do that. (Or with micros()-based output timing.)
Edit: The library might possibly be a bad choice, depending on the required resolution. Offhand, I don't remember if it uses an 8-bit or 16-bit timer.

I would

  • measure the time between input pulses in nanos()
  • use a low-pass filter to get a rolling average of the time between input pulses
    filteredInputPulseTime = .75 * filteredInputPulseTime + inputPulseTime * .25;
  • calculate the output pulse time in nanos, and do the standard blink-without-delay pattern