dac-waveform
Generate a sine wave on BOARD_DAC0 via a 32-point lookup table at a configurable sample rate, using <alp/dac.h>. Portable across families — BOARD_DAC0 resolves to the native Alif DAC12 on E1M (E1M-AEN801) and to the GD32-bridged DAC0 on E1M-X (V2N).
Source: examples/peripheral-io/dac-waveform/.
What it does
- Opens
BOARD_DAC0and parks it at mid-rail. - Steps a 32-point sine LUT out with
alp_dac_write_mv, pacing each step withalp_delay_usfor the requested sample rate. - Uses integer-only Q15 scaling (no FPU) and parks at mid-rail again before
close().
board.yaml
som:
sku: E1M-AEN801 # or an E1M-X V2N SKU — BOARD_DAC0 resolves per family
preset: e1m-evk
supported_boards:
- e1m-evk
- e1m-x-evk
cores:
a32_cluster:
os: "off"
m55_he:
app: ./src
peripherals:
- adc # as shipped in alp-sdk v0.17.0; the app drives the DAC
diagnostics:
log_level: info
The shipped board.yaml lists adc, not dac, under peripherals:. That looks like an SDK-side slip and is being confirmed upstream.
The default sine swings 0 to 3.3 V (mean 1650 mV, amplitude 1650 mV) at 3200 samples/s (32 points × 100 Hz). On E1M-AEN the analog outputs are referenced to 1V8, and DS-AEN-001 gives the DAC a 1 kHz sampling rate, so the default exceeds both. Lower SINE_DC_OFFSET_MV / SINE_AMPLITUDE_MV and SINE_FREQ_HZ in src/main.c before you rely on the output on E1M-AEN.
Expected output
A 32-step staircase sine approximation on the DAC pin, for 3 cycles. The console prints:
[dac] open BOARD_DAC0 (initial 1650 mV)
[dac] generating sine: freq=100 Hz, mean=1650 mV, ampl=1650 mV
[dac] cycle 0: peak=... mV trough=... mV
[dac] cycle 1: peak=... mV trough=... mV
[dac] cycle 2: peak=... mV trough=... mV
[dac] done
There is no per-step setpoint output.
See also
<alp/dac.h>aen-analog-validate— DAC0 → ADC loopback on E8