SAMD21 tickless implementation fixed by sync before sleep?

I have implemented tickless on my samd21 chip based off the ASF tickless.c. My sleep will wake up after 8 ms instead of about 1000 ms on occasion and think that it has sleeped for the entire duration. If I add a timer/counter sync then the erroneous wake up goes away. Any insight on why? ~~~ while (tcissyncing(&tc45)) { /* Wait for sync */ } system_sleep(); ~~~ I am thinking this is probably more of a samd21 question so I have cross posted it (http://community.atmel.com/forum/samd21-tc-sync-fixes-short-sleep). However, I wanted to ask here as well.

SAMD21 tickless implementation fixed by sync before sleep?

Is this timer tc45 dedicated for the Tickless Idle sleep? If so, can’t you set it (initialise it) to wake up the CPU after a given period of time? When called, FreeRTOS will advise you how many ticks it wants to be idle (at most). A second remark: if you’re using ‘Tickless Idle’ to save energy, you should better try to sleep much longer periods of time, like 30 seconds or more.

SAMD21 tickless implementation fixed by sync before sleep?

tc45 is the freeRTOS system tick, which fires the interrupt every millisecond (every 32 counts of the 32 kHz external oscillator). For Tickless idle, the timer/counter is switched to be the sleep timer and sleeps as much as xEpectedIdleTime dictates. In my test case I have it waking every second to toggle a test pin and output debug data. In my actual system the sleep times will be on the scale of 20 seconds. The oddity is that for some reason the timer/counter wakes very quickly and thinks it has fired the interrupt indicating that it has matched. Adding the sync fixes the problem. Just trying to understand why, concerned it it just a bandaid and will show up again down the road.

SAMD21 tickless implementation fixed by sync before sleep?

I dont know what the timer sync does but if the function exists maybe you are meant to use it. Check the hardware ref manual.

SAMD21 tickless implementation fixed by sync before sleep?

The sync just waits until the hardware module has synched to the bus. You call this before writing or reading the timer/counter and so forth. Just don’t know why checking it before sleep will fix an error where the timer/counter wakes up after 8 ms instead of 1000 ms.