Electrical – Some questions on optimizing a Schmitt trigger to eliminate possible glitches

ltspiceschmitt-trigger

enter image description here

Above is a Schmitt trigger circuit using a LM2903 open collector comparator. On the left side the incoming pulses are mixed with noise. Before the noise the desired clean 5Hz incoming pulse train looks like:
enter image description here
After adding up to the incoming pulse the 5000Hz noise itself is 3V and looks like:
enter image description here
And at the non-inverting input the noisy signal becomes as:
enter image description here
The noisy output pulse train becomes:
enter image description here
And here is when we zoom a "rising edge" you can see the glitches:
enter image description here

I have used similar easier circuits before but there are some points to optimize and improve this circuit.

My question is:

To eliminate the glitches at the output, it seems to me there are two options here. A low-pass filter which blocks above lets say 500Hz freq. or a higher hysteresis which is 5V between upper and lower threshold.

1-) But if the noise is not known and is a "possible noise" what would be the safe improvement to this circuit to eliminate possible glitches from a better design perspective? A low pass filter? A higher hysteresis? Or both? Is C1 already forming a lowpass filer?

2-) Although I know the hysteresis concept and its benefits I'm unable to see that in simulation. How can I see the upper and lower thresholds of the hysteresis in simulation? Can it bee seen by looking at the voltages at point X or Y? But X is the non-inverting input and Y looks like fixed by voltage dividers. How can I increase the hysteresis and see the actual lower and higher thresholds? I tried playing with R1 and R4 values and couldn't succeed.

edit:

I attempted to create noise with a concerned citizen's suggestion. But I guess I didn't get it all right since I get the following error when trying to simulate:
enter image description here

Best Answer

You cannot just ignorantly apply a comparator.

First, you need to have an approximate description of what your input signal looks like and what range of behavior it may have. If this is supposed to be a digital input that switches between \$0\:\textrm{V}\$ to \$18\:\textrm{V}\$, but that you have noise on this that is \$V_{PP(RMS)}=2\:\textrm{V}\$, centered on your signal, then you should be able to infer from those facts that you will see even larger excursions (because RMS just means that there's a 63% chance that you'll see noise within \$\pm1\:\textrm{V}\$ excursion, but this also means that there is a 37% chance it will be larger than that and you cannot ignore 37% of your possible input signal.) So you might decide that you need \$5\sigma\$. If so, in this case you'd need hysteresis large enough to cover \$V_{PP(RMS)}=10\:\textrm{V}\$.

There is a limit to your hysteresis. Obviously, you can't make hysteresis cover the entire voltage supply range.

Let's say you want to center this at the rough midpoint, \$+12V\:\textrm{V}\$. Let's also say that you want to use up \$\tfrac{1}{3}\$rd of your input range for hystersis -- an aggressive stance. Then you want your hysteresis band to be \$12 \pm 3\:\textrm{V}\$.

Let's first set up the schematic without hysteresis where the output inverts the input:

schematic

simulate this circuit – Schematic created using CircuitLab

I think you can see the midpoint there. It's just a voltage divider. It's Thevenin resistance is \$5\:\textrm{k}\Omega\$. Your output can drive LOW quickly (active, open-collector), but cannot drive HIGH quickly (\$R_3\$.) So here, again, you have another decision to make. What do you need for \$R_3\$ in order to meet other needs (capacitive loading, etc.) In this case, I've ignorantly decided on \$10\:\textrm{k}\Omega\$. But the point here is that you need to decide this not ignorantly. You need to know what you need here.

You can now consider how to add hysteresis. To achieve that, you use positive feedback. Input is applied to the (-) input, so the output will be oppositely arranged. But doing it this way means it is very easy to visualize how the output can contribute and modify the input threshold as positive feedback.

So, when the output is HIGH (because the input is LOW) you want the divider voltage to be higher than the midpoint so that the input needs to move further away from ground before the next transition. Similarly, you want the threshold to be lower than the midpoint when the output is LOW (because the input is HIGH) so that the input needs to move further away from the positive rail before the next transition.

This is very easily done by adding a resistor from the output to your midpoint divider voltage:

schematic

simulate this circuit

Note that I've removed the values here. There is a reason. You need to solve the resistor values.

The first thing to do is to look at the datasheet for the LM2903 (I'm picking that one) to check its output capability. It's given as about \$6\:\textrm{mA}\$, typical. Note that it also adds this is with \$V_{OL}=1.5\:\textrm{V}\$! It is pretty weak. (It shows \$80\:\mu\textrm{A}\$ as the base drive current.) So this really isn't a high output current device. Rather the opposite. I think I'd like to go for sinking \$1\:\textrm{mA}\$ when LOW. Since I need to sink current for both the pull-up as well as whatever I'm doing to the biasing pair via the positive feedback resistor, I'll figure on dividing that out as 90% for the pull-up and 10% for the feedback resistor to work with. (The more we reserve for the pull-up, the closer to \$24\:\textrm{V}\$ the output can get.)

I can now compute the values for \$R_3\$ and \$R_4\$ (I'll show standard values here):

$$\begin{align*} R_3 &= \frac{24\:\textrm{V}}{90\% \cdot 1\:\textrm{mA}} \approx 27\:\textrm{k}\Omega \\ \\ R_4 &= \frac{9V}{10\% \cdot 1\:\textrm{mA}} \approx 91\:\textrm{k}\Omega \end{align*}$$

Now, given the two estimated thresholds, we know the following should be approximately correct:

$$\begin{align*} V_{TH} - R_{TH}\cdot \left(10\% \cdot 1\:\textrm{mA}\right) &= 9\:\textrm{V} \\ \\ V_{TH} + R_{TH}\cdot\left(\frac{24\:\textrm{V}-15\:\textrm{V}}{R_3+R_4}\right) &= 15\:\textrm{V} \end{align*}$$

This solves out as:

$$\begin{align*} V_{TH} &\approx 12.404\:\textrm{V}\\ \\ R_{TH} &\approx 34.04\:\textrm{k}\Omega \end{align*}$$

Yielding the following standard values for \$R_1\$ and \$R_2\$:

$$\begin{align*} R_1 &=R_{TH}\left(\frac{24\:\textrm{V}}{V_{TH}}\right) \approx 68\:\textrm{k}\Omega \\ \\ R_2&=\frac{R_1\cdot R_{TH}}{R_1-R_{TH}} \approx 68\:\textrm{k}\Omega \end{align*}$$

So here is the resulting schematic:

schematic

simulate this circuit

That should about do it. The only remaining problem is that your output voltage won't actually reach the \$24\:\textrm{V}\$ rail, as the feedback and biasing pair load it down a bit. But it will get close (within about \$2\:\textrm{V}\$) and you are well within the operating parameters for the LM2903, as well, which will be sinking only \$1\:\textrm{mA}\$ and should get close to 0 V, then.

I also have no idea what is being driven by this. It's possible that you need more drive than this circuit can provide. It's not able to drive much of a load, as it is. But there's no spec. So I'm free to do this, I suppose.

This comparator inverts your input, though. I wanted to start simple and build on that and it was easier that way.

EDIT: Here's a case where the output doesn't invert the input. Rather than load down the input side, I'll just add an inverting BJT:

schematic

simulate this circuit

The way I figured the above circuit wasn't hard. I already knew from the prior analysis that I needed approximately \$27\:\textrm{k}\Omega\$ for the pull-up. I left most of that in \$R_3\$, as re-dedicated to supplying \$Q_1\$'s base current. I picked \$22\:\textrm{k}\Omega\$ very quickly, just by estimating \$22\:\textrm{V}\$ across it with \$1\:\textrm{mA}\$ through it. So the resistor just fell out of that thinking. It's really \$900\:\mu\textrm{A}\$ from the original design. But I didn't care enough to mess with it further. That left the remaining \$5\:\textrm{k}\Omega\$. I put that into \$R_6\$ and rounded up because I had used \$1\:\textrm{mA}\$ and should have used \$900\:\mu\textrm{A}\$. That's it.

From basic Silicon physics, I know that the BJT's base will drop about \$26\:\textrm{mV}\cdot ln\left(\tfrac{1\:\textrm{mA}}{18\:\textrm{fA}}\right)\approx 643\:\textrm{mV}\$ when active. So \$R_6\$ will only pull away about \$115\:\mu\textrm{A}\$, leaving plenty of drive current for the BJT.

That should do it. Now the output will get close to \$24\:\textrm{V}\$ and to \$0\:\textrm{V}\$.

EDIT: Try the following as your reed relay input to the (-) input of the opamp from the above schematic.

schematic

simulate this circuit

You can add additional components to filter and otherwise condition the signal. I added a resistor and capacitor there as a simple filter. You could use it, or remove it, and see how it goes. But the hysteresis is huge in the above opamp circuit. So I don't think there will be problems. But I really don't know what you are actually dealing with in practice and there are no promises, of course. (Also, keep in mind I'm just a hobbyist. I'm NOT an EE. Not even close.)

So here is the final diagram from my end. You can add your own mods.

schematic

simulate this circuit

Better to just do this by limiting the input range, feeding the input into your micro as a digital input, and doing the debouncing in software. Lots less hardware to worry over. This is the most Rube Goldberg design imaginable for handling nothing more than a reed relay switch. (I've no idea why 24V, either. But there it is. Oh, well.)