Skip to main content

Reply to "Using an optocoupler to connect insulated rail to input pin of shift register"

For some reason it still doesn't seem to have been made clear that a shcmitt trigger does not debounce an input.  It only filters noise.  Bounce is the effect caused when a switch is thrown or button pushed or wheels bridge an insulated rail, where the contact points rapidly open and close.  You get dozens, or hundreds, of on and off pulses over the course of a fraction of a second.  A micro-controller will read each one of these pulses as a separate on/off event if not debounced in some manor.  Each of these pulses, however is a (near enough) logic high or low, so if for example you were working with a 5 volt system, when you push a button the processor will read a couple dozen pulses of 0 and 5 volts before the contacts settle.  This is solved by using an RC circuit in hardware, which uses a resistor and capacitor to filter out the pulses as it takes time to charge up and then discharge. Or in software by writing code that says to ignore any rapid input changes and only report changes that have remained steady for a given amount of time.

The Schmitt trigger, on the other hand is used to filter inputs with noise, where the voltage of the input is not a full 5 or 0 volts (again assuming a 5v system).  Lets say for the example that the input reads everything below 2.5 volts as a logic low, and everything above as a logic high.  Here when the input is transitioning from low to high there can be noise on the signal, little pulses of say, a tenth of a volt up and down.  As the signal is rising up toward 2.5 volts this noise can cause the input to read many points where the voltage swings above and below 2.5 volts until the low points of the noise are above 2.5v on the way to 5v.  This will cause the logic output to rapidly oscillate high and low each time the input noise goes above or below that 2.5v threshold.  The Schmitt trigger works by providing hysteresis, or a buffer zone between the voltage that switches  the logic high and the voltage to switch low.  As an example if we provide 1 volt of hysteresis on the input, the output will only go high when the input reaches 3 volts.  in turn it will remain high until the input drops below 2 volts.  this effectively filters out the noise on the input as it is not enough voltage change to reach to point where the output will change.  

An input signal with bounce will still have bounce when put through a schmitt trigger, since the bounce is swinging well beyond the hysteresis thresholds of the schmitt trigger.  Debouncing and Hysteresis are both needed for a reliable input signal, but they are two different things doing two different jobs.  In the case of the original reason Schmitt triggers were brought up in this thread, the problem is that the opto coupler may not fully saturate, and when this happens it's output can be some floating value that digital logic could read as anything.  The Schmitt trigger in this circuit works to turn this undefined on/off state into a clearly defined one.  


With the 74165 parallel to serial shift register, a Schmitt trigger is needed as these chips deal in absolute logic and will be undefined with voltages in the middle range.  Through various incarnations way up in this thread I attempted to remove the need for extra parts and complexity in the circuit by using the input pins of a micro-controller which have built in Schmitt triggers on them.  It runs up the cost, but makes the circuit much less complex to put together.  (Though if one accounts for PCB board space the cost difference isn't that much) By using a Mega instead of an Uno, Nano, or ProMini, one can eliminate 10 other chips from the circuit as well as all the wiring and soldering of those parts.  One could also use something like the MCP23017 port expander as it also has built in Schmitt triggers on all inputs, but this isn't as cost effective as just using a Mega clone, as you would need 2 or 3 of them to get the job done, and it's more parts to work with.  Using the Mega also gives 8 times the storage space for your program, allowing much more flexibility and added functionality.  

Anyway, main point is both debounce and Schmitt trigger are needed, but the Schmitt trigger is built in on Arduino micro-controllers as well as on the port expander chips.  (you can find the hysteresis of the port expander on page 28 of it's data sheet from Microchip.)

JGL

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×