A recent PetitFoo talk at the Chaospott on how to debounce keys with a Schmitt trigger prompted me to play with a 74HC14 IC I had lying around.

A Schmitt-trigger converts an analog voltage to a digital logic level. It has two voltage thresholds, and the interesting thing happens between the two:

  • Below the lower threshold the input is considered logically low, so the inverter outputs a logic high.
  • Above the upper threshold the input is considered logically high, so the inverter outputs a logic low.
  • Between the two thresholds the Schmitt-trigger keeps the input state, so the output doesn't change.
  • That last part of the behavior is called hysteresis. It helps to avoid uncontrolled switching due to noise on the input, especially when the input is changing slowly compared to the switching speed of a logic IC.

    Basic Behavior

    Here is an oscilloscope screenshot of the basic behavior of one inverter of the 74HC14, using a triangle wave from the function generator as the input: Oscilloscope screen showing 74HC14 schmitt-trigger behavior The yellow trace is the input triangle wave, the green trace is the output. The X cursors are set to the edges of the output manually. The Y cursors are set to track the input waveform, in order to get the voltages corresponding to the X cursors. You can see that it switches the output when the input reaches 1.94 V on the downward slope (Y1), and when it reaches 3.07 V on the upward slope (Y2).

    Circuit

    The circuit is very simple and consists only of the 74HC14, and a 100 nF decoupling cap for the power supply on the top left of the IC. Breadboard with 74HC14 and attached oscilloscope probes The input signal is attached to the pin header on the left and is connected by the green wire to the input of the first inverter on pin 1 of the IC. Its output is on pin 2. The other inputs are tied to ground to prevent unwanted oscillations, other outputs are not connected. The oscilloscope probes on pin 1 and 2 are attached via 100 Ω resistors, which reduce ringing but cause a small slowdown.

    Schmitt-trigger vs standard logic input

    A close-up on the output edge shows that it is very clean. Its rise time is about 3 ns and there is just a little bit of overshot and ringing: Oscilloscope screen showing the rising edge of the output with 10ns/div

    When the 74HC14 is replaced by a 74HC04 hex inverter with standard non-Schmitt-trigger inputs (and the triangle wave slowed to 10 kHz) then the output misbehaves severely, oscillating for about 600 ns somewhere in the middle between the logic levels: Oscilloscope screen showing the rising edge of the output oscillating in mid-transition

    Building a Relaxation Oscillator

    It's also easy to build an oscillator from a Schmitt-trigger inverter, a so called relaxation oscillator. Connect a capacitor between the input and ground, and a resistor back from the output to the input. Then the output will cyclically charge and discharge the input capacitor, and the input voltage will oscillate between the two thresholds. The frequency is determined by R, C and the threshold voltages, which in this case are not that well defined (the ranges for the thresholds specified in the data sheet are quite large). So it should only be used if the frequency doesn't need to be precise. This is an example with R = 10 kΩ and C = 100 nF and a frequency of roughly 1 kHz: Oscilloscope screen showing severe oscillations overlaid on the signal

    Tie Your Inputs Down!

    And since it is so easy to get an oscillator, if you don't tie the other inputs to a defined logic level then it may happen all by itself, some of the inverters may start to oscillate and disturb the rest of the system. In my circuit the first inverter does this, and if I connect the triangle wave to the second inverter it gets a lot of injected noise from its neighbor: Oscilloscope screen showing severe oscillations overlaid on the signal