I want to control voltage on the motor (R1) by microcontroller output (Vin). The problem is that maximum output of the microcontroller is only 2V, while I want voltages on motor up to 12 V. So I decided to make a voltage divider (1:10) to scale down the voltage on the motor before putting it on the opamp.

enter image description here

However, the results are quite unsatisfactory. I have measured voltage Vin and voltage on R4 and they are quite off. Here is the list (V4a for no motor and V4b for motor)

Vin   V4a   V4b
0.00  0.01  0.04
0.10  0.13  0.07
0.20  0.24  0.11
0.30  0.40  0.15
0.40  0.51  0.18
0.50  0.61  0.58
0.61  0.70  0.66
0.71  0.78  0.77
0.81  0.86  0.86
0.91  0.92  0.95
1.01  0.99  1.04
1.11  1.05  1.13
1.21  1.11  1.22

Is opamp faulty or is there something wrong with the circuit? (I've tested two opamps with the similarly bad result.)

VDD = 16V.

EDIT: following the suggestions from others I have checked the voltage on the load. Below is the oscilloscope picture for a load of 1 kOhm. There is huge variation of voltages between 9V and 15V with frequency of 100kHz. Interestingly, using smaller resistor (40 Ohm bulb) the variation gets smaller, between 11V and 13V.

enter image description here

  • \$\begingroup\$ Is there a reason why you prefer not to use PWM to drive the motor? Operating it in this manner is energy-inefficient, wasting a lot of energy as heat which must be dissipated from the MOSFET. \$\endgroup\$
    – nanofarad
    Dec 13, 2020 at 22:38
  • 1
    \$\begingroup\$ @nanofarad This is a model train motor (no possibility for PWM) and the setup is designed for testing. \$\endgroup\$
    – Pygmalion
    Dec 13, 2020 at 22:44
  • \$\begingroup\$ Why no possibility for PWM? Lots of model trains use it. \$\endgroup\$
    – Finbarr
    Dec 13, 2020 at 23:00
  • \$\begingroup\$ "the setup is designed for testing." - exactly what 'testing' are you intending to do? \$\endgroup\$ Dec 13, 2020 at 23:23
  • 1
    \$\begingroup\$ Have you checked that this circuit isn't oscillating at some high frequency? I see a few red flags waving in this circuit that could make it unstable. \$\endgroup\$
    – glen_geek
    Dec 13, 2020 at 23:41

2 Answers 2


I've had trouble with oscillation around the loop when using a p-fet like that. The gate is going up whilst the feedback is going down and vice-a-versa. Could you perhaps see if there is a small alternating voltage across the load perhaps with an oscilloscope. Measuring the voltages with your meter set to dc will not tell you if there is ac there.

I solved my problem by swapping the p-fet for n-fet (source to motor) in source follower mode and taking the feedback back to the op-amp's inverting input with the control voltage applied to the non-inverting input.

Motor Driver

Depending on your motor current you will need a heat sink on the transistor.

  • \$\begingroup\$ There is huge variation of voltages between 9V and 15V with frequency of 100kHz when using 1kOhm resistor. Interestingly, using smaller resistor (40 Ohm bulb) the variation gets smaller, between 11V and 13V. I put the picture in the question. Is this consistent with your experience? \$\endgroup\$
    – Pygmalion
    Dec 14, 2020 at 12:39
  • \$\begingroup\$ In the sense that I was experiencing oscillation, yes. But when I attempted to drive a p-fet like that with an additional integrator in the loop I got smaller amplitude sinusoidal oscillation. You could try an n-fet in source follower mode and if there isn't enough head room for the gate voltage then swap the n-fet out for a Darlington driver with its smaller base-emitter voltage eg.TIP 120/121/122 \$\endgroup\$
    – user173271
    Dec 14, 2020 at 13:08
  • \$\begingroup\$ Thanks for the answer. Since I am a total amateur, I don't understand any of that. May I therefore just ask two more questions? 1. Is there any chance that an appropriate circuit could be already available on the internet, or is this a specific problem that amateurs should stay away of? 2. Andy suggested "feedback capacitor across the op-amp", but he wouldn't tell what exactly this is - is this by any chance capacitor between (-) and (+) of opamp? \$\endgroup\$
    – Pygmalion
    Dec 14, 2020 at 13:47
  • \$\begingroup\$ @Pygmalion See edit \$\endgroup\$
    – user173271
    Dec 14, 2020 at 17:55
  • \$\begingroup\$ Thanks! I have finally got the components from China and tested the circuit. It works like a charm (at least up to 12V where I need it). \$\endgroup\$
    – Pygmalion
    Mar 15, 2021 at 17:11

The problem will be that the LM358 won't be able to adequately turn off the MOSFET because its output voltage won't rise to the positive rail (Vdd) sufficiently. To turn off the MOSFET, you need to raise the gate voltage to the source voltage and the op-amp won't be able to do that - the highest voltage it can produce is \$V_{DD}\$ minus 2 volts and that will keep the MOSFET activated on.

It's quite possible that when you do choose an op-amp that is rail-to-rail on the output, the circuit could become unstable; try adding a 10 nF to 100 nF feedback capacitor across the op-amp. This is a common experience when adding a MOSFET within the negative feedback loop of an op-amp; the added loop-gain converts the otherwise stable phase margin of the op-amp into severe instability that is load dependent and fairly unpredictable.

In addition to the above, the MOSFET is likely to be destroyed by your circuit. If you look at the data sheet, the maximum \$V_{GS}\$ is +/- 8 volts and, if the op-amp output falls to zero (a very likely event), the gate-source region will become overstressed beyond its absolute maximum rating: -

enter image description here

In summary: -

  • You need a rail-to-rail output op-amp
  • You need a P channel MOSFET that is rated to withstand the 12 volt power rail
  • You need to slug the op-amp with local negative feedback to prevent it oscillating.
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Voltage Spike
    Dec 15, 2020 at 16:18
  • \$\begingroup\$ I just couldn't make this circuit working. I used IRF4905, LMC6482 and 100nF. Yes in general larger voltage on the input means larger voltage on load (220 Ohm), but precision is horrible (30% error). I guess it is impossible to control voltage by microprocessor in such a simple way. \$\endgroup\$
    – Pygmalion
    Mar 15, 2021 at 10:38
  • \$\begingroup\$ It's not impossible; you just haven't found a precision way yet. Maybe ask a new question and please do show your new circuit. Are we done with this Q and A now? \$\endgroup\$
    – Andy aka
    Mar 15, 2021 at 10:41
  • \$\begingroup\$ Yes, we are done. I think my design is too flawed and I will pursue other avenues. \$\endgroup\$
    – Pygmalion
    Mar 15, 2021 at 18:59
  • \$\begingroup\$ @Pygmalion you should still take the time to select an answer for acceptance and please do raise a new question to get help. \$\endgroup\$
    – Andy aka
    Mar 15, 2021 at 19:07

Your Answer

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

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