Below is the complete circuit for a PWM control output: enter image description here (please left-click to enlarge)

"Out" in the schematics will be directly connected to PWM input of a 3-wire or 4-wire DC fan.

Since I don't know the input impedance of the fan, I decided to use a PNP transistor at the output of the LM393 comparator.

Here is the output waveform of the comparator:

enter image description here

And here is the final output after the PNP (there is like 0.9V offset):

enter image description here (please left-click to enlarge)

As you see using a PNP is introducing offset to the output signal. Is there a technique or another coupling way to fix this issue without using another opAmp?

  • \$\begingroup\$ you want to recover the spike? If so, I would recommend decoupling cap with a small value. \$\endgroup\$
    – MathieuL
    Jun 20, 2016 at 14:41
  • \$\begingroup\$ The pwm signal is around 25kHz, the duty cycle can be from %0 to %100. I want to reduce offset voltage of the pulse to around zero. But adding a cap might deform the pulse waveforms? Comparator output is fine but I dont wanna load it. And if I use this transistor config Im having almost 1V offset \$\endgroup\$
    – user16307
    Jun 20, 2016 at 14:46

2 Answers 2


You're using the PNP as an emitter follower so no wonder it adds a voltage to the bottom side of the waveform.

What you need to do is use an NPN or an NMOS transistor. Then the polarity of the signal from opamp U1 (used as a comparator) is "upside down" but that is easy to fix: just swap the + and - inputs of the opamp.

In the case that you use an NPN, do not forget to add a base resistor between the base of the NPN and the output of the opamp. A 1 kohm resistor will do the job.

Get more info here about 3 and 4 wire fans.

  • \$\begingroup\$ This circuit can control pwm output from %0 to %100 in simulation without changing the pulse freq. At least in simulation. My prob was the output. I didnt want to load the comparator with the the Fan's pwm input. I also wanted LED to indicate the speed. I will try with NPN \$\endgroup\$
    – user16307
    Jun 20, 2016 at 14:52
  • \$\begingroup\$ Btw 3 and 4 wire DC fans do not need flyback diodes right? I thought they re built in \$\endgroup\$
    – user16307
    Jun 20, 2016 at 14:54
  • \$\begingroup\$ No they don't, they're not inductive loads like motors because there are some electronics inside. Get a fan you no longer need, open it and see how they work :-) Usually there's a chip that controls 3 or 4 coils. The chip has build-in flyback diodes. \$\endgroup\$ Jun 20, 2016 at 14:56
  • \$\begingroup\$ thanks for the suggestions i tried and it worked in simulation. Btw in my case I don't need to swap the signal inputs at opAmp, and i dont need to invert the output when using NPN. just the poti rotation will act reverse \$\endgroup\$
    – user16307
    Jun 20, 2016 at 17:02
  • \$\begingroup\$ Indeed, that will also work of course :-) \$\endgroup\$ Jun 20, 2016 at 19:24

The PNP will always have a diode drop between the base and emitter, hence your offset. You could replace Q1 with an N-channel MOSFET; pick one with low on resistance and a low gate threshold voltage. This will invert your logic so you must swap comparator pins or change your firmware. You may have to lower R5 if the input capacitance of the MOSFET is high.

  • \$\begingroup\$ Uhm, an NE555 works without firmware :-) This is real electronics :-) \$\endgroup\$ Jun 20, 2016 at 14:58
  • \$\begingroup\$ @FakeMoustache - oops. I am old enough to know better. Your answer is sufficient anyway - I can't type that fast. \$\endgroup\$ Jun 20, 2016 at 15:49

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.