Arduino Due Dac configuration

Hello to all.
I want to use DAC to get a sin wavwform of 200KHZ!

I read this example

and the maximum waveform frequency is 170Hz.

I am new user of arduino. What settings of clock i have to do in order to get a waveform of 200HKZ?

I have seen that arduino due saw max sampling rate of 1Mhz.So for 1 period i can get 5 samples.
Is this true?
Thank you

Where did you get the 1MHz sample rate from? The raw DAC hardware takes 50 clock cycles
to convert.

The overheads of calling analogWrite will be a lot higher though.

Configuring the DAC to be timer triggered and feeding if from the DMA hardware
is the only reliable way to get high speed operation in the face of interrupts flying
about, and that's quite complex.

I've not programmed the DMA system yet but have got a 48kHz clocked timer and
interrupt generated stream going:

http://forum.arduino.cc/index.php?topic=205096.0

Hi,

I've been using the link in the previous reply as the basis of my wavetable based function generator project. I've got it working fairly well at 48kHz 12bit. It's even doing a linear interpolation between the samples as needed. But from my experience this is pretty much at the limit of what this hardware can do. I've had to really hand optimize my code to get all the necessary processing done within the clocked time period. I'm still trying to squeeze out more spare cycles to get the rest of my application to work nicely as well. It is not easy and getting something like 200kHz sounds like a day dream to me. Maybe with some clever use of the digital outputs instead and an external DAC but still I think it would be a challenge...

EDIT: Just realized it was you Mark who replied before me. Thanks a lot for your post in the link. Really helpfull!

An I2S DAC might be a possibility, some of them clock at 192kHz (WM8524 being
one example). Haven't tried directly interfacing one yet, there is hardware support,
the synchronous serial interface, but clocking might be an issue.

Thank you very much for your answers.
From the datashhet of SAM3X.
45.6.1 Digital-to-Analog Conversion
The DACC uses the master clock (MCK) divided by two to perform conversions. This clock is
named DACC Clock. Once a conversion starts the DACC takes 25 clock periods to provide the
analog result on the selected analog output.

Anyone knows what is the default MCK value?

If we choose prescaler 2 i suppose we can get very haig sampling rate.
Maybe if i cant make it i try to make a 200khz signal with PWM.

For the ad converter what is the max sampling rate that i can get?Can i go above 500ksample/sec?

Thank you very much again for your help

One option for generating high frequency signals would be to use one of these DDS chips. They usually have an SPI interface for microcontroller connection: http://www.analog.com/en/content/glp_dds/fca.html?gclid=CNPzoJDg3bwCFWLHtAod-TkAzw

As a reference, here a BareMinimum sketch that generates a decent 1.4kHz sinewave (120 samples) using DUE's DAC1.

int i = 0;
void setup() {
  analogWriteResolution(12);
}

static int sine[] = {
    0x7ff, 0x86a, 0x8d5, 0x93f, 0x9a9, 0xa11, 0xa78, 0xadd, 0xb40, 0xba1,
    0xbff, 0xc5a, 0xcb2, 0xd08, 0xd59, 0xda7, 0xdf1, 0xe36, 0xe77, 0xeb4,
    0xeec, 0xf1f, 0xf4d, 0xf77, 0xf9a, 0xfb9, 0xfd2, 0xfe5, 0xff3, 0xffc,
    0xfff, 0xffc, 0xff3, 0xfe5, 0xfd2, 0xfb9, 0xf9a, 0xf77, 0xf4d, 0xf1f,
    0xeec, 0xeb4, 0xe77, 0xe36, 0xdf1, 0xda7, 0xd59, 0xd08, 0xcb2, 0xc5a,
    0xbff, 0xba1, 0xb40, 0xadd, 0xa78, 0xa11, 0x9a9, 0x93f, 0x8d5, 0x86a,
    0x7ff, 0x794, 0x729, 0x6bf, 0x655, 0x5ed, 0x586, 0x521, 0x4be, 0x45d,
    0x3ff, 0x3a4, 0x34c, 0x2f6, 0x2a5, 0x257, 0x20d, 0x1c8, 0x187, 0x14a,
    0x112, 0xdf, 0xb1, 0x87, 0x64, 0x45, 0x2c, 0x19, 0xb, 0x2,
    0x0, 0x2, 0xb, 0x19, 0x2c, 0x45, 0x64, 0x87, 0xb1, 0xdf,
    0x112, 0x14a, 0x187, 0x1c8, 0x20d, 0x257, 0x2a5, 0x2f6, 0x34c, 0x3a4,
    0x3ff, 0x45d, 0x4be, 0x521, 0x586, 0x5ed, 0x655, 0x6bf, 0x729, 0x794
};

void loop() {
  analogWrite(DAC1, sine[i]);
  i++;
  if(i == 120)
    i = 0;
}

Regards, palliser

giogiannis:
Anyone knows what is the default MCK value?

The Due is clocked at 84MHz, this is explained on the Due page and isn't hard to look up!

I think the key fact that giogiannis has overlooked is that to reconstruct a sine wave using the DAC, in the examples referenced above, it takes 120 conversions (i.e. 120 data points) to reconstruct one complete cycle of the waveform. If the DAC uses the the MCK divided by two, and the DAC requires 25 clock periods for one conversion, and there are 120 conversions in one cycle, by my calculation, the theoretical maximum frequency sinewave the DAC could put out would be 14 KHz. Allowing for the processor overhead to increment counters, read values from memory, and send them to the DAC, a frequency of 1.4KHz as demonstrated by palliser sounds entirely reasonable. You could push this a bit higher by reducing the number of points you use to reconstruct the wave, but cutting the number of points in half will only get you a 2.8 KHz maximum. I agree with kbrown, you need to use a dedicated chip to get high frequencies, not a general purpose microprocessor.

bgentles:
I think the key fact that giogiannis has overlooked is that to reconstruct a sine wave using the DAC, in the examples referenced above, it takes 120 conversions (i.e. 120 data points) to reconstruct one complete cycle of the waveform. If the DAC uses the the MCK divided by two, and the DAC requires 25 clock periods for one conversion, and there are 120 conversions in one cycle, by my calculation, the theoretical maximum frequency sinewave the DAC could put out would be 14 KHz. Allowing for the processor overhead to increment counters, read values from memory, and send them to the DAC, a frequency of 1.4KHz as demonstrated by palliser sounds entirely reasonable. You could push this a bit higher by reducing the number of points you use to reconstruct the wave, but cutting the number of points in half will only get you a 2.8 KHz maximum. I agree with kbrown, you need to use a dedicated chip to get high frequencies, not a general purpose microprocessor.

For higher frequencies you'd use DDS and a similar table lookup - can go up towards the
Nyquist limit then, given a good analog output filter.

Direct digital synthesis is basically:

while (true)
{
  phase += frequency ;
  output (sine_table [phase >> shift]) ;
  delayMicroseconds (sample_period) ;
}

Just posted my take on a Due based function generator. See here.