Go Down

Topic: ADC - Triggering on pulses (Read 463 times) previous topic - next topic


Hi, i'm actually working on data-acquisition via ADC.  I found the sample code on Nicecircuits, which runs perfect for continious signals. But my goal is to detect short single events.

So i have to set up the DUE sampling for triggering on defined levels (like an oscilloscope).
The sample code uses direct register-settings and DMA-Function to get the best sampling rate of the SAM-Controller. Could someone give me hints how to change the code for adc-sampling with pre-defined trigger-levels ?




Dec 06, 2017, 09:25 am Last Edit: Dec 06, 2017, 09:26 am by ard_newbie
Here is an example sketch to trigger an interrupt each time an ADC conversion crosses a pre-defined comparison window :

Code: [Select]

/*********        ADC interrupt trigger depending on a compare window           *****/

void setup() {

void loop() {

void adc_setup ()
  PMC->PMC_PCER1 |= PMC_PCER1_PID37;                    // ADC power ON
  ADC->ADC_CR = ADC_CR_SWRST;                           // Reset ADC
  ADC->ADC_MR |=  ADC_MR_FREERUN_ON;                    // ADC in free running mode

  ADC->ADC_EMR = ADC_EMR_CMPMODE_OUT                   // Generates an event when the converted data crosses the comparison window.
                 | ADC_EMR_CMPSEL(7)                   // Compare channel 7 = A0
                 | ADC_EMR_CMPFILTER(0);               // Number of consecutive compare events necessary
                                                       // to raise the flag = CMPFILTER+1

  ADC->ADC_CWR = ADC_CWR_LOWTHRES(1000) | ADC_CWR_HIGHTHRES(4000); // Compare with a high and low thresholds of conversion

  ADC->ADC_CHER = ADC_CHER_CH7;                         // Enable Channel 7 = A0

  ADC->ADC_IER = ADC_IER_COMPE;                         // Interrupt on Compare match enable

  NVIC_EnableIRQ(ADC_IRQn);                             // Enable ADC interrupt

void ADC_Handler() {

  ADC->ADC_ISR;                            // Read and clear status register
  // Do some stuff (keep this as short as possible, e.g. set a flag to be proceed in loop())

Go Up