There is a command in the controlControl B register of the TCC peripherals, which is called "Force COUNT read synchronization". It seems
- READSYNC – Force a read synchronization of COUNT
The value of the counter cannot be read without issuingCOUNT register is not valid until this command is issued and fully executed.
For exampleSample code, this worked for metested on a SAMD21E17A device:
while// (TCC0->SYNCBUSY.bit.CTRLB);Step 1: Issue READYSYNC command TCC0->CTRLBSET.bit.CMDreg = TCC_CTRLBSET_CMD_READSYNC_Val;TCC_CTRLBSET_CMD_READSYNC; // Step 2: Wait until the command is fully executed while (TCC0->SYNCBUSY.bit.CTRLB); // or while (TCC0->SYNCBUSY.bit.COUNTreg); // Step 3: Now we can read the value of the COUNT register int count = TCC0->COUNT.reg; After this, theThe resulting value of the counter can be read fromvariable TCC0->COUNT.bit.COUNTcount. I would assume that the vaule I read was corresponds to the value it hadof the counter when I issued the TCC0->CTRLBSET.bit.CMD = TCC_CTRLBSET_CMD_READSYNC_Val;READSYNC command was actually executed.
More info can be found in this (yet another) Arduino forum topic:For additional information, check chapter 31 of the https://forum.arduino.cc/index.php?topic=396804.30
It seems the Arduino forums are not as well organized regarding duplicate questions as SE.SAM D21/DA1 Family datasheet