Skip to content

Instantly share code, notes, and snippets.

@nanase
Created April 27, 2020 14:12
Show Gist options
  • Save nanase/869d7af3174d61fb480cc522ae8d5246 to your computer and use it in GitHub Desktop.
Save nanase/869d7af3174d61fb480cc522ae8d5246 to your computer and use it in GitHub Desktop.
Sine wave output on Seeeduino XIAO
#define MAX_VALUE ((1 << 10) - 1)
#define SIN_MAX (MAX_VALUE / 2.0)
void setup() {
DAC->CTRLA.bit.ENABLE = 0x01;
syncDAC();
}
double i = 0.0;
void loop() {
for (uint16_t k = 0; k < 1024 * 4; k++) {
DAC->DATA.reg = (uint32_t)(SIN_MAX * sin(i) + SIN_MAX);
i += 0.0005;
}
}
void syncDAC() {
while (DAC->STATUS.bit.SYNCBUSY == 1) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment