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® Dx | AVR® Ex | ATtiny | ATmega |
4.14.6.3 Required Header Files
#include "mcc_generated_files/timer/tcd[X].h"
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.
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.
|
|
TCD_SetOVFIsrCallback()
void TCD_SetOVFIsrCallback (TCD0_cb_t cb)
ISR callback function to be called if the Counter Overflow flag is set.
|
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.
|
None. |
4.14.6.5.2 TIMER INTERFACE
This file contains API prototypes and other data types for the Timer module.
4.14.6.6 Class Documentation
4.14.6.6.1 TMR_INTERFACE Struct Reference
#include <timer_interface.h>
Public Attributes
-
void(* Initialize )(void)
-
void(* Start )(void)
-
void(* Stop )(void)
-
void(* PeriodCountSet )(size_t count)
-
void(* TimeoutCallbackRegister )(void(*CallbackHandler)(void))
-
void(* Tasks )(void)
Member Data Documentation
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"
Functions
-
void TCD_SetTRIGIsrCallback (TCD_cb_t cb)
-
void TCD_SetOVFIsrCallback (TCD_cb_t cb)
-
int8_t TCD_Initialize (void)
Initializes the TCD interface.
-
ISR (TCD0_OVF_vect)
-
ISR (TCD0_TRIG_vect)
Variables
-
void(* TCD_TRIG_isr_cb )(void) = NULL
-
void(* TCD_OVF_isr_cb )(void) = NULL
Detailed Description
This file contains the API implementations for the TCD driver.
TCD0 Generated Driver File
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
-
typedef void(* TCD_cb_t) (void)
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>
Data structures
-
struct TMR_INTERFACE
Detailed Description
Timer Interface Generated Driver API Header File