2.5.2.2 TCB in Input Capture for Frequency Measurement Mode

In Input Capture for Frequency Measurement mode, the TCB captures the counter value and restarts on either a positive or negative edge of the event input signal (the active edge is selectable using the Event Edge bit from the TCBn.EVCTRL register). Using this mode, the period of the input signal is available to software on each signal period, helping the software to monitor the signal’s period/frequency.

AVR® Dx - TCB initialization for Input Capture Frequency Measurement Mode

void TCB2_Init(void)
{
	TCB2.CTRLB = 0 << TCB_ASYNC_bp       /* Asynchronous Enable: disabled */
	             | 0 << TCB_CCMPEN_bp    /* Pin Output Enable: disabled */
	             | 0 << TCB_CCMPINIT_bp  /* Pin Initial State: disabled */
	             | TCB_CNTMODE_FRQ_gc;   /* Input Capture Frequency measurement */

	TCB2.EVCTRL = 1 << TCB_CAPTEI_bp    /* Event Input Enable: enabled */
	              | 0 << TCB_EDGE_bp    /* Event Edge: disabled */
	              | 0 << TCB_FILTER_bp; /* Input Capture Noise Cancellation Filter: disabled */

	TCB2.INTCTRL = 1 << TCB_CAPT_bp     /* Capture or Timeout: enabled */
	               | 0 << TCB_OVF_bp;   /* OverFlow Interrupt: disabled */

	TCB2.CTRLA = TCB_CLKSEL_DIV1_gc     /* CLK_PER */
	             | 1 << TCB_ENABLE_bp   /* Enable: enabled */
	             | 0 << TCB_RUNSTDBY_bp /* Run Standby: disabled */
	             | 0 << TCB_SYNCUPD_bp  /* Synchronize Update: disabled */
	             | 0 << TCB_CASCADE_bp; /* Cascade Two Timer/Counters: disabled */
}