DAC Dithering: How can I enable and use it?

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
AidanHockey5
 
Posts: 1
Joined: Wed Mar 21, 2018 5:14 pm

DAC Dithering: How can I enable and use it?

Post by AidanHockey5 »

Hello,

I was taking a look at the SAMD51 family datasheet and noticed that the DAC features a dithering mode.
https://www.mouser.com/datasheet/2/268/ ... 130176.pdf

Page 1681.

I have an audio application that involves signed, 16-bit stereo WAV data being fed to the two DAC pins in 12-bit resolution mode. Right now, I'm simply using some bitshifting to map the 16-bit signed sample data to the 12-bit unsigned DAC registers, like so:

Code: Select all

void playWavSample()
{
    int16_t l = readBuf16(&wavStream);
    int16_t r = readBuf16(&wavStream);

    //16 bit signed to 12 bit unsigned conversion
     REG_DAC_DATA0 = ((l + 32768) >> 4); //Quickly write to the ADC A0   
     REG_DAC_DATA1 = ((r + 32768) >> 4); //Quickly write to the ADC A1 
}
I configure the DAC as follows before I run the above code:

Code: Select all

  analogWriteResolution(12);
  analogWrite(A0, 0);
  analogWrite(A1, 0);
This works well for quickly pushing samples to the DAC, but I can't help but wonder if I could improve my audio quality by applying a bit of dithering to the output.
After doing a little Googling, I haven't seen anything on how to utilize the built-in dithering feature. I'm pretty new to operating the DACs with lower level code, so I would really appreciate some insight or examples since I don't entirely understand what the datasheet is instructing me to do.

My preferred result would be allowing me to push 16-bit audio samples to the dithering register and have it output result to the DAC pins.

If it's possible to leverage this dithering function, I think it would be great for others to potentially improve their audio applications too! Thanks!

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

Return to “Metro, Metro Express, and Grand Central Boards”