Lessons and the learning game

Build a pocket oscilloscope

An oscilloscope from an Uno, its ADC and a 2.4 inch TFT, honest about where it stops.

The finished scope

Build a pocket oscilloscope runs every lesson on the same wiring:

  • The sampler: an Arduino Uno. Its ADC, set free running at a prescaler of 16, takes a sample every 13 us: 76,923 a second.
  • CH1: a bench function generator on A0, 0 to 5 V. Change its wave, frequency, amplitude and duty in its properties.
  • CH2: a 555 timer astable on the breadboard, on A1, with R1 = R2 = 10 k and C = 100 nF: 481 Hz at 67 percent on paper.
  • The controls: three buttons, TIME, TRIG and CH.
  • The screen: an ILI9341, 320 by 240 in landscape.

The catalog card names an ESP32. The course builds on the Uno, whose ADC registers are simple enough to drive by hand and fast enough for audio.

How it works

Sampling. analogRead() takes about 108 us. Writing the ADC's registers directly (ADPS for the prescaler, ADATE for free running, ADLAR so ADCH holds the top 8 bits) brings that to 13 us. A 1 MHz ADC clock is above the 200 kHz the datasheet rates for full accuracy, so only 8 bits are kept: 19.6 mV a step.

Triggering. Each capture is 500 samples, twice the 250 the screen shows. The trigger is the first place the signal rises through the level, and the screen starts there, so the trace stands still. With no crossing it shows the capture anyway, like a scope's auto mode.

Scales. A division is 25 samples, so the prescalers make 0.33, 0.65, 1.3 and 2.6 ms a division. Up the screen it is 1 V a division, or 0.5 V zoomed.

Measurements. Frequency is whole cycles between rising crossings of the middle level, with a band of hysteresis, over the time they span. Duty is the share above the middle; Vpp the highest sample minus the lowest. On the screen they are averaged over a second.

Drawing. There is no SPI hardware on Mokxi's ATmega, so pixels go out by hand at about fifty thousand a second. The graticule is drawn once, and each frame repaints only the columns where the trace moved.

The limits

It cannot see above the 38 kHz Nyquist limit, and needs about ten samples a cycle to show a shape. Its input is the ATmega's pin, 0 to 5 V and nothing outside it. A real scope has a front end: an anti-alias filter, an attenuator and amplifier, input protection, a 1 Mohm input and AC coupling.

The course

  1. Fast sampling: analogRead against free running, and Nyquist.
  2. Triggering: rolling frames, a rising-edge trigger, its level, and no trigger at all.
  3. Time and volt scales: timebases from the prescaler, a zoom, and the smallest step.
  4. Measurements: frequency, duty and peak to peak from the samples.
  5. A display: a graticule and a trace that repaints only what moved.
  6. Project: probe a 555: measure it, check it against the formula, change a resistor, and predict before you measure.

Every checked step is tested against the running circuit.