/*** *** EXAMPLE SLEEPWALKING: TC0 is used to trigger *** ADC Start conversion using the Event System, *** at 1 kHz frequency based on XOSC32K. ***/ void ADC_preconfig(void) { /*** Configure the ADC with *** run in Standby and On-Demand ***/ ADC->CTRLA.reg = (ADC_CTRLA_RUNSTDBY|ADC_CTRLA_ONDEMAND); /*** ADC clock prescaler configuration ***/ ADC->CTRLB.reg = (ADC_CTRLB_PRESCALER_DIV2); /*** ADC in 12-bit resolution ***/ ADC->CTRLC.reg = (ADC_CTRLC_RESSEL_12BIT); /*** (write synchronized) ***/ while(ADC->SYNCBUSY.reg & ADC_SYNCBUSY_CTRLC); /*** internal variable reference voltage ***/ ADC->REFCTRL.reg = (ADC_REFCTRL_REFSEL_INTVCC2); /*** Event control input with start of Conv ***/ ADC->EVCTRL.reg = (ADC_EVCTRL_STARTEI); /*** MUXNEG: Internal Ground; *** MUXPOS: AIN0: Signal on ADC+ *** of the Xplained Pro EXT1 connector ***/ ADC->INPUTCTRL.reg = (ADC_INPUTCTRL_MUXNEG(0x18)| ADC_INPUTCTRL_MUXPOS_AIN0); /*** (write synchronized) ***/ while(ADC->SYNCBUSY.reg & ADC_SYNCBUSY_INPUTCTRL); /*** wait 5 adc Clock during sample ***/ ADC->SAMPCTRL.reg = ADC_SAMPCTRL_SAMPLEN(4); /*** (write synchronized) ***/ while(ADC->SYNCBUSY.reg & ADC_SYNCBUSY_SAMPCTRL); /*** *** ADC Interrupt and ADC Enable are not done *** at this tep as EVSYS reminds to be configured ***/ }