I am using a samd21g18a and I am seeing incorrect callback times for TC4/5 (32 bit counter) when I setup another timer (say TC3) and I read the value from that timer before reading the value from TC4. I have tried to recreate the problem outside of my project using the samd21j18a XPLAINED board.
What I see is if I setup TC3 as a 16 bit counter with no callback and I setup TC4 as a 32 bit counter with a callback running off the external 32 kHz crystal and I read both of them (tc_get_count_value) in a loop I will see noise on the TC4 callback.
Hopefully, to make this easy to reproduce I am using the standalone ASF download (xdk-asf-3.32.0) and I modified the quick_start_callback example as show in the attached file (xdk-asf-3.32.0/sam0/drivers/tc/quick_start_callback/qs_tc_callback.c). I also modified the conf_clocks.h (xdk-asf-3.32.0/sam0/drivers/tc/quick_start_callback/samd21_xplained_pro/conf_clocks.h) to use the 32kHz external oscillator and DFLL to produce the 48MHz clock. I then ran the make file (xdk-asf-3.32.0/sam0/drivers/tc/quick_start_callback/samd21_xplained_pro/gcc/Makefile) and use openocd to write the hex file to the xplained board using the USB debug.
If you put a scope on the LED you will see jitter on the ~1ms signal. If you comment out either of the tc_get_count_value functions:
Line 190: tc_get_count_value(&tc_instance2);
Line 192: tc_get_count_value(&tc_instance);
then the jitter goes away.
Another interesting note is if you increase the for loop value from 70 to say 1000 the jitter goes away as well.
My actually problem shows up when I use tickless mode of freeRTOS running off TC4/5 and it will occasionally fire the freeRTOS at very short intervals if I am using another timer/counter in my code.
I asked Atmel support if this could be related to Errata 13268 but was told that is only if I use the event system. I sent this information to them as well so hopefully I will get a response that I can share.
Any help is appreciated...