DUE PWM controller COMPARISON UNIT based ADC and DAC synchronization.

Thanks for the help.

I made my own code file. I want to use the DACC in tag mode for the present code example. What are the modification should I make.

[
void setup() 
{
  ADC_setup();
  DAC_setup();
  TC_setup();
}

void loop() 
{
  // Do nothing.
}

void ADC_setup(void)
{
  pmc_set_writeprotect(false);            // PMC controller write protection disable.
  PMC->PMC_PCER1 |= (PMC_PCER1_PID37);    // power on of the ADC module
  ADC->ADC_CR     = (ADC_CR_SWRST);       // Reset of ADC.
  ADC->ADC_IDR    = (0xFFFFFFFF) ;        // disabling the interrupts.
  ADC->ADC_IER    = (ADC_IER_EOC7);       // enabling the EOC interrupt of the channel-6.
  ADC->ADC_MR    |= (ADC_MR_TRGEN_EN)|
                    (ADC_MR_TRGSEL_ADC_TRIG1);  // ADC Trigger setting TIOA of TIMER/COUNTER channel-0.
  ADC->ADC_CHER   = (ADC_CHER_CH6)|       // Selecting the Channel-6
                    (ADC_CHER_CH7);       // Selecting the channel-7 for the conversion.
  ADC->ADC_CR     = (ADC_CR_START);       // Starting the ADC module
  NVIC_EnableIRQ(ADC_IRQn);               // Enabling the ADC interrut handler in NVIC. 
}

void TC_setup(void)
{
  pmc_enable_periph_clk(ID_TC0);             // Power on the TC0 peripheral.
  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKDIS; // disabling the internal clock while setting the registers.
  TC0->TC_CHANNEL[0].TC_IDR = 0xFFFFFFFF;    // disabling the interrupts (Actually there are eight different interrupts available for each channel).
  TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 |
                              TC_CMR_WAVE |
                              TC_CMR_WAVSEL_UP_RC |
                              TC_CMR_ACPA_CLEAR | 
                              TC_CMR_ACPC_CLEAR ;
  TC0->TC_CHANNEL[0].TC_RC = 830;            // The Triggering frequency selected is 50KHz for ADC and DACC modules.
  TC0->TC_CHANNEL[0].TC_RA = 300;
  TC0->TC_CHANNEL[0].TC_CMR = ((TC0->TC_CHANNEL[0].TC_CMR) & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET ;
  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG ;
  
  // This part of the code is to check the sampling frequency in Arduino DUE pin.
  PIOB->PIO_WPMR   = 0x50494F00;                // disabling the write protect registers for PIOB Peripheral controller.
  PIOB->PIO_PDR    = PIO_PB25B_TIOA0 ;          // disable PIO control.
  PIOB->PIO_IDR    = PIO_PB25B_TIOA0 ;          // disable PIO interrupts.
  PIOB->PIO_ABSR  |= PIO_PB25B_TIOA0 ;          // switch to B peripheral.
}

void DAC_setup(void)
{
  PMC->PMC_PCER1  |= (PMC_PCER1_PID38);          // Power on for the DACC peripheral.
  DACC->DACC_CR    = (DACC_CR_SWRST);            // Resetting the DAC.
  DACC->DACC_MR   |= (DACC_MR_TRGEN_EN)|
                     (DACC_MR_TRGSEL(1))|        // Selecting TIOA as the trigger.
                     (DACC_MR_WORD_HALF)|        // Enabling Halg word transfer.
                     (DACC_MR_USER_SEL_CHANNEL0)|
                     (DACC_MR_REFRESH(5))|
                     (DACC_MR_STARTUP_16);
  DACC->DACC_IDR   = 0xFFFFFFFF ;
  DACC->DACC_CHER |= DACC_CHER_CH0;
}

void dac_write (int val)
{
  DACC->DACC_CDR = val & 0xFFF ;
}

void ADC_Handler (void)
{
  if (ADC->ADC_ISR & ADC_ISR_EOC7)   // ensure there was an End-of-Conversion and we read the ISR reg.
  {
    int V = *(ADC->ADC_CDR+7) ;
    int U = *(ADC->ADC_CDR+6) ;    
    dac_write (0xFFF & (V - U)) ;       // copy inverted to DAC output FIFO.
  }
}

//]