LM393 comparator (and the LM358 Op Amp)
Measuring stuff in the real world can be messy - for instance when the ambient light drops around dusk it can oscillate about a value which you may be trying to measure (e.g. to turn on an artificial light). I have dealt with this same scenario a couple of times.One project I have measures light exactly in this way, but I have an attiny13 microcontroller providing software hysteresis by switching on if the sensor value is above "350", but not switching off until the value is below "250". These are nominal values.
Noisy signal tamed by hysteresis (green lines) |
Configured as a Schmitt trigger the LM393 hysteresis is provided according to the following diagram and formulae.
I've seen a lot of formulae and online calculators for hysteresis using op amps and comparators, but the equations shown above for Vth and Vtl actually work when measuring all of the parameters (including crucially the Vol and Voh numbers), as can be seen in the screenshot below from a spreadsheet.
In the circuit above 9V supplies three key components. Firstly 9V is fed to the LM317 from a previous blog which then provides variable signal voltage to Vin.
Secondly the op amp/comparator needs to be powered itself and accepts 2V to 36V.
Finally 9V is fed to a voltage divider that supplies the reference voltage (in this case 5V).
When the LM317 signal is above the upper threshold (~5.5V) then the output of the LM393 is high (2.66V). When the signal drops below the lower threshold (~5.2V), the output drops to low (0.03V). 2.66V is enough to weakly drive a lot of LEDs, but most likely it is better to use a transistor switch as shown in the video below.
So we get lovely hysteresis after all of that, importantly based on some measured values. It's a bit of a dark art and I've certainly read much conflicting advice on the subject - but if you're keen there is some quality information available. Good luck.
No comments:
Post a Comment