Arduino UNO R4 DAC speed

My understanding of the R4 DAC is that it is a genuine Analogue output on A0 with a resolution of (up to ) 12 bits. Can anyone tell me how fast you can write to it? To be clear, if I write one value, then another value in a continous loop without any delay between instructions what is the frequency of the corresponding square wave ?

It seem to me that this must be important to lots of people but I can't find any mention of it. To be clear, I'm not wanting to use any kind of pre-programmed wave output, just two selected values. I'm concerned that the ESP32 may be surprisingly slow and the ESP32 boards seem to be limited to two 8 bit DACs

You could write a program just as you described, alternating between high and low output on each iteration of the main loop. Then read the output on an oscilloscope.

Using the following code:

void setup()
{
  analogWriteResolution(12);
}
void loop()
{
  noInterrupts();
  analogWrite(A0,4095);
  analogWrite(A0,0);
  analogWrite(A0,4095);
  analogWrite(A0,0);
  analogWrite(A0,4095);
  analogWrite(A0,0);
  interrupts();
  delayMicroseconds(100);
}

The frequency of the 'squarewave' is just under 52kHz.

Many thanks to you both. I don't have a UNO R4 yet, so I was asking to find out if it's worth buying for an audio application. I checked in a similar way for a Seeeduino XIAO but including analogRead() between each DAC output and got 31kHz, albeit at only 10 bit resolution. The read pins were connected at the nodes of three resistors between ground and 3.3V

void loop() {
A = analogRead(A7);
analogWrite(A0,A);
B = analogRead(A8);
analogWrite(A0,B);
}

I favour the 12 bit DAC but I'm now wondering if the analogRead() would take longer so maybe the UNO R4 is actually slower...

The ESP32 boards should be faster but I watched a video showing a sine wave output from a lookup table and it was surprisingly slow and with all that power it only has DACs with 8 bit resolution, albeit two of them

Consider whether you are better off using an external DAC like the PT8211 for example.

Looks nice. Strictly, I don't need two channels, but the clock rate looks good so I'm now wondering how fast the Arduino UNO R4 can clock - probably not 18.4 MHz?

Arduino UNO R4 should also be able to communicate faster. But why? You said you need it for an audio application, and you're unlikely to need that high a frequency. If you don't need 2 channels just use one, still these chips are quite cheap.

Fair point, I’ll give it a try, thanks for the suggestion

According to the RA4M1 data-sheet the DAC12 conversion time is 30uS to reach specified accuracy... although the 'scope shows this as being faster.

Using the Arduino IDE calls:

A = analogRead(A1);  // This takes c. 21uS

analogWrite(A0, A);   // This takes c. 10uS for the code and 5uS (max) for the DAC output to change.

Doing direct register operations:

analog_read_value = *ADC140_ADDR00;    // Internal 16bit register read 
*ADC140_ADCSR |= (0x01 << 15);         // Write to register to start next ADC conversion 
// ADC total time =  290nS
*DAC12_DADR0 = analog_read_value;      // Write to DAC takes 166nS

Doing direct register operations and allowing for minimum visual 'scope settling time of the DAC output (alternating min/max) I am getting a 599.2kHz loop frequency.

Brilliant, thank you. I’ll get an R4 and have a go at this. I can imagine this will be of interest to others :+1:

1 Like

I have put the code up on GitHub:

https://github.com/TriodeGirl/Arduino-UNO-R4-Minima-Fast-DAC/tree/main

The steps in the above 'scope trace clearly shows the DAC change times.

If one comments out the #define SINE_DAC in the code then one gets this example of MIN to MAX, etc. at min or max directly from the ADC values.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.