-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDAC_Sine_wave.ino
38 lines (30 loc) · 1.2 KB
/
DAC_Sine_wave.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// This example outputs a 32KHz sine wave on A12/DAC1.
#include <Arduino_AdvancedAnalog.h>
AdvancedDAC dac1(A12);
uint16_t lut[] = {
0x0800,0x08c8,0x098f,0x0a52,0x0b0f,0x0bc5,0x0c71,0x0d12,0x0da7,0x0e2e,0x0ea6,0x0f0d,0x0f63,0x0fa7,0x0fd8,0x0ff5,
0x0fff,0x0ff5,0x0fd8,0x0fa7,0x0f63,0x0f0d,0x0ea6,0x0e2e,0x0da7,0x0d12,0x0c71,0x0bc5,0x0b0f,0x0a52,0x098f,0x08c8,
0x0800,0x0737,0x0670,0x05ad,0x04f0,0x043a,0x038e,0x02ed,0x0258,0x01d1,0x0159,0x00f2,0x009c,0x0058,0x0027,0x000a,
0x0000,0x000a,0x0027,0x0058,0x009c,0x00f2,0x0159,0x01d1,0x0258,0x02ed,0x038e,0x043a,0x04f0,0x05ad,0x0670,0x0737
};
static size_t lut_size = sizeof(lut) / sizeof(lut[0]);
void setup() {
Serial.begin(9600);
if (!dac1.begin(AN_RESOLUTION_12, 32000 * lut_size, 64, 128)) {
Serial.println("Failed to start DAC1 !");
while (1);
}
}
void loop() {
static size_t lut_offs = 0;
if (dac1.available()) {
// Get a free buffer for writing.
SampleBuffer buf = dac1.dequeue();
// Write data to buffer.
for (size_t i=0; i<buf.size(); i++, lut_offs++) {
buf[i] = lut[lut_offs % lut_size];
}
// Write the buffer to DAC.
dac1.write(buf);
}
}