Electronics > Projects, Designs, and Technical Stuff
Comparator output needs a kick start and then quickly shortens to zero.
PansLab:
Folks,
I need some help please. I'm trying to use an arduino to measure a frequency. I'm using an op am module and sending that to an LM324 comparator. I have two behaviors I don't understand.
1) with a varying signal, that does go above and below the reference voltage, on the non-inverting input the output stays low, until I short the inverting pin to ground. Then the comparator starts working as expected, sort of. Read on.
2) The comparator works as expected for only a few seconds. The input signal does not change but the time interval of the comparator output shortens until it reaches zero and then stays that way.
The schematic is attached. I've also taken screen shots of the mysterious shortening output length. Their chronology is indicated by the title.
This is single supply, all on breadboards with Dupont wires.
StillTrying:
The -IN of the LM324 needs a bias voltage similar to what's on the +IN, probably with a few 10s of mV difference between the -IN and +IN.
WattsThat:
StillTrying told you how to fix it but if you're trying to understand the behavior...
Practically speaking, no current flows into or out of an op amps input pins. You can think of an input as a very, very high resistance. So, there is no load on the output side of C1 and the voltage there starts at zero and as the output of ‘386 goes up, the right side of that cap just keeps going up with nothing to pull the voltage down. Putting a bias voltage on the input pin provides the necessary load so the output of the cap will follow the input voltage.
Dave has an excellent tutorial on op amps on YouTube:
Ian.M:
WattsThat's explanation isn't entirely accurate - its nothing to do with the LM386's DC output level which is blocked by two capacitors. Theoretically no current flows into or out of an ideal OPAMP's input pins, but in practice BJT OPAMPs like the LM324 need a very small but significant input bias current. JFET or MOSFET input OPAMPs do have very much higher impedance inputs, closer to the ideal, but even so they still need a DC path from each input pin to signal ground, so their absolutely minuscule bias current doesn't cause an offset voltage to slowly build up eventually railing their output. OTOH, I also recommend Dave's OPAMP video.
The LM324 OPAMP* has PNP Darlington inputs to a long tailed pair. Both inputs *MUST* have a DC path to ground and need about 45nA 45uA bias current. That means that across a 10K input resistor the input bias current will make the input pin end about 0.45mV 0.45V more positive. Therefore if you don't want to run into significant trouble with input offset voltages you've got to keep the DC resistance as seen by the +in and -in pins well matched if you are using high value resistors round the OPAMP
Momentarily grounding the comparator OPAMP's -in made it work until its 45nA 45uA bias current had charged up the input capacitor enough for the troughs of the signal on the -in pin to no longer go below the reference voltage on the +in pin.
I suggest duplicating the R3, R1 potential divider to bias its -in with matched input resistance. You may also need an 820K feedback resistor from Out to +in to give it just over 1% hysteresis to stop it 'chattering' on noise if there's no input.
Also its crazy using a LM386 audio output amplifier as a preamp before your OPAMP comparator. You've got three spare OPAMPs in the LM324 - use two of them to give you x200 gain. Configure them each as inverting amplifiers, and split the gain fairly evenly between them. To make them easy to bias use the remaining OPAMP as a rail splitter. As the LM324 wont drive closer than 1.5V to its Vcc rail you don't want to split the 5V supply symmetrically, as you want an equal swing above and below your bias rail. A potential divider with 18K lower resistor and 33K upper resistor for about 1.75V, decoupled with 100nF to ground, with the OPAMP configured as a unit gain buffer will be ideal. Use the bias rail as signal ground for the amplifiers.
* Its output will transition a lot slower than a real comparator - it can only slew at about 0.5 V/us, and its push-pull output high level will only be about 3.5V with 5V Vcc so it will crap out on you if you try to use it as a comparator for signals much over 70KHz, as the output just doesn't have enough time to go high. Compare that with a real comparator like a LM393, which can slew between valid TTL levels in only 300ns, so should be good for over 380KHz on small signals and well over 1MHz with enough input drive.
Edit: Thanks for the correction to my three orders of magnitude screwup (see strikeout and italics in my second and third paragraphs above) - I need to clean my glasses and possibly drink less Pimms! :palm:
PansLab:
StillTrying, thank you. Your clue about biasing both inputs was the key. I took and replicated the resistors on both inputs and it started working reliably.
Ian, thank you for clarifying. Plus, you're correct that it is crazy to use the 386 as a pre-amp. but here is my cop out. It's been *decades* since I've messed with discreet circuits like this. I'm so out of practice that I'm struggling to get an op amp to work as a comparator and interface it to a pre-amp output. I knew I'd be in way over my head trying to get a pre-amp working, and that's if I have all the right parts. I have a 5 pack of those audio amp circuits and I know they work. so I did the lazy thing and slapped one of those in.
Thank you everyone.
Navigation
[0] Message Index
[#] Next page
Go to full version