Initialization

To start using the timer/counter in a basic mode, follow these steps:
  1. 1.Write a TOP value to the Period register (TCAn.PER).
  2. 2.Enable the peripheral by writing a ‘1’ to the ENABLE bit in the Control A register (TCAn.CTRLA).

    The counter will start counting clock ticks according to the prescaler setting in the Clock Select bit field (CLKSEL) in TCAn.CTRLA.

  3. 3.Optional: By writing a ‘1’ to the Enable Count on Event Input bit (CNTEI) in the Event Control register (TCAn.EVCTRL), events are counted instead of clock ticks.
  4. 4.The counter value can be read from the Counter bit field (CNT) in the Counter register (TCAn.CNT).