

After routing the GCLK4 output to digital pin D6 (PA20), I noticed there's problem with the DFLL or GCLK4 during sleep. However, during testing the TC timer period wasn't what I expected. The issue is that to run the timer from the 48MHz Digtial Frequency Locked Loop (DFLL48M) during sleep, the DFLL, generic clock (GCLK) and the TC timer have to be set to run standby mode (RUNSTDBY).

SCB->SCR |= 1 WAKEUP.reg = (1 << 2) //Wake up using EXINT2(Digital pin 1/PA02) put your setup code here, to run once: REG_TC4_INTFLAG = TC_INTFLAG_OVF // Clear the OVF interrupt flag Put your timer overflow (OVF) code here: Void TC4_Handler() // Interrupt Service Routine (ISR) for timer TC4 REG_TC4_INTENSET = TC_INTENSET_OVF // Enable TC4 interrupts REG_TC4_INTFLAG |= TC_INTFLAG_OVF // Clear the interrupt flags TC_CTRLA_WAVEGEN_MFRQ | //Enable Matched Frequency Waveform generation TC4-> |= TC_CTRLA_PRESCALER_DIV1024 | //Division factor 1024 While (TC4->) // Wait for synchronization TC4-> |= TC_CTRLA_MODE_COUNT16 //16 bit counter enable

TC4-> &= ~TC_CTRLA_ENABLE //Disable CTRLA to write configs GCLK_CLKCTRL_ID_TC4_TC5 //Feed GCLK4 output to TC4 & TC5 GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN | //Enable generic clock GCLK->GENDIV.reg = GCLK_GENDIV_DIV(48) | //Divide 48MHz by 48 i.e clock output of GCLK4 is 1MHz While (GCLK->) //Wait for the settings to be synchronized GCLK_GENCTRL_SRC_DFLL48M | //48MHZ clock as the input of the general clock generator as source GCLK_GENCTRL_GENEN | //Enable generic clock generator GCLK->GENCTRL.reg = GCLK_GENCTRL_IDC | //50-50 Duty Configure Clock Generator 4 to give output to Timer modules to generate PWM signal I need to wake up the SAMD21 from deep sleep in every ‘X’ sec interval,do some tasks & put it back to sleep again.By far,i’ve configured TC4 interrupt followed by Mr MartinL’s code in another forum & the interrupt is working correctly with a LED state change test code.But,whenever I am putting the CPU to sleep,it is unable to wake up.I also don’t have the 32.768k RTC crystal & unable to run the RTC event interrupt.Please take a look at the code below to wake up & suggest what can be done… volatile bool LED_state = 0
