what is happening in this lm393?? - Page 1
Forum section: electronics / beginners

author: superwester
author_rank: Contributor
timestamp: January 07, 2018, 12:50:13 am
content: so im working in this circuit :http://tinyurl.com/ybk6vdk2it detects any change in the potentiometer and sends a high signal from the lm393 to a micro.the thing is, it works perfectly... but only for the rise in voltage (capacitor conected to the non-inverting pin, as it delays the rise so that the inverting pin is higher for a little while).aso soon as i try to do the same but for the falling voltage (cap on the inverting pin, thus, delaying the drop in voltage and making that pin higher than the non inverting for a while) the out put goes crazy, it starts oscillating(at simple sight) or just stays on. i measure the voltage between the two input pins and its unstable(varies between 0.5v and 1.5v).i really dont understand whats happeningin the schematic attached, R 4-5-6-7 are voltage dividers so the inputs will be within the specs.i made sure that the other comparator of the lm393 isnt an issue making it go low all the time.I hope i explained the issue good enough if not, let me know to further explanations and to get better at iti'll be glad if you offer your help

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 07, 2018, 01:24:42 am
content: This is the incorrect way to do it, and you've discovered why.There are two factors which combine:1. The comparator is normally biased very close to linear. This should fill you with dread already.2. The negative input has a high driven impedance (just a resistor divider), so at high frequencies, the capacitance between nearby pins dominates.This is about 1pF (or maybe it's more, not sure) between OUT and -IN.It only takes a few mV to cross the threshold and make OUT swing the other way. But it takes some hundreds of nanoseconds for that change to propagate through the comparator and trigger the output to go the other way.Basically, whereas a [voltage mode, dominant pole compensated] op-amp is stable with feedback from OUT to -IN, a comparator is intentionally designed to be unstable, so that it can be as fast as possible given the internal design.There isn't much difference between the LM358 and LM393, beyond the output stage (open collector vs. push-pull). But the one big difference is the compensation. LM358 is quite slow, so that its output moves gradually enough to settle to a stable state. LM393 is too fast, and constantly overshoots the equilibrium point -- it oscillates.So, to fix #2, you can move the capacitor over, Put it on -IN instead of +IN. That shunts the OUT to -IN capacitance, so the -IN pin doesn't move around (much if at all) when OUT transitions. There is a slight capacitance from OUT to +IN which may be valuable, and can be enhanced by layout (route traces together?) or by adding a capacitor.To fix #1, you need to add something that will increase the threshold whenever it's crossed. Positive feedback. Capacitance from OUT to +IN has this effect, but only temporarily -- it increases the threshold, but the increase decays over time. To maintain it, you need a resistor as well.This makes things tricky, because now you're feeding some bias into the pot, which introduces an error depending on whether you last moved it up or down. Icky.A new configuration is needed. Use a high-pass filter (differentiator) instead.This way you have a voltage divider, biasing each input at +V/2, say. (Use one divider, then a series resistor to each input. If you use two separate dividers, they need to be perfectly matched -- that'll never happen, not without better than 0.1% resistors!) Connect the pot wiper to an input via series capacitor, and connect a resistor from OUT to +IN to get the hysteresis.Now the inputs will normally sit slightly apart: +IN biased up or down by some mV due to the feedback resistor, -IN biased to whatever the divider is at (minus input bias current, of course). When sufficient input change (dV/dt) is applied, that input crosses the threshold, and the comparator output changes state.Now it's stable and consistent, but it only works one way at a time. To capture both directions consistently, duplicate this circuit using the other comparator, swapping the input the series capacitor connects to (one is connected via +IN, the other -IN). That's with two separate capacitors.Two problems remain:1. What if the pot is turned very, very slowly?2. What if the pot goes noisy?In 1, the comparator never changes state and triggers the MCU. In 2, the MCU is triggered incessantly, even though the average input voltage isn't really changing. Or it is, in fact, changing, horribly fast, and you can't really do anything about it because it's just a shitty pot that's gone scratchy.What to do now?I would get rid of the comparator entirely.Instead, set a timer so the MCU polls the pot infrequently. When the sample is different by a suitable margin, set the timer period to a shorter duration -- so it samples more frequently, capturing more slope (hopefully) -- if a well defined slope is even necessary -- and less frequently when the slope slows down.As a bonus, power the pot from an IO pin (or external switch transistor), so its bias current is turned off except during an acquisition.If the pot is just a user input, a polling rate of 100Hz is more than enough. Any MCU ought to be able to complete that task in a few dozen microseconds, giving a duty cycle around 1% -- even if it's a stupendously hungry core gobbling 10mA in run-mode, that's an average 0.1mA (assuming the sleep mode is nothing..), considerably better than the LM393 and free from the quirks identified above.And, probably, if it's a modern core consuming that much power, it's probably not that it's inefficient, but that it's that much more powerful. So that it would complete the operation in less than a microsecond, maybe, giving an even better duty cycle.It's not clear what your underlying motivation is with this circuit -- if it's to save current consumption over a sampled method, it's not doing a very good job because the MCU can sip much less than a mA in such service (probably 10s of uA with a low power chip and judicious use of standby modes), whereas the LM393 already burns almost a mA, plus you have all those pull-up and divider resistors drawing bias current for no other benefit at all. In other words -- the old saw of "spending pounds to save pennies".There are some ideas about irregular and threshold-triggered sampling, but it's not something you can do discrete -- it's all about conserving power with on-chip resources, that can be made small enough to be worth the current consumption. Basically -- it's really hard to do low-current analog circuitry in the first place, and it's even harder to do with discretes (transistors or chips).Tim

author: superwester
author_rank: Contributor
timestamp: January 07, 2018, 04:22:14 am
content: i see way more clearly my faults)) thank you for the great answer.for what i understood, my knowledge as hobbyist electronics has reached it's limits and i need to learn concepts like hysteresis.the idea is that the potentiometer will set the temperature via MCU and after some time the MCU will go to sleep mode and then will woke to any movement in the potentiometer.I started with this aproach to learn to use a comparator and understand it, wich is working, instead of a easier/more eficcient solution (throwing a button is not enough for my soul).for the configuration you recommended... how does the change in voltage (dV/dt) gets differentiated between the pins? i feel im missing something, maybe a simple sketch of the circuit would help, or is it too much asking?(sorry if it is).Again, thank you!!

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 07, 2018, 07:09:16 am
content: Talk is cheap, but if you'd like to "commission" a schematic, we can do that...(Or more likely, someone else will come along and do it)The best solution (that I forgot to get to) is an encoder. Two digital outputs, MCU watches any change, not rate sensitive. If it goes noisy (possible with a mechanical contact type, or an optical type on the edge), it only toggles between adjacent states, and you can filter that out, limiting the number of trigger events the MCU sees, and you can divide the states in half so nothing actually moves until two states over.Downside: encoder is free rotation, which can be annoying for a control that ought to be a 0-100% potentiometer control.Tim

author: danadak
author_rank: Super Contributor
timestamp: January 07, 2018, 11:20:34 am
content: Comparator Hysteresis ref material -http://www.analog.com/en/analog-dialogue/articles/curing-comparator-instability-with-hysteresis.htmlhttps://www.maximintegrated.com/en/app-notes/index.mvp/id/3616http://www.ti.com/lit/ug/tidu020a/tidu020a.pdfRegards, Dana.

author: superwester
author_rank: Contributor
timestamp: January 08, 2018, 05:18:07 pm
content: So...this is what i came with:http://tinyurl.com/y87wfedeit does the job pretty goodthanks to your insightful answer and with a bit (a lot) of tinkering i finally pulled throughfeel free to criticize my circuit, im sure it has a lot to improve.thanks again!