/***
 *** EXAMPLE SLEEPWALKING: TC0 is used to trigger 
 *** ADC Start conversion using the Event System, 
 *** at 1 kHz frequency based on XOSC32K.
 ***/
void init_TC0_1KHz(void)
{

 /*** Disable TC0 (Enable Protected, write synchronized) ***/
 TC0->COUNT8.CTRLA.bit.ENABLE = 0;
 while(TC0->COUNT8.SYNCBUSY.reg & TC_SYNCBUSY_ENABLE);

 /*** Configure TC0 in 8-bit counter with GLCK 
  *** for synchronization and a DIV16 to get 1KHz 
  *** event generation for the ADC.
  ***/
 TC0->COUNT8.CTRLA.reg |= (TC_CTRLA_MODE(TC_CTRLA_MODE_COUNT8_Val) |
                          TC_CTRLA_RUNSTDBY|
                          TC_CTRLA_ONDEMAND|
                          TC_CTRLA_PRESCALER(TC_CTRLA_PRESCALER_DIV1_Val));

 /*** TC0 Wave generator is configured 
  *** as Match frequency generator (MFRQ)
  ***/
 TC0->COUNT8.WAVE.reg    =    (TC_WAVE_WAVEGEN_MFRQ);

 /*** TC0 is an event generator based on compare value 
  *** These bits enable the generation of an event for 
     *** every match or capture on channel 0.
  ***/
 TC0->COUNT8.EVCTRL.reg =    (TC_EVCTRL_MCEO0);

 /*** 32 is the number to get an event @ 1 kHz frequency 
  *** used by the ADC with a 32 kHz input frequency.
  ***/
 TC0->COUNT8.CC[0].reg    =    32;

 /*** (write synchronized) ***/
 while(TC0->COUNT8.SYNCBUSY.reg & TC_SYNCBUSY_CC0);

 /***
  *** TC  Enable is not done
  *** at this tep as EVSYS reminds to be configured
  ***/

}