First Question for me. I have benefited from other answers here but have not fully resolved my problem. Here's my problem...

The LM311 Comparator output does not drive the N channel MOSFET fully on.

The LM311 has a 110mv ref voltage on the inverting input.
The non-inverting input is driven by an opto-isolator output. The Opto-isolator is driven by 1 of 4, AC 60Hz voltages. <1VAC, 9VAC, 55VAC and 115VAC.

The goal of the design is to have the FET fully turn on the 12VDC fan when there is appreciable AC voltage. So fan fully On for the 9, 55, and 115VAC voltages. It seems it should work because I measure voltages on the non inverting input of 1.6, 2.2 and 3VDC respectively for the 3 appreciable AC voltages. And my ref voltage on the inverting input is 110mv.

So it "almost" works because the fan is off at the <1VAC, but not fully "On" for the other AC voltages. I believe this is because Vgs is 167mv, 6.1V, 7.7V and 9.9 Volts for the 4 AC voltages listed above. And the fan is only getting 7, 8 and 10VDC instead of a desired 12VDC. Would really like to be able to fully turn this FET all the way on. So Close!

Any input or guidance is appreciated.

Ps-Things I think I've done right? Flyback diode across the fan. Putting N channel FET to switch to ground on low side of fan. LM311 has Open collector output using correctly?

PSS-I realize that the pinouts for the LM311 are not right in my schematic. I have them right in my protoboard circuit. Its a single device. Pin 2 is noninveritng and pin 3 in Inverting

Thanks Again.

enter image description here

The suggested duplicate question and answer doesn't help for the following reasons: Both diagram and schematic are"No file found" making it pretty difficult to follow the answers. I am not using any positive feedback in my circuit as I don't think I need one. I have a simple pull up resistor to my 12V supply, not a voltage divider to the power supply as is mentioned in the answer. Thanks.

Just for the record I wanted to post a more accurate schematic and thanks for the response on using a Cap to hold up the opto isolator output. I actually have a full wave input to the phototransistor but I'm sure the cap will help anyway. To answer the last question, the Pin 7 comparator output has a pullup resistor to 12v. The issue is still that Vgs is only 10v when the comparator has 3v on pin 2 and 110mv on pin 3. I would have expected the LM311 output to go much closer to 12v (Vcc) with those inputs. The intent is for the FET to go completely on for pin 2 voltage > pin 3. enter image description here

  • 8
    \$\begingroup\$ I am voting to close as a duplicate. Basically, the LM311 output is open-collector, so it needs a pullup to go high. It is not expected to go high without a pullup. \$\endgroup\$ – mkeith Nov 11 '17 at 6:18
  • \$\begingroup\$ This question actually has a schematic, the other question is terrible \$\endgroup\$ – Voltage Spike Nov 11 '17 at 18:00
  • \$\begingroup\$ What are pins 1 and 7 of the LM311 connected to? \$\endgroup\$ – Bruce Abbott Nov 12 '17 at 2:14
  • \$\begingroup\$ I don't think it is a bad question. But the answer is simple. Just add a pullup. \$\endgroup\$ – mkeith Nov 13 '17 at 15:19
  • 2
    \$\begingroup\$ @laptop2d I went ahead and merged the two questions. As you said, this one was much better. \$\endgroup\$ – W5VO Nov 15 '17 at 6:08

the maximum voltage output is around 3.3V and not at 5V. How would you explain that ?

The LM311 has an open collector output so the it does not "drive" the output high. For your circuit, the output high is given by:

$$V_{OH} = 5V(\dfrac{2.7k + 1k||2.7k}{2.97k + 2.7k + 1k||2.7k} + \dfrac{1k}{1k + 2.7k}\dfrac{2.97k}{2.97k + 2.7k + 1k||2.7k}) = 3.31V$$

how would you explain that the output is not exactly at 0V when the input is high?

enter image description here


Normally, when using a comparator, the output level when the comparator switches off is determined only by the power supply level. However, your circuit also has positive feedback via R52 and this will limit the maximum voltage. If you increased R52, R53 and the 1k by 10 times you'd see a bigger output voltage. Remember this is a comparator that relies on an output resistor pulling the output up to positive supply rail. If you used an op-amp (push-puul output) this wouldn't happen.


With the output high, you have a voltage divider as pull-up: 2.97K to +5, and 2.7K to the junction of R53 and the 1K - this will prevent the output from rising to +5 volts.

On the low side, the specs give a saturation voltage of 0.23 to 0.4 volts with 8 mA load. Your pull-up circuit will draw about 11 mA, so the output low voltage may be a bit more than the spec'd 0.4 V.


The basic problem with your circuit is that the mains voltage is AC, so the LED in the opto-isolator only lights up during positive half cycles and the comparator gets pulses at 60Hz. What looks like 7V, 8V or 10VDC on your meter is actually a square wave which is on for less than 50% of each AC mains cycle.

The graph below is an LTspice simulation of your opto-isolator's response to the AC mains input. The output voltage (green) is 1.6V average so your meter will show 1.6VDC, but the comparator will convert it to a 60Hz square wave with an on/off ratio of less than 50%.

enter image description here

To get a continuous DC output you need some way to fill in the gaps between each half cycle. The simplest solution is to add a capacitor across R1 which charges up during the pulses and discharges more slowly between them. If the capacitor is large enough then this should produce a relatively smooth DC voltage which is equal to or higher than the original the meter reading, but with some 'ripple' caused by the capacitor discharging between half cycles.

enter image description here

If the capacitor is too small then instantaneous voltage will drop below the comparator threshold between half cycles, but if it is too large the response may be too slow. As a starting point you can apply the RC time constant formula T = R x C (where T is the time taken for the voltage to drop to 37%, R is R1 in your circuit, and C is the required capacitance). Make the time constant much larger than 16.7ms (60Hz cycle time).

Response to your edit 2017-11-15

With R2 = 10k and R3 = 100k you should get ~1.1V on pin 3 of the LM311, not 0.11V. If you really are getting 0.11V then these values cannot be correct. A higher voltage may be preferable if you don't want the circuit to turn on much below 9VAC.

Looking closer at the SHF620A datasheet it appears to have two LEDs back-to-back, which produces output on both positive and negative half cycles. However this 'rectified' output will still follow the AC, dropping to zero at each crossover (the output waveform will just have two 'humps' per cycle instead of one). This will be easier to smooth due to the shorter time (~8ms) between peaks. With R5 = 10k a 2.5uF capacitor in parallel would produce about the same ripple as in my simulation, while 4.7uF would make it even smoother but with similar response time.

The IRLR024N is virtually fully turned on with 10V Gate drive (datasheet shows <0.1V drop at 1.5A). The way your comparator is configured the output should go to 12V, but if the input is dropping below the threshold for 17% of the AC cycle then your meter would only read 10V - even though the FET is fully turned on 83% of the time.

Diagnosing pulsing waveforms with a multimeter is tricky because it only shows the average voltage. To see what's really happening you need an oscilloscope. Even a cheap low bandwidth scope such as the JYE Tech DSO138 is fine for mains frequencies.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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