Created
April 27, 2020 14:12
-
-
Save nanase/869d7af3174d61fb480cc522ae8d5246 to your computer and use it in GitHub Desktop.
Sine wave output on Seeeduino XIAO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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