(Update!) How do you calculate Hysteresis ? - Page 1
Forum section: electronics / beginners

author: jbs
author_rank: Contributor
timestamp: May 18, 2020, 09:58:33 pm
content: Hi all,I'm trying to learn about Schmitt triggers. (Thanks to @Doctorandus_P for pointing this out to me)Here's my schematic:The IC is an open collector comparator LM339.How can I calculateR3andR5andV_out(V_out should preferrably be 5 V again, is that possible?), if I know R2 and R4 (both 10K for example)?Thanks in advance,Joël

author: Zero999
author_rank: Super Contributor
timestamp: May 18, 2020, 10:35:34 pm
content: I don't have a massive amount of time to walk you through everything now, so I'll post a few hints:Look up potential dividers and resistors in parallel.R2 and R4 form a potential divider.When the output is low, pin 4 is connected to 0V, via the comparator's output transistor, so R3 is in parallel with R4. Now we have a potential divider with R2 at the top and R3 & R3 in parallel at the bottom.When the output is high, pin 4 is open circuit. R3 is connected to +V, via R5. V+ is also connected to R2. Now we have a potential divider with R4 at the bottom and R2 in parallel with R3 connected in series with R5.The output voltage, when the output is high, can be calculated, as R5 and R3 form another potential divider between the non-inverting input and +V.If R5 has a very low value, compared to R3, say one hundredth of the value, then it can be ignored, thus simplifying the calculations. Here's an application note showing how to calculate the hysteresis for a comparator with a push-pull output, which is similar to R5 being tiny, compared to R3.http://www.ti.com/lit/ug/tidu020a/tidu020a.pdf?&ts=1589841131589

author: chris_leyson
author_rank: Super Contributor
timestamp: May 18, 2020, 11:41:54 pm
content: ^^^ What Zero999 said and the TI app note.If you make some assumptions to simplify things, for example, comparator output is either 0V or 5V and R5 << R3. Ignore R3 for now and assume the comparator inputs draw no current. Treat R2 and R4 as a Thevenin source that set the threshold voltage Vt, open circuit voltage at the junction of R2, R4 is 2.5V and the source impedance is R2//R4 = 5k. Say for example you want +/-10mV hysteresis then how much current do you have to inject into the node formed at the junction of R2 and R4. I = V/R = +/-10mV/5k = +/-2uA. This current is supplied by R3.Assuming the comparator output is high, Vo = 5V and Vt = 2.5V + 10mV = 2.51V then R3 = (5-2.51)/2uA = 1.245MEG. Similarly for a low output Vo = 0V and Vt = 2.5V - 10mV = 2.49V then R3 = 2.49/2uA = 1.245MEG. R3 will be be the same for each case because of symetry, Vt = 2.5V, half the supply voltage, and Vo swings +/- 2.5V with respect to Vt. Also, if the hysteresis is very small compared to the output voltage swing then you could ignore it and R3 = 2.5/2uA = 1.25MEG which is close enough. If Vt is some other voltage, say 2V, then you will get two values for R3 and this is where steering diodes come into play but that is another story.

author: jbs
author_rank: Contributor
timestamp: May 19, 2020, 09:14:27 am
content: Thank you both very very much. This helped me understand a lot. However I have one question. How come that if I put a small resistor (220 Ohm) on R5 there is still some voltage across that resistor, even when the output is off ? For example, if R2=R3=R4=10k, and R5=220, then the output voltage is 1.54 V when LOW (and 5.03 V when HIGH).

author: Zero999
author_rank: Super Contributor
timestamp: May 19, 2020, 09:45:24 am
content: Quote from: jbs on May 19, 2020, 09:14:27 amIf R5 is very low, the comparator's output transistor will never saturate. It will be in the linear region when on, thus dropping a reasonable voltage, rather than the couple of hundred mV, when saturated. This will have more effect when the voltage on the input potential divider is low. To ensure saturation, R5 shouldn't allow more than 6mA to flow, so for 5V the minimum value is just under 1k.

author: jbs
author_rank: Contributor
timestamp: May 20, 2020, 09:04:46 pm
content: Thanks again. One very last question, since I got it almost worked out, how can I invert the output signal?Let me explain. In my configuration, instead of R1 I have a reflective optical sensor CNY70. The sensor puts out approx. 0 voltage unless I obscure it, in which case the voltage increases.So in the beginning, the LM339 has an ouput that is HIGH, because the CNY70's 0 volts are below the reference voltage (set by R2 & R4, or in my configuration, a trimpot). When I obscure the sensor, its voltage increases until it passes the reference voltage threshold and the LM339 changes its output from HIGH to LOW.I need it to be reversed, I need the output to read HIGH, once the CNY70 increases the voltage past the threshold.I've tried to invert the pins (non-inverting and inverting), but to no avail...because the Schmitt trigger fails.

author: jbs
author_rank: Contributor
timestamp: May 20, 2020, 09:56:02 pm
content: Should I use a transistor, or is there a better way?

author: jbs
author_rank: Contributor
timestamp: May 21, 2020, 01:59:18 pm
content: So I have done the following. It works, but is there a more efficient way (without adding a Not Gate)? Also, is this a good alternative, or can you suggest a better one ?Thanks, Joël

author: Zero999
author_rank: Super Contributor
timestamp: May 21, 2020, 08:56:45 pm
content: To get non-inverting, apply the signal to the non-inverting input, via a series resistor with the same value as R2 & R4 in parallel and move R2 & R4 to the inverting input.

author: jbs
author_rank: Contributor
timestamp: May 21, 2020, 10:08:14 pm
content: Not sure if I'm following correctly. Do you mean like this ?where R6 = R2*R4/(R2+R4). I'll have to ponder upon why R6 is even necessary...

author: Zero999
author_rank: Super Contributor
timestamp: May 22, 2020, 07:45:48 pm
content: If R6's value is equal to R2 and R4 in parallel and R3 +R6 are much greater than R1, then the voltage thresholds will be same as the other circuit.If you remove R6, then the hysteresis will depend on R1's wiper setting.

author: jbs
author_rank: Contributor
timestamp: May 22, 2020, 09:26:51 pm
content: I can't thank you enough, zero999. /hug.The above schematics were for the purpose of better understanding.Here's my final schematic. Hopefully it is correct.The phototransistor is a CNY70. The reference voltage is set by a potentiometer R1. (I have renamed the resistors, mind you, e.g. R4 is the Schmitt trigger)As you can see, with this configuration, R1 can be changed (as opposed to R2&R4 in the previous schematic), but R6 will stay fixed...My objective with this circuit is the following: I want to build a midi controller for a Piano action. I measure the velocity of a piano hammer with a CNY70 that is attached above a key. I use 2 trimpots to set 2 different voltage threshold, representing 2 different positions of the hammer in relation to the key. Whenever the hammer approaches the sensor, the comparator will trigger twice, and I will be able to calculate the velocity.

author: Zero999
author_rank: Super Contributor
timestamp: May 23, 2020, 02:26:05 pm
content: The LM339 has four comparators on the IC, so why not use the others? A three comparator circuit can be used to provide independent thresholds for the on and off voltages.https://www.eevblog.com/forum/beginners/the-simplest-thermostat-with-programmable-thresholds/msg1432025/#msg1432025