← Back to the chapter · Next detail →

Technical detail · Microcontroller Programming: Setup and GPIO

Polling intervals and ADC resolution

A band-limited signal has no frequencies above a stated limit. Aliasing occurs when sampling makes a faster-changing signal appear to change at a different, lower frequency. The Nyquist frequency is half the sample rate; for a band-limited signal, its frequencies must lie below that limit to avoid aliasing. A brief button press is a separate event-coverage problem, so use the polling interval to judge whether it can be missed.

The mathematical gist. delay(250) checks the button every 250 ms, so it can miss a 100 ms press. Poll more often than every 100 ms; a 50 ms interval (20 checks per second) gives margin. For a band-limited sensor signal sampled every 250 ms, the sample rate is 4 Hz and the Nyquist frequency is 2 Hz. Separately, a 12-bit ADC over 3.3 V has 0.806 mV steps, which an LM35’s 10 mV/°C slope turns into 0.0806 °C per code.

← Back to the chapter · Next detail →