Timer SAMD21 sleep mode

Hi all,
I'am working on a samd21e18a, I use Adafruit wrapper for timer here but I'd like to let a timer running in a deep sleep mode but it's doesn't work, I added this in my setup but it's seem it's not working, should I set another clock to run in stand by mode?


As you suspected, you also need to set the 48MHz Digital Frequency Locked Loop (DFLL48M) clock and TC timer's RUNSTDBY bits.

For the DFLL48M clock:

SYSCTRL->DFLLCTRL.bit.RUNSTDBY = 1;   // Set the DFLL48M 48MHz clock to run on standby
while(SYSCTRL->PCLKSR.bit.DFLLRDY);   // Wait for synchronization

For the TC timer you'll need to first disable it, (since the timer's CTRLA register is enable-protected), set the RUNSTDBY bit then re-enable. You'll also need to select which timer you're using TC3, TC4 or TC5 and the timer size 8, 16 or 32-bit, for example TC4 in 16-bit timer mode:

TC4->COUNT16.CTRLA.bit.ENABLE = 0;           // Disable timer TC4
while (TC4->COUNT16.STATUS.bit.SYNCBUSY);    // Wait for synchronization
TC4->COUNT16.CTRLA.bit.RUNSTDBY = 1;         // Set timer TC4 to run on standby
TC4->COUNT16.CTRLA.bit.ENABLE = 1;           // Enable timer TC4
while (TC4->COUNT16.STATUS.bit.SYNCBUSY);    // Wait for synchronization

@simon884 By the way, if you need run a number of timers or peripheral in standy mode, you'll also need to keep the SAMD21's internal voltage regulator activated as well:

SYSCTRL->VREG.bit.RUNSTDBY = 1;    // Keep the voltage regulator in normal configuration during run stanby

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.