Using the INT0 interrupt to count external pulses (also hardware debounce)Dr Nathan Scott & Dr Hiroyuki Kagawa · July 2002 Microcontrollers can sense the voltage levels on their pins and software can be written to respond to these levels. In this tutorial we will set up an AVR to respond to an external digital signal using an interrupt method. |
|
|

Figure 1 Example program that uses the INT0 interrupt
It is very likely that you will find that your LED flashes in an apparently random way. Sometimes it will turn on, sometimes it won't, every time you connect or disconnect the "digital input" wire. Why? |
Figure 2: example of an input which is tied low and another which is tied high.
|
Figure 3: switch noise and floating input noise when the INT0 wire is moved (apologies, figure shows AT90S8535, an older AVR.)
|
|
Figure 4: noise caused by switching or from a floating input is converted to a very fast digital noise signal.
|
Here is a simple circuit which greatly reduces switching noise: |
Figure 5: a debounce circuit (tied low version)
The circuit of Figure 5 is supposed to have the effect shown in figure 6:
Figure 6: desired effect of the capacitor debounce circuit of Figure 4
I had to go to the internet and do some research. I learned that most digital logic circuits do not like slowly changing inputs - this can cause rapid electrical oscillations. To reliably sense switch events we must condition the input signal using a device called a schmitt trigger. A convenient device that contains these circuits is the 74LS14 hex inverter with schmitt trigger input stages. This device converts a slowly changing input to a sudden, sharp voltage change at a certain voltage level, very much as shown in Figure 6. The device also inverts the signal which means that a low input signal causes a high output signal, and a high input causes a low output. This means that we must now ground the input of the 74LS14 (pin 1) to cause a low-to-high transition as shown in Figure 6. |

Figure 7: practical debounce circuit i.e. should actually work
Here is what your breadboard would look like to implement the circuit of Fig. 7:
Figure 8: a reliable debounce circuit using a capacitor, resistors and 74LS14
The circuit of Figs.
|
|