0
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ What is the noise amplitude in this simulation? \$\endgroup\$ – Ale..chenski Oct 5 '16 at 17:43
  • \$\begingroup\$ I couldnt manage to add 3V noise from a seperate 3V source to a pulse in LTspice(my ignorance) so I tried different combinations at least to achive a noisy pulse train which has noise with 3V amplitude and 5000Hz freq. It is at the INPUT just before 2.2k. I say 3V but it is actually less.. But I want to have a very large hysteresis to eliminate any possible glitches caused from noise \$\endgroup\$ – user16307 Oct 5 '16 at 17:44
  • \$\begingroup\$ For 3Vpp white noise, first add your original source as a voltage source with Rser=3, then add a behavioural current source with I=white(2*5k*time). The 2*5k is necessary to achieve a 5kHz bandwidth within around -6dB. If you think the source's resistance (3) is too large for you case, simply make it as low as you need (say 1m) then scale the current source accordingly: white()/1m*3. Don't forget that using a too high dynamic range, V, A, Hz, etc, will make LTspice "compromise". To avoid that, add .opt plotwinsize=0 and, maybe, a timestep of ~(highest freq)/10. \$\endgroup\$ – a concerned citizen Oct 6 '16 at 7:31
  • \$\begingroup\$ @aconcernedcitizen could u have a look at my edit. i tried to do what u suggested but what is wrong there? \$\endgroup\$ – user16307 Oct 6 '16 at 11:02
  • \$\begingroup\$ @user16307 After adding your voltage source (V1), in its properties, look for Series resistance, on the right. Set it to 3 (or just add Rser=3 after SINE(...)). Then, instead of a current source, add a bi, or bi2 (behavioural current source). Edit the I=F(...) to what you have in your example. It's better to use the internal Rser, in a voltage source, because 1) it will not add towards the node count and b) it will transform the voltage source into a current source, internally, which has superior convergence (as per the manual). \$\endgroup\$ – a concerned citizen Oct 6 '16 at 12:02
5
\$\begingroup\$

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.)

\$\endgroup\$
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Dave Tweed Oct 7 '16 at 1:05
  • \$\begingroup\$ @DaveTweed Thanks. Wish I knew how to do that without waiting for it to prompt me. Haven't noticed how that gets done, yet. More learning to do. \$\endgroup\$ – jonk Oct 7 '16 at 1:08
  • \$\begingroup\$ Hi again in this circuit I think theres a problem. The inverting input goes to 24V which is same with the supply voltage. And if I add nose to the signal it exceeds 24V. So I opened a new question regarding this: electronics.stackexchange.com/questions/262364/… \$\endgroup\$ – user16307 Oct 8 '16 at 15:25
0
\$\begingroup\$

It looks like you have the noise level set to about 2-3V p-p. The circuit hysteresis is, however, only about 50mV ( ~ 2.2/1000 * 24V). If the circuit hysteresis is smaller than noise, it will still follow some transitions and will output glitches. Of course, the result will depend on relationship between spectrum of noise and edge rate of main signal, but generally the hysteresis should be bigger than the noise amplitude to avoid multiple transitions on signal edges.

\$\endgroup\$
  • \$\begingroup\$ But how can I increase hysteresis to 5V here? And how can I see that 5V treshold change in simulation? \$\endgroup\$ – user16307 Oct 5 '16 at 17:55
  • 1
    \$\begingroup\$ You have the issue with signal edges. Then why didn't you zoom and compare your input signal with output near the edge itself? You already have the output, now check how it is related to your input. \$\endgroup\$ – Ale..chenski Oct 5 '16 at 18:01
  • 1
    \$\begingroup\$ By definition, hysteresis replaces a single detection threshold with two - one for positive-going and one for negative-going signals. This in turn means that the minimum signal amplitude which can be detected gets larger and larger as hysteresis is increased, and the circuit responds more and more cleanly, but only to larger and larger signals, and missed pulses becomes a real possibility. Your circuit is an extreme case, with very large signal swings. Try reducing your pulse amplitude and you'll see what I mean. \$\endgroup\$ – WhatRoughBeast Oct 5 '16 at 18:39
  • 1
    \$\begingroup\$ Also, be aware the the circuit has a nominal (no hysteresis) detection threshold of approximately 0.54 time Vcc, set by R3 and R4. Be careful if you change the pulse amplitude, since that is referenced to ground, not to the trigger point. \$\endgroup\$ – WhatRoughBeast Oct 5 '16 at 18:42
  • 1
    \$\begingroup\$ Simply show your input and output at the same time. The output transitions mark the input values. \$\endgroup\$ – WhatRoughBeast Oct 5 '16 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.