Arduino Due ADC triggered by PWM event line

Can someone tell me where I am going wrong in this implementation of trying to trigger the ADC using PWM ch3 event line 1? I cannot see the ADC being called at all. I tried this with PWM channel 0 as well.

void pwm_setup () {
  uint32_t PERIOD_VALUE = 4200;
  // Set the PWM Reference channel 0 i.e. : Clock/Frequency/Alignment
  PWM->PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(2);       // Set the PWM clock rate
  PWM->PWM_CH_NUM[3].PWM_CMR = PWM_CMR_CPRE_CLKA;               
  PWM->PWM_CH_NUM[3].PWM_CPRD = PERIOD_VALUE;

  PWM->PWM_CMP[3].PWM_CMPV = PWM_CMPV_CV(PERIOD_VALUE / 2);   
  PWM->PWM_CMP[3].PWM_CMPM = PWM_CMPM_CEN;                     // Comparison enable

  PWM->PWM_ELMR[1] = PWM_ELMR_CSEL3;                          

  PWM->PWM_ENA = PWM_ENA_CHID3;                                // Fire !!

}

//******************* ADC SETUP ***********************//
 void adc_setup(){
  PMC->PMC_PCER1 |= PMC_PCER1_PID37;  //Turn ADC on
  ADC->ADC_CR = ADC_CR_SWRST;         //Reset ADC
  ADC->ADC_MR |= ADC_MR_TRGEN_EN | ADC_MR_TRGSEL_ADC_TRIG5; 
  
  ADC->ADC_CHER = ADC_CHER_CH7|ADC_CHER_CH13;
  ADC->ADC_IER = ADC_IER_EOC7 | ADC_IER_EOC13;
  NVIC_EnableIRQ(ADC_IRQn);                   //Enable ADC interrupt
 }

 void ADC_Handler(){
  digitalWrite(7,HIGH);
 VFB_bot = ADC->ADC_CDR[7]; //Read ch7 bottom V_1 (not dropping any bits)
 VFB_tot = ADC->ADC_CDR[13]; //Read ch13 (V1+V_1)(not dropping any bits)
 
 VFB_bot_r = (VFB_bot/4095)*3.3*10;  //Physical value
 VFB_tot_r = ((VFB_tot/4095)*33);  // Physical value

 vcm = VFB_tot_r/2;
 vdm = (VFB_tot_r - 2*VFB_bot_r)/2;

 digitalWrite(7,LOW);
 }

got the same problem
solution is there: Start ADC-conversion with PWM-Interrupt - #6 by onkeluhu

hope it helps

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