Tutorials

Separate RP2040 Round-Robin ADC Samples Without Losing Channel Order

Published · Updated

A DMA capture of two analogue inputs contains a stream of codes. Labelling every even entry as channel 0 works only while software knows the initial channel and the stream has no lost entries.

Anchor the channel sequence at the start of each capture

Oscilloscope probes on a populated PCB. Probe loading and the ground return matter when comparing the rail and its reference.
Oscilloscope probes on a populated PCB. Probe loading and the ground return matter when comparing the rail and its reference. Sensepeek AB (Wikimedia Commons), CC BY-SA 4.0. Site-sized copy.

On an RP2040 choose the AINSEL starting input and the round-robin mask deliberately. Stop the previous run, allow an in-progress conversion to finish and drain stale FIFO samples before arming the new capture. The conversion FIFO does not attach a channel number to each reading.

Preserve the selected channels, the expected sequence and overflow status with the block. A single missing result can change the interpretation of every later sample.

Check ADC divider loading and settling · Trace sample order in a multichannel capture

Account for the time between two channels

All conversions / 10 µs / 100 kS/s; One of two channels / 20 µs / 50 kS/s; Time offset within a pair / 10 µs / Sequential sampling
View of the stream / Interval / Rate.

Assume an aggregate conversion rate of 100 kS/s with two channels visited alternately. Adjacent entries are nominally 10 µs apart. Each individual channel appears every 20 µs, or 50 kS/s.

Treating adjacent entries as simultaneous can give the wrong phase or instantaneous power for rapidly changing signals. During bring-up, apply a stable, in-range voltage to one input and ground the other through the intended input network. A repeating pair of distinct codes makes a swapped phase or stale first result easy to see.

Can an overflow be fixed by deleting the first sample in software?

That does not reveal how many samples were lost or which channel they represented. Mark the block invalid and restart from a known sequence when channel identity matters.

Read the example one step at a timeAll conversions / 10 µs / 100 kS/s; One of two channels / 20 µs / 50 kS/s; Time offset within a pair / 10 µs / Sequential sampling
  1. All conversions · 10 µs · 100 kS/s
  2. One of two channels · 20 µs · 50 kS/s
  3. Time offset within a pair · 10 µs · Sequential sampling

Budget FIFO capacity during a service stall · Allow the ADC input to settle

Look for missed trigger edges.

Raspberry Pi RP2040 Datasheet, 4.9 ADC and temperature sensor.

Photograph credit and licence

Sensepeek AB (Wikimedia Commons), CC BY-SA 4.0. Site-sized copy.

Original photograph https://commons.wikimedia.org/wiki/File:PCBite_handsfree_oscilloscope_probes_measuring_a_circuit_board.jpg

Licence https://creativecommons.org/licenses/by-sa/4.0

Back to Tutorials

Related evidence and next tasks

Continue the task with the relevant source scope. These reading paths do not establish interchangeability or current supply.

Source addresses and citation trail

Full source addresses are retained below. Read each citation with its document revision, page, table and applicability conditions above.

  1. https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf#page=535