Suppose we have a PWM signal which controls the speed of a motor and a digital pin which specifies which direction a motor is travelling in, how can we convert these signals into 1 +/- 10V signal where <0 is reverse and >0 is forward travel.

I appreciate there will be several ways of implementing this, but it's be good to consider different methods

  • \$\begingroup\$ When you say +/- 10V signal, does that "signal" power the motor, or is it a low-current signal which is passed to a high impedance input which then does something else (i.e. a driver)? Also, what is the voltage of the PWM signal? And what is the PWM frequency? \$\endgroup\$
    – stefandz
    May 25, 2016 at 14:24
  • \$\begingroup\$ Inverter + low pass filter... \$\endgroup\$
    – Eugene Sh.
    May 25, 2016 at 14:36
  • \$\begingroup\$ I already gave you a link in your previous question regarding VFD and MCU. \$\endgroup\$ May 25, 2016 at 16:15
  • 2
    \$\begingroup\$ Why are you asking again? You didn't accept either answer from your previous question. \$\endgroup\$
    – Transistor
    May 25, 2016 at 17:51

4 Answers 4


Something like this should work well. Parts are just for example, optimization will take more work (and information).


simulate this circuit – Schematic created using CircuitLab


I've been asked for analysis of the amplifier (gain = +2 for switch closed, -2 for switch open).

First observe that the op-amp inputs are always at Vin/2 at balance due to R3/R5.

(Note also that they are always positive since Vin varies from 0V to 5V, so M1 always sees positive voltage on the drain- 0 to 2.5V for 0 to 5V in)

Switch M1 open (off), we have current (Vin - Vin/2)/R2 flowing through R2, so - (Vout - Vin/2)/R1 must be flowing through R1, using KCL.

Solve for Vout/Vin = 1/2 - R1/(2*R2) = -2.00 for R1 = 5*R2

With the switch closed (assume M1 = 0\$\Omega\$) we have an added term and using KCL again, the result is:

Vin/(2*R2) - Vin/(2*R4) + (Vout -Vin/2)/R1 =0

Solve for Vout/Vin = 1/2 +R1/(2*R4) - R1/(2*R2) = +2.00 for R1 = 5*R2 R4 = (25/40) * R2.

  • \$\begingroup\$ Nice, I was thinking of a switched gain (+1/-1) circuit with an analog switch rather than the FET. (like a lockin type thing.) I've got several of those scribbled in a notebook.. One could invert the PWM and then use a MUX selected by the drive "bit" to change the sign. \$\endgroup\$ May 25, 2016 at 15:40
  • \$\begingroup\$ @GeorgeHerold Thanks This gives +/-2 gain with a single SPST switch. If you're feeling flush it's easier and maybe more accurate to use a DPDT analog switch and an instrumentation amp but that costs 100x as much. \$\endgroup\$ May 25, 2016 at 15:42
  • \$\begingroup\$ Nice response @SpehroPefhany - I had something more like George had in mind. Forgive my ignorance, but I don't think I've seen that topology for an opamp before (excluding the FET switch - the basic amplifier setup). Would you mind doing a bit of the circuit analysis on it? Or is that a relatively standard setup that I could look up somewhere else? When I try to analyse I get incorrect results. \$\endgroup\$
    – stefandz
    May 25, 2016 at 15:59
  • 1
    \$\begingroup\$ @stefandz, w/o the FET, It's a differential opamp. (Which is why an instrument amp could also be used... for even more money you can buy a single IC, AD630.) \$\endgroup\$ May 25, 2016 at 16:42
  • \$\begingroup\$ @GeorgeHerold you're quite right - I got my head in a mess by trying to analyse it as an inverting opamp with an offset on the non-inverting input. Lazy analysis = wrong answers! Now that I see it I am embarrassed I didn't sooner. But thanks for putting the name to the devil! \$\endgroup\$
    – stefandz
    May 25, 2016 at 16:44

I can see an analog scheme there, which is cool, but one thing is bothering me. If you have direction signal in the system, are you sure, PWM is used to actually modulate speed/position/voltage, or it is used to generate frequency? I have seen several systems where people controlled stepper motors with direction signal and PWM signal, which was used for step signal. This is WRONG! Yet people do it.

In fact, the question hints that in certain system a pulse/direction drive was replaced with analog drive, and some kind of interface is required to stitch things back together.

If this is the case, no analog circuit will help. Because the information is not compatible- pulses are position, while analog command is current (well, normally, not always). And if this is the case, you need a digital device, FPGA or Microcontroller, that will capture the pulses, calculate current command value accordingly. In fact, it's one of the features of modern servo drives. It will probably have to close the loop- otherwise errors will accumulate quickly. So bottom line, if this is the case, rethink the system.

  • \$\begingroup\$ Surely using PWM to drive a step signal on a stepper would quickly be discarded as a solution - because it wouldn't change speed (unless you mean by completely skipping steps at low - and possibly very high - duty cycles)? \$\endgroup\$
    – stefandz
    May 25, 2016 at 20:01
  • \$\begingroup\$ No, it depends. For non-real time systems it's the only way to maintain speed, so for low speeds it's fine, as long as position control is not required. For higher speeds they may even build simple profile, again, no position control. And why would i even defend this thing? No idea... \$\endgroup\$
    – user76844
    May 25, 2016 at 20:15
  • \$\begingroup\$ I am totally confused - surely if you're using PWM to drive a step signal, you're only changing the pulse width, not the frequency, and hence can't change speed? Not sure this is worth discussing here (as you point out) but intrigued as to what detail I am missing! \$\endgroup\$
    – stefandz
    May 25, 2016 at 20:20
  • \$\begingroup\$ No, constant 50% duty cycle, but changing frequency. The thing is that PWM peripheral is independent of program, so they just need to change the value in frequency register from time to time. \$\endgroup\$
    – user76844
    May 25, 2016 at 20:22
  • \$\begingroup\$ Gotcha. So PWM peripheral, but actually used as a PFM controller (but speed only, not position). Phew, thought I had lost my marbles there! \$\endgroup\$
    – stefandz
    May 25, 2016 at 20:24

Here is a single-IC solution that gets you pretty close:

enter image description here


  • V1 is your PWM-generating circuit. This should be low-impedance. Most microcontroller outputs would suffice, depending on the input impedance of your low-pass filter.
  • R1 and C1 form the low-pass filter. You can make this as elaborate or as simple as you like. I chose simple.
  • R4 is used to adjust the offset. If your input PWM is 0V to +3.3V and your desired output range is -10V to +10V, then 6.3k gets you pretty close.
  • R6 and R5 are used to scale your voltage output after adjusting R4.

Adjusting the Circuit

If you need to adjust the circuit manually, I suggest that you short R5 to make a voltage-follower and adjust R4 until a 50% duty cycle gives an output voltage of 0V.

We can also use some maths to find our ciruit relationships. In this circuit, adjusting R4 is really adjusting the voltage divider of R1 and R4 so that

$$(\frac{V1_{max}}{2} - V_{neg})\frac{R_4}{R_1 + R_4} - V_{neg}= 0$$

Assuming V1 = 3.3V and Vneg = 10V:

$$(\frac{3.3V}{2} - 10V)\frac{R_4}{R_1 + R_4} - 10V = 0$$ $$(11.5V)\frac{R_4}{R_1 + R_4} - 10V = 0$$ $$\frac{R_4}{R_1 + R_4} = 0.8696$$ $$6.67R_1 = R_4$$

Once you get your offset adjusted, start adjusting R5 up until 100% duty cycle gets you 10V and 0% duty cycle gets -10V. Again, you should be able to calculate this step:

$$V_{out,max} = GV_{in,max} $$

Where 'G' is the opamp circuit gain and Vin,max is the maximum voltage on V+ (or the PWM at 100% duty cycle). In an inverting amplifier,

$$G = 1 + \frac{R5}{R6}$$

From this point, you should be able to use substitution and arrive at suitable values for R5 and R6.

  • \$\begingroup\$ Where is the direction input for this circuit? \$\endgroup\$
    – stefandz
    May 25, 2016 at 19:59
  • 2
    \$\begingroup\$ Embarrassingly, I misread the question and missed the direction input. The circuit is designed to operation on PWM alone where 0% duty cycle scales to -10V and 100% duty cycle scales to +10V. I'll leave it up here for posterity in case anyone stumbles on this question with that particular need, but the answer provided by spehro is more suited to the question and I upvoted his answer. \$\endgroup\$ May 25, 2016 at 20:19

As some of the comments show, we need a little more information. I will assume here that you are using micro-controllers and that both your PWM and Digital output pins are operating at 0-3.3V. Here is the digital logic that you are first trying to implement:

PWM   DIR |  Output
  1         0  |     1    (Forward Direction)
  0         0  |     0    (Forward)
  1         1  |     0    (Reverse)
  0         1  |     1    (Reverse)

This represents XOR logic. So the easiest way to implement this would be to use a simple XOR IC, and a level shifter. Not really much of a need for a low pass filter if you are driving a motor as the coils in the motor will act as a low pass filter


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.