How to get working 12-bits resolution for ADC and DAC and sample rate on Due

Hello,

I start with Due and need highest resolution on both ADC and DAC.

How to miximize sampling rate/frequencies for ADC and DAC?

Last question - best method for transfer sampled data /on-line/ to PC on Windows for ADC; and setup DAC from PC?

Thank you.

what is miximize?
define what best is for you. It is a very personal qualifier, some think reliability is best other think speed
so ambiguous at best :wink:

If it is not reliable, it is not really good for much.
So, if using the library is slow or unreliable, is anybody
working on fixing the problems?

Writing code to control the ADC directly, what is needed to
get reliable, consistent reading, as fast as the hardware will
reliably do the A to DC?

Some have reported getting their conversion
working, and then report running other code
(seemingly unrelated) causes conversion errors.

Thanks for any education.

I used this code and tested it for now

//ADC - one chanel takes (approximately) 1us [1 microsecond]

void setup() {
//  Serial.begin(9600);
  SerialUSB.begin(115200); //...change it from the programming port to the native USB port; then ... SerialUSB.print(yourData);

  // change the resolution to 12 bits and read A0
  analogReadResolution(12);

  // change the PWM resolution to 12 bits
  // the full 12 bit resolution is only supported
  // on the Due
  //analogWriteResolution(12); //for direct access to DAC not needed
  // this is a cheat - enable the DAC
  analogWrite(DAC0,0);
  analogWrite(DAC1,0);
  
  int t=analogRead(0);

  ADC->ADC_MR |= 0x80; // these lines set free running mode on adc 7 and adc 6 (pin A0 and A1 - see Due Pinout Diagram thread)
  ADC->ADC_CR=2;
  ADC->ADC_CHER=0xC0; // this is (1<<7) | (1<<6) for adc 7 and adc 6
}

int N=1000;

void loop() {
  int t=micros();
  int q0=0,q1=0;
  int a0,a1,u0=0,u1=0;
  for(int i=0;i<N;i++){
    while((ADC->ADC_ISR & 0xC0)!=0xC0);// wait for two conversions (pin A0[7]  and A1[6])
    a0=ADC->ADC_CDR[7];              // read data on A0 pin
    a1=ADC->ADC_CDR[6];              // read data on A1 pin
    q0+=a0;
    q1+=a1;
    
    /*
    analogWrite(DAC0, 4095); //output voltage at value set to 0: 0.544V, 2048: 1.650V, 4095: 2.75V
    analogWrite(DAC1, 2048); //function analogWrite takes "longer (cca. 2-3 us / chanel)
    u0++;
    if(u0 > 4095) u0 = 0;
    u1++;
    if(u1 > 4095) u1 = 0;    
    */
    /* write to DAC0 */
    
    //direct access to registers of DAC, value is "always" 12bits, fastest way(?, hope so) (http://rcarduino.blogspot.sk/2012/12/arduino-due-dds-part-1-sinewaves-and.html)
    dacc_set_channel_selection(DACC_INTERFACE, 0);   
    dacc_write_conversion_data(DACC_INTERFACE, 2047);
    /* write to DAC1 */
    dacc_set_channel_selection(DACC_INTERFACE, 1);
    dacc_write_conversion_data(DACC_INTERFACE, 1024);
  }
  t=micros()-t;
  /*
  Serial.print("1000 pairs of ADC and DAC conversions in ");Serial.print(t);Serial.println(" micros");
  Serial.print("A0 total:");Serial.println(q0);
  Serial.print("A1 total:");Serial.println(q1);
  */
  SerialUSB.print(t); SerialUSB.println(" micros");
}