Skip to main content

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​

  1. Opens BOARD_DAC0 and parks it at mid-rail.
  2. Steps a 32-point sine LUT out with alp_dac_write_mv, pacing each step with alp_delay_us for the requested sample rate.
  3. 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.

E1M-AEN: the default waveform exceeds the DAC's range and rate

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​

Questions about this page? Email contact@alplab.ai