Course materials · Microprocessor Applications

GPIO

English translation

Use timestamped records to examine multiple signals from a single button press, and define input handling rules.

Before practice

01 Does one button press mean one signal?

Description

Contact bounce can produce several recorded changes in a short time.

02 Do polling intervals and debounce times serve the same role?

Description

Polling is the observation interval; debounce is a rule for grouping closely spaced changes into one.

Execution conditions

Use the recorded waveform for the baseline exercise. For the hardware extension, compare the BCM numbers and input/output settings in the original RPi.GPIO code with the board you use.

Practice

Preview practice notebookDownload practice notebook

1. GPIO Edge Detection

Starting conditions

(t_ms,level)=[(0,0),(10,1),(12,0),(14,1),(50,0),(80,1)]. Between records, the preceding level is maintained.

Procedure

  1. Reconstruct 0~100 ms at 1 ms intervals and draw a step plot.
  2. Find the times of the rising and falling edges in the original record.
  3. Record the cumulative count with only rising edges counted by the counter.

Results to retain

Items to record and points to check
t [ms]
level
Edge type
Cumulative rising count

Points to check

  • Did you avoid counting the initial level as a transition?
  • Do repeated readings of the same level avoid being counted as new edges?

2. Effects of polling intervals

Starting conditions

Read the same waveform at Δt∈{1,10,20}\Delta t\in\{1,10,20\} ms intervals. Keep the original edge record unchanged.

Procedure

  1. At each polling time, read the level of the preceding event.
  2. Recount rising edges in the sampled data and compare with the original record.
  3. Identify the actual intervals of the short pulses that disappeared.

Results to retain

Items to record and points to check
Polling interval [ms]
Number of samples
Detected rising count
Missed intervals

Points to check

  • Did you change only the sampling interval while keeping the original waveform fixed?
  • Did you distinguish event times from the times they were detected by polling?

3. Filter contact bounce

Starting conditions

Set the minimum accepted interval between rising edges to 20 ms. Evaluate each edge relative to the last accepted edge.

Procedure

  1. From the raw rising list, ignore subsequent edges less than 20 ms apart.
  2. Change the limit to 5,20,50 ms and compare the number of accepted edges.
  3. Read the GPIO.setmode and time.sleep arguments in Week6-1_GPIO_LED_Test.ipynb, and explain how its pin numbering scheme and time units relate to this activity's records. Complete this by reading the code only.

Results to retain

Items to record and points to check
Minimum interval [ms]
raw count
Accepted count
Accepted times [ms]

Points to check

  • Do discarded edges leave the last accepted time unchanged?
  • Did you distinguish BCM numbers from the board's physical pin numbers?