fixed-point sine function able send to DAC at 291 kHz.

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ericfont
 
Posts: 4
Joined: Wed Jul 27, 2022 8:33 pm

fixed-point sine function able send to DAC at 291 kHz.

Post by ericfont »

I just wanted to share a quick investigation I did today to see how fast I could output sine waves on the Trinket M0+. Since the core doesn't have floating point hardware, doing a floating-point sin() function and outputting to the DAC took a long time (72,374 ns per sample...a rate of 13.8 kHz). However since the DAC is only 10-bit int anyway, integer sine if sufficient. I first tried a lookup table which could output very fast (2,346 ns per sample...a rate of 426 kHz). That lookup was only a couple CPU clock cycles per sample slower than simply outputting a sawtooth because of the memory access...but the big downside is I spent one-third of the available storage simply to put my 32,768-entry lookup table. So then I tried looking for some quick integer function calls, and I tried someone's (Andrew Steadman https://www.nullhardware.com/blog/fixed ... ed-systems) 13-bit fixed-point sine function which could take 15-bit input angles, which was able to output to the DAC at quite fast (3,437 ns per sample...a rate of 291 kHz per sample) which was only about 63 clock cycles slower than the lookup table. That's sufficiently faster than the 40 kHz necessary to reproduce highest audio sinewave and still have plenty to spare to do other things on the core. Just thought I would share for anyone curious. My test/benchmarking code is https://gist.github.com/ericfont/847ce9 ... 508e926a0f

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”