Achieving 1MS/s on SAMD51 DAC?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The SAMD51 DAC is supposed to do 1M conversions/second.  What exactly do you need to do to actually achieve that, or anything close to that?

 

the Clock should be set to 12MHz, and I have a loop: while (1) {

    for (int i = 0; i < 4096; i += 1) {
      DAC->DATA[0].reg = i;
      while (!DAC->STATUS.bit.EOC0) // wait for conversion
        ;
    }
  }

So 4096 steps, at 24 clocks for each conversion.   Inconsequential amount of looping code (at 120MHz), so it should be totally timed by the DAC itself, and should give me a waveform with a frequency of about 122Hz, right?  (12e6/(3096*24))

I'm getting a nice sawtooth at about 12Hz; 1/10th of expected frequency!

 

But even if that was "working", it would only be doing 500k conversions/s (24 clocks at 12MHz.)   It says in the datasheet that I can load a new DATA value after only 12 clocks, but ... I don't see any status bits that would tell me when those 12 clocks have elapsed?

 

There's a double buffer, but I can't see how get it to be used without using the event system?  Is that the solution - you MUST use the event system to have the DAC trigger automatic loads from the buffered value?  And I could check... interrupt bits (even if they're not enabled) to see if I can put new data in the buffered value?  It just seems ... weird; like a lot of info that should be status bits just isn't present.

 

The Datasheet has a READY status bit for each DAC, but doesn't really describe what it means.  It says "startup time has elapsed", which elsewhere is described as an initialization thing, rather than a between-coversions thing...

 

Most of the samples of other code I've seen online are for providing slow-changing outputs :-(

 

Last Edited: Sun. Mar 17, 2019 - 05:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So most of my inability to get the speed I expect turned out to be a mis-configured GCLK (DIVSEL set wrong, causing 48MHz/2**(4+1) instead of 48MHz/4)

I'm still off by a factor of a little more than 2 (getting a 95Hz sawtooth instead of 220+Hz), and I still don't understand how to tell when the 12 cycles have passed...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try using the DMA mode. The DMA will automatically load the next value when the conversion is complete without any processor overhead. Just link the DMA descriptor back on itself and it will run forever.