1.1 Timer/Counter Type B

The capabilities of the TCB include frequency-adjustable waveform generation and input capture on event with time and frequency measurement of digital signals. The TCB consists of a base counter and control logic that can be set in one of eight different modes, each mode providing unique functionality. The base counter is clocked by the peripheral clock with optional prescaling. The TCB features the following characteristics:

  • 16-Bit Timer/Counter
  • Operation Modes:
    • Periodic interrupt
    • Time-out check
    • Input capture:
      • On event
      • Frequency measurement
      • Pulse-width measurement
      • Frequency and pulse-width measurement
      • 32-Bit capture
    • Single-Shot
    • 8-Bit PWM
  • Noise Canceler on Event Input
  • Synchronized Operation with TCE

In the context of this technical brief, both TCB instances are used, and the focus is on the Periodic Interrupt mode and Input Capture Frequency Measurement mode.

In the Periodic Interrupt mode, the counter adds up to the capture value and restarts from BOTTOM. A Capture interrupt and event is generated when the counter value equals to TOP. If TOP is updated to a value lower than the counter value, upon reaching MAX (the maximum value in the count sequence), an Overflow interrupt and event is generated, and the counter restarts from BOTTOM.

Figure 1-1. TCB Periodic Interrupt Mode

In the Input Capture Frequency Measurement mode, the TCB captures the counter value and restarts on either a positive or negative edge of the event input signal, depending on the state of the Event Edge bit in the Event Control (TCBn.EVCTRL) register. The Count register value is transferred to the Compare/Capture register, and a Capture interrupt and event are generated. The Capture interrupt flag is cleared automatically after reading the low byte of the Compare/Capture register. An Overflow interrupt and event are generated when the counter value reaches MAX.

The Input Capture Frequency Measurement mode requires the TCB to be configured as an event user by writing 1 to the Capture Event Input Enable bit in the Event Control register and setting up the Event System (EVSYS) according to the application’s requirements. The event must last at least one peripheral clock cycle to be recognized.

Figure 1-2. TCB Input Capture Frequency Measurement

If additional filtering of the input signal is desired, the Noise Canceler feature of the TCB can be used. When the Noise Filter bit in the Event Control register is enabled, the peripheral monitors the event channel and keeps a record of the last four observed samples. If the four consecutive samples are equal, the input is considered stable, and the signal is fed to the edge detector.