Author Topic: (Update!) How do you calculate Hysteresis ?  (Read 1523 times)

0 Members and 1 Guest are viewing this topic.

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
(Update!) How do you calculate Hysteresis ?
« on: May 18, 2020, 09:58:33 pm »
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 calculate R3 and R5 and V_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

 
« Last Edit: May 21, 2020, 02:00:07 pm by jbs »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19546
  • Country: gb
  • 0999
Re: How do you calculate Hysteresis ?
« Reply #1 on: May 18, 2020, 10:35:34 pm »
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
 
The following users thanked this post: jbs

Online chris_leyson

  • Super Contributor
  • ***
  • Posts: 1541
  • Country: wales
Re: How do you calculate Hysteresis ?
« Reply #2 on: May 18, 2020, 11:41:54 pm »
^^^ 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.
 
The following users thanked this post: jbs

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
Re: How do you calculate Hysteresis ?
« Reply #3 on: May 19, 2020, 09:14:27 am »
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).

 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19546
  • Country: gb
  • 0999
Re: How do you calculate Hysteresis ?
« Reply #4 on: May 19, 2020, 09:45:24 am »
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).
If 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.
 
The following users thanked this post: jbs

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
Re: How do you calculate Hysteresis ?
« Reply #5 on: May 20, 2020, 09:04:46 pm »
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.
« Last Edit: May 20, 2020, 09:08:04 pm by jbs »
 

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
Re: How do you calculate Hysteresis ?
« Reply #6 on: May 20, 2020, 09:56:02 pm »
Should I use a transistor, or is there a better way?
 

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
Re: How do you calculate Hysteresis (update)?
« Reply #7 on: May 21, 2020, 01:59:18 pm »
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
« Last Edit: May 21, 2020, 08:53:26 pm by jbs »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19546
  • Country: gb
  • 0999
Re: (Update!) How do you calculate Hysteresis ?
« Reply #8 on: May 21, 2020, 08:56:45 pm »
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.
 
The following users thanked this post: jbs

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
Re: (Update!) How do you calculate Hysteresis ?
« Reply #9 on: May 21, 2020, 10:08:14 pm »
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...
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19546
  • Country: gb
  • 0999
Re: (Update!) How do you calculate Hysteresis ?
« Reply #10 on: May 22, 2020, 07:45:48 pm »
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.
 
The following users thanked this post: jbs

Offline jbsTopic starter

  • Contributor
  • Posts: 33
  • Country: lu
Re: (Update!) How do you calculate Hysteresis ?
« Reply #11 on: May 22, 2020, 09:26:51 pm »
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.
« Last Edit: May 23, 2020, 09:09:18 am by jbs »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19546
  • Country: gb
  • 0999
Re: (Update!) How do you calculate Hysteresis ?
« Reply #12 on: May 23, 2020, 02:26:05 pm »
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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf