1- #if  defined(_SAMD21_) || defined(ARDUINO_QTPY_M0)
21
32#include  " samd21_mcu.h" 
3+ 
4+ #if  defined(_SAMD21_)
5+ 
46#include  " ../../hardware_api.h" 
57#include  " ../../../drivers/hardware_specific/samd/samd_mcu.h" 
68
@@ -19,8 +21,8 @@ static void setupADCEventTriggerFromDriver(const SAMDHardwareDriverParams *par,
1921  while  (ADC->STATUS .bit .SYNCBUSY );
2022
2123  ADC->REFCTRL .reg  = ADC_REFCTRL_REFSEL_INTVCC1;  
22-   ADC->CTRLB .reg  = ADC_CTRLB_PRESCALER_DIV32  | ADC_CTRLB_RESSEL_12BIT;
23-   //   ADC->CTRLB.bit.FREERUN = 0; 
24+   ADC->CTRLB .reg  = ADC_CTRLB_PRESCALER_DIV16  | ADC_CTRLB_RESSEL_12BIT;
25+   ADC->CTRLB .bit .FREERUN  = 0 ; 
2426  while  (ADC->STATUS .bit .SYNCBUSY );
2527
2628  ADC->INPUTCTRL .bit .MUXPOS  = g_APinDescription[_pinA].ulADCChannelNumber ;
@@ -36,7 +38,7 @@ static void setupADCEventTriggerFromDriver(const SAMDHardwareDriverParams *par,
3638  NVIC_EnableIRQ (ADC_IRQn);
3739
3840  //  --- Configure Event System ---
39-   uint8_t  tcc_num = par->tccPinConfigurations [0 ]->tcc .tccn ; 
41+   uint8_t  tcc_num = par->tccPinConfigurations [1 ]->tcc .tccn ; 
4042
4143  //  --- Enable event output on the PWM timer (important!) ---
4244  Tcc* tcc = nullptr ;
@@ -83,11 +85,12 @@ static void setupADCEventTriggerFromDriver(const SAMDHardwareDriverParams *par,
8385
8486//  ADC interrupt (switch between A, B, C)
8587void  ADC_Handler () {
86- 
88+    // digitalWrite(13,HIGH); 
8789  //  check if we are in high-side or low-side current sense
8890  is_high_side = !is_high_side;
8991  if (is_high_side){
9092    ADC->INTFLAG .reg  = ADC_INTFLAG_RESRDY;
93+     // digitalWrite(13,LOW);
9194    return ;
9295  }
9396
@@ -113,6 +116,7 @@ void ADC_Handler() {
113116    }
114117    ADC->INTFLAG .reg  = ADC_INTFLAG_RESRDY;
115118  }
119+   // digitalWrite(13,LOW);
116120}
117121
118122
0 commit comments