# Electronic – Reversing a .5-4.5V analog sensor output to 5V-0V

analogpwmsensor

I have a pulse width modulation (PWM) control board that uses a 0-5V input via a potentiometer to control a DC motor speed. As I understand how this works, the potentiometer goes from 0% PWM at 0V to 100% PWM at 5V. I want to use a pressure sensor that outputs .5VDC at 0 PSI to 4.5VDC at 100 PSI to control the DC motor. Specifically, the controller will need to be at 100% PWM when the pressure is 0, and 0% PWM (off) when the pressure is at 43 PSI or 2.2VDC.

I found a somewhat similar question here,
How do I invert the output of this current sensor using the other side of the LM358?
but the answer was not clear to me.

If you had the code for the micro doing the PWM, this would be a trivial firmware change. However, it seems you don't have access to the internals of the "control board".

What you need therefore is a inverting amplifier. You want 500mV-4.5V to map to 5V-0V. Or put another way, you want a gain of -1.25 centered around 2.5 V. This is easy to do: The gain is -R2/R1, which is -1.27 in this example. R3 and R4 form a voltage divider to make the 1/2 supply level around which this circuit will amplify the input. C2 attenuates supply noise on the 1/2 supply voltage.

Most rail to rail opamps would work.

Thanks to Anindo's comment, I see now the problem is really mapping 500mV-2.2V to 5V-0V.
That is a gain of -2.94 with some offset. Specifically, you want

OUT = -2.94 * IN + 6.47

However, this circuit will essentially subtract first, then multiply by the gain. It is therefore more useful to write the same relationship as:

OUT = -2.94 * (IN - 2.2)

That means R3 and R4 need to be adjusted to produce 2.2 V instead of 2.5 V, and R2/R1 should be about 2.94. Rounding to standard 1% values we get:

R2 = 294 kΩ 1%
R3 = 12.7 kΩ 1%
R4 = 10 kΩ 1%