Skip to main content

adc-voltmeter

Single-shot ADC sample on the E1M EVK's Arduino A1 input (E1M pad class ADC1), read in microvolts. The minimal demo for <alp/adc.h>.

Source: examples/peripheral-io/adc-voltmeter/.

board.yaml​

som:
sku: E1M-AEN801

preset: e1m-evk

pins:
- { e1m: E1M_ADC1, macro: EVK_ADC_ARDUINO_A1, doc: "Arduino UNO header A1 analog input" }

cores:
m55_hp:
app: ./src
peripherals: [adc]

diagnostics:
log_level: info

Source (abbreviated)​

#include <stdio.h>

#include "alp/adc.h"
#include "alp/peripheral.h"
#include "alp/boards/alp_e1m_evk_routes.h"

int main(void) {
(void)alp_init();

alp_adc_t *adc = alp_adc_open(&(alp_adc_config_t){
.channel_id = EVK_ADC_ARDUINO_A1,
.resolution_bits = 12,
.reference = ALP_ADC_REF_INTERNAL,
});
if (adc == NULL) {
printf("[adc] open failed: alp_last_error=%d\n", (int)alp_last_error());
return 0;
}

int32_t uv = 0;
alp_status_t s = alp_adc_read_uv(adc, &uv);
printf("[adc] read_uv -> status=%d, uv=%d\n", (int)s, (int)uv);

alp_adc_close(adc);
return 0;
}

Expected output​

[adc] read_uv -> status=0, uv=<input voltage in µV>

alp_adc_read_uv() converts against the module's own ADC reference. On E1M-AEN the analog inputs are referenced to 1.8 V (DS-AEN-001), so the input range is 0 V to 1.8 V. Code that scales raw codes itself must use that reference, not 3.3 V.

Capability validation​

Asking for a resolution above the SoC's ALP_SOC_ADC_MAX_RESOLUTION_BITS fails at _open(). On E1M-AEN (Alif E8) that maximum is 24 bits, so a 16-bit request passes the gate; the example uses a deliberately unreasonable 100 bits:

alp_adc_t *bad = alp_adc_open(&(alp_adc_config_t){
.channel_id = EVK_ADC_ARDUINO_A1,
.resolution_bits = 100, /* deliberately unreasonable */
.reference = ALP_ADC_REF_INTERNAL,
});
// bad == NULL, alp_last_error() == ALP_ERR_OUT_OF_RANGE
// (ALP_ERR_NOT_READY under the permissive no-SoC default, e.g. native_sim)

See also​

Questions about this page? Email contact@alplab.ai