Chapter 9 – AD Converter: three ways to read a voltage

Hello everyone,

I have just published Chapter 9 of the Pi Ada Tutorial:

AD Converter – three ways to read a voltage

This is the Freenove potentiometer lesson in Ada. One sketch on GP26
prints the raw 12-bit code, the HAL’s integer microvolts, and a
fixed-point Volts type from Pico.Analog.Input on the same UART
line.

Highlights:

  • AGND / ADC_VREF — filtered analogue pair, not a second isolated
    supply. ADC3 (VSYS/3) and ADC4 (the on-chip temperature sensor) never
    appear on the header.
  • The RP2040 ADC has dead zones at both rails. On my board the floor
    sits around 19 counts (~15 mV) and the ceiling around 4081. You will
    not see 0 or 4095.
  • Pico.Analog.Input.Volts is a 32-bit ordinary fixed-point subtype
    (delta 0.1 mV, 'Small => 2**(-16)). Conversion is multiply first,
    then divide — no Float.
  • Free_Running plus a 2 Hz Put_Line left stale samples in the FIFO.
    The sketch uses One_Shot.
  • No_Return under Jorvik: the handler logs and re-raises, the
    embedded runtime halts. Fine for a sample you reset with BOOTSEL.
    SPARK would want an outer loop instead.

Full write-up:

Alire crate: pico_ada_c09_ad_converter (soon)

Source: https://sourceforge.net/p/pi-ada-tutorial/code/ci/master/tree/

As always, feedback and questions are very welcome.

Cheers,
Martin

5 Likes

Thanks for this.

Do you have a figure for the conversion time of the ADC?

(Quality external ADC’s have 10ms. Less expensive ones are 100ms)

1 Like

I looked it up in the RP2040 datasheet, and in Section 4.9.2 the conversion time is listed as 2 µs (96 cycles of the 48 MHz ADC clock)

2 Likes

That looks very fast. Thanks.