SAMD21, slow synchronization of TC7 reads

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I have TC7 clocked with XOSC32K (32768 Hz) and CPU + almost all other peripherals running @40MHz.

I have just found that reading of TC7.COUNT is terribly slow.

TC7 is configured to automatically synchronize COUNT value and reading it done via:

 

wa = ((TcCount16 *)TC7)->COUNT.reg; // 16b Read

 

I have measured this Read takes about 6 periods of the generic clocks used, i.e. 6x 30.5us = 180us.

The fact that synchronization takes approx. 5-6 periods of generic clocks is described in datasheet - as I found now, too late.

Blocking other tasks for such a long time is unacceptable in my app.

 

Is there any method that would enable me to use accurate 32768 Hz clocks for some of the TC counters

and read the current counter state quickly (in <1us, CPU tick is 25ns..) ?

 

I have only one idea on mind - to configure the TC7 to count to 15 (for example) => would serve as prescaller /16, and timer-match-INTerrupts would increment SW-counter (that can be read with no delay).

But this is a bit clumsy as counting would stop when I switch to Standby.

 

This topic has a solution.
Last Edited: Fri. Jun 22, 2018 - 07:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have RCONT set already?

(Come to think if it, I'm not sure how "automatically syncing" the COUNT register is supposed to help if it takes 6 clocks (ie 6 counts) to synchronize...)

Last Edited: Thu. Jun 21, 2018 - 11:25 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I forgot this thread as nobody answered.. Already sorted out.

 

"automatically syncing" of the COUNT register works, there is no waiting for sync.needed;

counter seems to be latched everytime a one cycle of synchronization completes.

=> reading of latched COUNT gives values  i, i, i, ...... , i, i+6, i+6, i+6, i+6, ....... ,i+6, i+12, i+12, i+12,..... etc. 

so the effect of 6 periods needed for synchronization is still visible as granularity but reading of latched COUNT is fast (just few cycles of CPU).

 

this configuration is to be used:

 

// !!! Do not forget to set RREQ=1 after setting RCONT=1 !!!

// (otherwise CPU stalls for about 6 periods of generic clocks used would occur)

// set request for reading of COUNT

// RREQ RCONT - - - - - - // - - - ADDR[4:0]

((TcCount16 *)TC7)->READREQ.reg = 0xC010;

       // RREQ=1 + RCONT=1

       // 0x10 is address (offset) of register COUNT that we want to read