dac-onde.ino

Arduino Due · File : dac-onde.ino · Language : Arduino · Use case : Générer une onde sinusoïdale analogique sur la vraie sortie DAC

Unlike AVR Arduinos, the Due has two true 12-bit DAC outputs: the sine wave comes out straight, no filter or PWM. On a scope you see a clean curve centered at 1.65 V.

Hardware required

An Arduino Due (AT91SAM3X8E, ARM Cortex-M3 at 84 MHz) connected over USB to its « Programming » port. Caution: 3.3 V logic, never 5 V on the pins. Oscilloscope (or amp + speaker via capacitor).

Wiring

Probe on pin A0 (DAC0), ground to GND.

How it works

analogWrite(DAC0, v) drives the 12-bit DACC (0-3.3 V); the 64-point table is replayed in an open loop. In the Arduino IDE, select « Arduino Due (Programming Port) » then Upload; the serial monitor runs at the speed set in the code.

Going further

A second output on DAC1 (A1) in quadrature for stereo, or a bigger table for a cleaner wave.

dac-onde.ino

// Onde sinus sur DAC0 (broche A0) : la Due a un vrai convertisseur.
const int DAC = DAC0; // broche A0
const int N = 64;     // points de la table

float sinus(int i) {
  return 2048.0 + 2047.0 * sin(2.0 * PI * i / N);
}

void setup() {
  analogWriteResolution(12); // 0..4095 sur la DAC
}

void loop() {
  for (int i = 0; i < N; i++) {
    analogWrite(DAC, (int)sinus(i));
    delayMicroseconds(100); // frequence ~ 1/(64*100us) = 156 Hz
  }
}

← Back to the board