4.14.6 12-bit Timer/Counter D with PWM

One 12-bit PWM Timer/Counter type D (TCD) optimized for power control

4.14.6.1 Introduction

The Timer/Counter type D (TCD) is a flexible 12-bit timer that can perform complex actions as well as the basic functions of a simple timer. The TCD is a high-performance waveform generator consisting of a counter that can run on a clock which is asynchronous to the peripheral clock, a prescaler, as well as compare, capture and control logic. The compare logic generates two independent outputs with optional dead time. The TCD is also connected to the Event System for capture and deterministic fault control. The timer/counter can generate interrupts and events on compare match and overflow.

4.14.6.2 Supported Device Families

AVR® DxAVR® ExATtinyATmega

4.14.6.3 Required Header Files

#include "mcc_generated_files/timer/tcd[X].h"
Note: Replace [X] with the selected instance number of the TCD module.

4.14.6.4 How to Use the TCD PLIB Driver

For use cases see: How to Use the TCA PLIB Driver

Since the TCA, TCB and TCD share the same timer interface, running the TCA use cases on the TCB or TCD is relatively simple. Specifically, look for the TMR_INTERFACE definition in tcbX.c or tcdX.c, then set the timer pointer to use the correct timer interface, i.e. *Timer = &TCBX_Interface, where X is the timer instance.

/* Create a pointer of the type TMR_INTERFACE and assign it to the address of the TCA0_Interface TMR_INTERFACE struct.
This enables us to get access to the portable API interface, ensuring that it's easy to change the peripheral instance the timer runs on. */
const struct TMR_INTERFACE *Timer = &TCA0_Interface;

Similarly, for more specific code, such as the line below, replace these with the equivalent code for the selected timer.

TCA0.SINGLE.CNT = 0x0;  //Clear the Counter register

4.14.6.5 Module Documentation

4.14.6.5.1 TCD

This file contains the API prototypes for the TCD driver.

Module description

This file contains the API prototypes for the TCD driver.

Version: TCD0 Driver Version 1.0.1
Functions
  • int8_t TCD_Initialize ()

    Initializes the TCD interface.

  • void TCD_SetTRIGIsrCallback (TCD0_cb_t cb)

    Interrupt Service Routine (ISR) callback function to be called if the Trigger Input Interrupt flag is set.

  • void TCD_SetOVFIsrCallback (TCD0_cb_t cb)

    ISR callback function to be called if the Counter Overflow flag is set.

Function Documentation

TCD_Initialize()

int8_t TCD_Initialize ( )

Initializes the TCD interface.

Parameters:
None.
Return values:
0

- TCD initialization was successful.

1

- TCD initialization was not successful.

TCD_SetOVFIsrCallback()

void TCD_SetOVFIsrCallback (TCD0_cb_t cb)

ISR callback function to be called if the Counter Overflow flag is set.

Parameters:
TCD0_cb_t

cb - Callback function for the counter overflow event.

Returns:

None.

TCD_SetTRIGIsrCallback()

void TCD_SetTRIGIsrCallback (TCD0_cb_t cb)

Interrupt Service Routine (ISR) callback function to be called if the Trigger Input Interrupt flag is set.

Parameters:
TCD0_cb_t

cb - Callback function for the trigger input event.

Returns:

None.

4.14.6.5.2 TIMER INTERFACE

This file contains API prototypes and other data types for the Timer module.

Version: Timer Interface Version 1.0.0

4.14.6.6 Class Documentation

4.14.6.6.1 TMR_INTERFACE Struct Reference

#include <timer_interface.h>

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

timer_interface.h

Initialize

void(* TMR_INTERFACE::Initialize) (void)

PeriodCountSet

void(* TMR_INTERFACE::PeriodCountSet) (size_t count)

Start

void(* TMR_INTERFACE::Start) (void)

Stop

void(* TMR_INTERFACE::Stop) (void)

Tasks

void(* TMR_INTERFACE::Tasks) (void)

TimeoutCallbackRegister

void(* TMR_INTERFACE::TimeoutCallbackRegister) (void(*CallbackHandler)(void))

4.14.6.7 File Documentation

4.14.6.7.1 source/tcd0.c File Reference

This file contains the API implementations for the TCD driver.

#include "../tcd0.h"

Detailed Description

This file contains the API implementations for the TCD driver.

TCD0 Generated Driver File

Version: TCD Driver Version 2.0.2

Function Documentation

ISR()[1/2]

ISR (TCD0_OVF_vect )

ISR()[2/2]

ISR (TCD0_TRIG_vect )

TCD_SetOVFIsrCallback()

void TCD_SetOVFIsrCallback (TCD_cb_t cb)

TCD_SetTRIGIsrCallback()

void TCD_SetTRIGIsrCallback (TCD_cb_t cb)

Variable Documentation

TCD_OVF_isr_cb

void(* TCD_OVF_isr_cb) (void) = NULL

TCD_TRIG_isr_cb

void(* TCD_TRIG_isr_cb) (void) = NULL

4.14.6.7.2 source/tcd0.h File Reference

#include "../system/utils/compiler.h"
#include "../system/ccp.h"

Functions

  • int8_t TCD_Initialize ()

    Initializes the TCD interface.

  • void TCD_SetTRIGIsrCallback (TCD0_cb_t cb)

    Interrupt Service Routine (ISR) callback function to be called if the Trigger Input Interrupt flag is set.

  • void TCD_SetOVFIsrCallback (TCD0_cb_t cb)

    ISR callback function to be called if the Counter Overflow flag is set.

Typedefs

Detailed Description

TCD0 Generated Driver API Header File

Typedef Documentation

TCD_cb_t

typedef void(* TCD_cb_t) (void)

4.14.6.7.3 source/timer_interface.h File Reference

#include <stddef.h>

Detailed Description

Timer Interface Generated Driver API Header File