Maker Pro
Maker Pro

Voltage comparator debouncing

pineapple

Oct 24, 2011
6
Joined
Oct 24, 2011
Messages
6
Hello! I'm working on a simple comparator circuit that will be used to measure resistivity. However, I'm having a lot of trouble with double counting and false readings. It seems like I need to do some sort of debouncing, but I'm pretty new to this and not exactly sure what the best way of handling it would be. My circuit is below:

circuit.jpg


The circuit is designed to test for regions of low resistivity across a surface that is normally non-conductive. R4 is actually a set of probes that run across the surface. The value (0.27) will vary, I've just set it at this to represent equilibrium between the inputs. My problem is that minor "spikes" in the surface are picked up by the comparator, which in turn results in false readings on my counter circuit. I've got the resistors tuned down about as far as I can go. (Any less and my threshold would be below the resistance in my probes!).

So my question now is - is there any way to tune out the "spikes"? I tried adding a 10uF capacitor between my output and ground, but that resulted in a slow response time. Also not sure what adding the cap does to my digital output (i'll be interfacing this with another device eventually). Any help would be very appreciated!
 

pineapple

Oct 24, 2011
6
Joined
Oct 24, 2011
Messages
6
My mistake, I drew R5 and C1 wrong. They should both be connected to the + input of the comparator. R5 is supposed to be for hysteresis. R6 is my pull-up resistor. See correct circuit below:

circuit2.jpg


I'll have to try Alchymist's suggestion about adding a capacitor across R4. THanks again!
 

davenn

Moderator
Sep 5, 2009
14,254
Joined
Sep 5, 2009
Messages
14,254
your corrected circuit didnt post ... ie its not there to view


nor is the old cct either .... try again :)
 

Laplace

Apr 4, 2010
1,252
Joined
Apr 4, 2010
Messages
1,252
It is typical to provide only a few millivolts of hysteresis for comparator operation. Make R5 something larger than 10 ohms, perhaps 56K. As it is the output of the LM311 is trying to drive a 20 ohm resistance to ground, so the output voltage will be current-limited.
 

pineapple

Oct 24, 2011
6
Joined
Oct 24, 2011
Messages
6
Hmm, I found a site that gives the following method of calculating hysteresis. Does this sound right?

The fractional change in the threshold is roughly the value of the divider resistors in parallel divided by the feedback resistor, here 5/100 or 0.05. With a 5 V supply, this gives a difference of 0.25 V, called the hysteresis.

Even so, I'm not sure if improving the hysteresis will prevent all of the false readings on the random "spikes" I'm seeing. It's almost like I need some way of determining for how long the comparator is high. This way I could filter out output pulses that were too short. I'd want to maintain the digital output of the comparator. Is there maybe a way to do this with a timer IC?
 

Resqueline

Jul 31, 2009
2,848
Joined
Jul 31, 2009
Messages
2,848
The issue Laplace tried to convey is not so much about the hysteresesis in itself, but the low value of the hysteresis resistor you have there now, limiting output amplitude.
What kind of an output amplitude are you seeing now? 235mV perhaps? That low amplitudes are prone to noise infringement. It would be better if it was closer to 12V.
To achieve this amplitude I suggest replacing R5 with a 22-47k resistor in series with a 470k potentiometer. At max resistance there will only be a minimal hysteresis.
The output of a comparator with hysteresis (and also a positive feedback capacitor) is already digital in nature. You may also have an issue with cabling & shielding btw..
 

Laplace

Apr 4, 2010
1,252
Joined
Apr 4, 2010
Messages
1,252
So the inputs to the comparator are normally around 12 mV, but occasionally the probe to R4 will lose contact and the '-' input will jump to 12 V.

Placing a capacitor across R4 will stabilize the '-' input but the capacitor will charge to 12 V through R3. Suppose that the probe loses contact for 1 msec and during that time the input voltage should not rise by more than 3 mV, then the time constant T is calculated: (3 mV)/(1 msec)=(12 V)/(T), T=4 sec. This is also the RC time constant, T=(R3 x C), C=4/270=15,000 uF.

Now suppose that you buffer the comparator inputs with resistors of equal value, assuming that these can be selected as exactly equal so the input bias current can be ignored, and C is directly connected to the '-' input. With an input offset current of 10 nA, let's say you would not want more than 1 mV of offset voltage due to the resistors. R=E/I=(1 mV)/(10 nA), R=100K. So now C will charge through the 100K resistor for that 1 msec. C=4/100K=40 uF. If you can find an ultra-low leakage 40uF capacitor, then this might be an acceptable approach.

Otherwise I could only suggest adding a second comparator to detect when when the probe input voltage jumps to 12 V and use that signal to digitally inhibit the original comparator output, or else to prevent the capacitor from charging by shunting the charging voltage. In that case you could use a much smaller capacitor, for instance a 0.68 uF film capacitor.
 

pineapple

Oct 24, 2011
6
Joined
Oct 24, 2011
Messages
6
Thanks for all your help guys. Sorry if I seem a bit daft at all this, it's been a while since studying this stuff :eek:

Laplace, I think I'm going to do something similar to what you suggested in your last paragraph there, add a second comparator. I'm using an lm339, so I have 4 of them! In my searching, I was able to find a circuit design that uses two comparators to force a delay. I think this will actually serve my purpose perfectly.

ComparatorTimeDelay.GIF


Of course, 3 seconds is a little much. I'll probably swap in a 10K trimmer and a 10uF cap. This will give me the ability to tune a delay of a few milliseconds. I tried a test with a fixed 3.3K resistor and it seemed to work pretty good! I think this is the design I'm going to run with!
 

pineapple

Oct 24, 2011
6
Joined
Oct 24, 2011
Messages
6
Good morning! It's been a while since discussing this last. I think I've finally settled on a design that will suit my needs. Attached is the revised circuit diagram as well as a chart explaining how I "think" this will work. Basically, SW1 will be connected to two probes. As the resistance between the two probes rises past the tripping point (in this case, past 0.245 Ohms), the first comparator will output 12V. At this point, the RC circuit adds a delay of 23ms before activating the second Comparator. This should filter out any erratic spikes. R2 can be tuned to set at what point the first comparator trips. R5 can be tuned to control the delay. Overall, I think this will serve my needs, but I wanted to run it past everyone before ordering parts and constructing it. Any feedback is appreciated! Thanks!
circuit3.jpg

chart1.jpg
 

Laplace

Apr 4, 2010
1,252
Joined
Apr 4, 2010
Messages
1,252
Circuit operation here is tied directly to the nature of the probe contact bounce. Not sure whether the probe signal will be as clean as depicted in your diagram. If you will get a contact bounce more often than 23 ms when moving the probe, then you have succeeded in suppressing any output while the probe is in motion. Was that your intention? However, if you need the indicator to work while the probe is in motion, then you may need a more sophisticated approach than time delay. It all depends on what the probe contact bounce looks like. A digital storage oscilloscope would be useful to investigate that.
 
Top