Initialization

By default, the TCB is in Periodic Interrupt mode. Follow these steps to start using it:
  1. 1.Write a TOP value to the Compare/Capture (TCBn.CCMP) register.
  2. 2.Optional: Write the Compare/Capture Output Enable (CCMPEN) bit in the Control B (TCBn.CTRLB) register to ‘1’. This will make the waveform output available on the corresponding pin, overriding the value in the corresponding PORT output register. The corresponding pin direction must be configured as an output in the PORT peripheral.
  3. 3.Enable the counter by writing a ‘1’ to the ENABLE bit in the Control A (TCBn.CTRLA) register.

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

  4. 4.The counter value can be read from the Count (TCBn.CNT) register. The peripheral will generate a CAPT interrupt and event when the CNT value reaches TOP.
    1. a.If the Compare/Capture register is modified to a value lower than the current CNT, the peripheral will count to MAX and wrap around.
    2. b.At MAX, an OVF interrupt and event will be generated.