Skip to main content

Subsection 2.4.1 Part 1: Observing and Fixing Bounce

We’ll start by watching the button. Load button.c onto your Nucleo, or your own toggleLED.c if you finished the homework. We want to see the button’s signal and the signal of the LED your program toggles on the oscilloscope at the same time. Look at your breadboard. Before you connect the AD2, discuss at your table which point in your circuit each probe should touch, and where the minus leads connect, and why. Put the button on CH1 and that LED on CH2. Then check your plan against Figure 2.4.1 and wire the AD2.
Figure 2.4.1. AD2 wiring for observing button bounce. CH1 (orange) touches the button’s signal row, CH2 (blue) touches the LED’s row, and the minus leads (white stripe) go to the GND rail.

Activity 2.4.1. Capturing Switch Bounce.

(a)

In Waveforms, configure the trigger as shown in Figure 2.4.2: Source: Channel 1, Type: Edge, Condition: Falling, Level: 1 V. Set the time base to 20 µs/div. (Depending on your Waveforms version, you may need Normal or Auto trigger mode.)
Figure 2.4.2. Waveforms trigger settings for capturing switch bounce. Source: Channel 1 (button signal), Condition: Falling edge, Level: 1 V. Time base 20 µs/div is a good starting point; adjust if your bounce is shorter or longer.
Click Single, press the button once, and examine the captured waveform. What do you see instead of a clean falling edge?

(b)

Use cursors to measure the total duration of the bounce on your button. Compare results with other students. Do all switches bounce the same amount?

(c)

Look at channel 2 (LED). How many times does the LED change state during a single physical button press? Why?
Figure 2.4.3. CH1 (orange) shows the button and CH2 (blue) shows the LED. Switch bounce captured on CH1: a single button press produces many rapid HIGH/LOW transitions before the signal settles low. CH2 shows the LED toggling on each bounce, not just once. Bounce duration varies by switch, typically 50 µs to a few ms.
Now we’ll try the analog fix: a small capacitor across the switch. The circuit and the arithmetic behind it are written out in Subsection 2.5.1; here we’ll just fit the part and look at what it does to the trace.

Activity 2.4.2. Hardware Fix: Adding a Capacitor.

In Lab 2’s Technical Study you learn how to select an appropriately sized capacitor for a given switch. For today the 0.1 µF or 0.15 µF capacitor works well.
Figure 2.4.4. Reading metal film capacitor markings. The three fields encode value, tolerance, and maximum voltage. Value is two digits and a decimal point; the decimal point can be an n (nano), a p (pico), or a dot (micro). Example: .1J63 = 0.1 µF, ±5%, 63 V. The two photographs are what the part looks like in your kit: a small squared-off block with two legs, in blue or cream depending on the manufacturer, with the marking printed on the flat face.
Figure 2.4.5. Place the debounce capacitor (0.1 µF or 0.15 µF, depending on how your kit was stocked) from D5 (PB4) to GND on the breadboard, in parallel with the button. The red dashed line shows where the capacitor connects. Identify the correct capacitor by reading its marking code (Task 1 below).

(b)

Place the capacitor across the button (one leg on the GPIO pin side, the other to GND). Capture the button waveform again with the same scope settings. How has it changed?

(c)

Look at channel 2 (LED) again. Does the LED now toggle exactly once per press? Save a screenshot showing both channels, with and without the capacitor, for your lab report.
Figure 2.4.7. Button waveform with vs. without the debounce capacitor.
Figure 2.4.9. The internal pull-up and the debounce capacitor form an RC low-pass filter.