source
pico_ada_c09_ad_converter
1.9.0Chapter 9: read the Pico ADC as counts, microvolts and fixed-point volts
1.9.0
Chapter 9 - AD Converter
Ada rewrite of the Freenove "AD Converter" lesson for the Raspberry Pi Pico.
The sketch on GP26 (ADC0) prints three representations of the same potentiometer on one UART line:
RP.ADC.Analog_Value- the 12-bit code (0 .. 4095)RP.ADC.Microvolts- that code scaled by the HAL with aFloatPico.Analog.Input.Volts- a 32-bit ordinary fixed-point subtype (delta 0.1 mV,'Small => 2**(-16)), converted from the count by multiply-first / divide-second
The chapter is the notes I needed before that line made sense:
- AGND and ADC_VREF are a filtered analogue pair, not a second isolated supply. ADC3 (VSYS/3) and ADC4 (the on-chip temperature sensor) are not available as general inputs.
- 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. Software
clamps those to
Volts'FirstandVolts'Last. Free_Runningplus a 2 HzPut_Lineleaves stale samples in the FIFO. The sketch usesOne_Shot.- The three columns are three conversions, not three formats of one sample. They may differ by a count or two.
Sketch_09_1_ADCisNo_Returnunder the Jorvik profile. The handler logs onAda.Text_IOand re-raises; the embedded runtime then halts. Fine for a sample you reset with BOOTSEL. SPARK would want an outer loop instead.
Built against rp2040_hal / the Pico BSP. Watch the UART with
CoolTerm (or any 115200 8N1 terminal).
Read the full tutorial at Chapter 9 - AD Converter: three ways to read a voltage, GNATdoc documentation, SourceForge repository