How to get the full Vcc output from comparator

comparatoropen-collectorpullup

I am working on a circuit using a comparator for a school project, but in testing it is not acting as expected. Specifically, the output is not going all the way to the higher rail voltage attached to the comparator. I am using the LM311, an open collector comparator. This can be changed if that would fix my problem. I have tried varying values for a pull up resistor but I still cannot get all the way to the Vcc value I want (this project is my first exposure to pull up resistors and I am not sure how to choose values.) This circuit is designed to turn on the mosfet (or BJT) and charge a capacitor so that the mosfet/BJT stays on for a period of time after the comparator output goes back to low.

Note: This is not the exact circuit we will be using, we will likely be switching to a BJT instead of the mosfet and resistor values will be adjusted around the capacitor. The solenoid valve values are also made up. However, I do not think this changes the general question around the comparator.enter image description here

Best Answer

Don't connect the solenoid to ground, connect it to Vcc and use the MOSFET with its source tied to ground - drain to the other end of the solenoid. Put the protection diode across the solenoid, cathode to Vcc.

Now, if you do this you'll most likely find that it behaves much more as you would expect it to because the MOSFET will turn on properly. You need to maximize gate-source voltage from the Vcc rail to turn it on properly. What you had before was called a source follower and with your solenoid voltage required and your limited 9V supply it would never turn on effectively. Here's a snapshot of the changes: -

schematic

simulate this circuit – Schematic created using CircuitLab