4.14.4 16-bit Timer/Counter A with PWM
16-bit Timer/Counter type A (TCA) with three compare channels for PWM and waveform generation.
4.14.4.1 Introduction
The Timer/Counter type A (TCA) is a 16-bit flexible timer that can perform complex actions as well as the basic functions of a simple timer. The TCA can be split into two completely independent 8-bit timers and can also support Wave Generation modes. Another important characteristic is that the TCA was devised to overcome common problems when using timers, such as the unpredictable behavior of the Pulse-Width Modulator (PWM) signal when the duty cycle is changed while the timer is running. The TCA has double-buffered registers that synchronize the updates of different registers, making the generated waveforms predictable in every single situation.
4.14.4.2 Supported Device Families
AVR® Dx | AVR® Ex | ATtiny | ATmega |
4.14.4.3 Required Header Files
#include "mcc_generated_files/timer/tca[X].h"
4.14.4.4 How to Use the TCA PLIB Driver
The links below provide examples for the different TCA use cases.
General instructions common for all examples: Timer Use Case Code Snippet Instructions
- Timer Use Case 1: 100 ms Timer
- Timer Use Case 2: Switching timer period 100 ms/500 ms
- Timer Use Case 3: Timer Wakes from Sleep Every 10s
- Timer Use Case 4: 250 Hz Output Signal on General Purpose Input/Output (GPIO) pin
- Timer Use Case 5: Single slope PWM
- Timer Use Case 6: Single Slope PWM in Split mode
- Recommended starting point: UART Driver, Timer/Counter A PLIB Driver and the Data Streamer Library.
- Videos also included for: RTC PLIB Driver, ADC PLIB Driver, AVR Event System.
4.14.4.5 Module Documentation
4.14.4.5.1 TCA0 in Normal Mode
This file contains the API prototypes for the TCA0 driver in Normal (16-bit) mode.
Module description
This file contains the API prototypes for the TCA0 driver in Normal (16-bit) mode.
Typedefs
typedef void(* TCAx_cb_t) (void)
Function pointer to the callback function called by TCA when operating in Normal mode. The default value is set to NULL which means that no callback function will be used.
Functions
void TCAx_Initialize (void)
Initializes the TCA interface.
void TCAx_Start (void)
Starts the 16-bit timer/counter for the TCA interface.
void TCAx_Stop (void)
Stops the 16-bit timer/counter for the TCA interface.
void TCAx_OverflowCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called if the Overflow Interrupt flag is set.
void TCAx_Compare0CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 0 Match Interrupt flag is set.
void TCAx_Compare1CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 1 Match Interrupt flag is set.
void TCAx_Compare2CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 2 Match Interrupt flag is set.
void TCAx_EnableInterrupt (void)
Enables the 16-bit timer/counter interrupt for the TCA interface.
void TCAx_DisableInterrupt (void)
Disables the 16-bit timer/counter interrupt for the TCA interface.
uint16_t TCAx_Read (void)
Reads the 16-bit timer/counter value for the TCA interface.
void TCAx_Write (uint16_t timerVal)
Writes the timer value to load to the TCA.
void TCAx_ClearOverflowInterruptFlag (void)
Clears the Overflow Interrupt flag after the Overflow flag set.
bool TCAx_IsOverflowInterruptFlagSet (void)
Checks the Overflow Interrupt flag status for the TCA interface.
void TCAx_ClearCMP0InterruptFlag (void)
Clears the Compare 0 Interrupt flag after the Compare 0 flag is set.
bool TCAx_IsCMP0InterruptFlagSet (void)
Checks the Compare 0 Interrupt flag status for the TCA interface.
void TCAx_ClearCMP1InterruptFlag (void)
Clears the Compare 1 Interrupt flag after the Compare 1 flag is set.
bool TCAx_IsCMP1InterruptFlagSet (void)
Checks the Compare 1 Interrupt flag status for the TCA interface.
void TCAx_ClearCMP2InterruptFlag (void)
Clears the Compare 2 Interrupt flag after the Compare 2 flag is set.
bool TCAx_IsCMP2InterruptFlagSet (void)
Checks the Compare 2 Interrupt flag status for the TCA interface.
Typedef Documentation
TCAx_cb_t
void TCAx_cb_t
Function pointer to the callback function called by TCA when operating in Normal mode. The default value is set to NULL which means that no callback function will be used.
Function pointer to the callback function called by TCA when operating in Split mode. The default value is set to NULL which means that no callback function will be used.
Function Documentation
TCAx_ClearCMP0InterruptFlag()
void TCAx_ClearCMP0InterruptFlag (void )
Clears the Compare 0 Interrupt flag after the Compare 0 flag is set.
|
None. |
TCAx_ClearCMP1InterruptFlag()
void TCAx_ClearCMP1InterruptFlag (void )
Clears the Compare 1 Interrupt flag after the Compare 1 flag is set.
|
None. |
TCAx_ClearCMP2InterruptFlag()
void TCAx_ClearCMP2InterruptFlag (void )
Clears the Compare 2 Interrupt flag after the Compare 2 flag is set.
|
None. |
TCAx_ClearOverflowInterruptFlag()
void TCAx_ClearOverflowInterruptFlag (void )
Clears the Overflow Interrupt flag after the Overflow flag set.
|
None. |
TCAx_Compare0CallbackRegister()
void TCAx_Compare0CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 0 Match Interrupt flag is set.
|
None. |
TCAx_Compare1CallbackRegister()
void TCAx_Compare1CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 1 Match Interrupt flag is set.
|
None. |
TCAx_Compare2CallbackRegister()
void TCAx_Compare2CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 2 Match Interrupt flag is set.
|
None. |
TCAx_DisableInterrupt()
void TCAx_DisableInterrupt (void )
Disables the 16-bit timer/counter interrupt for the TCA interface.
|
None. |
TCAx_EnableInterrupt()
void TCAx_EnableInterrupt (void )
Enables the 16-bit timer/counter interrupt for the TCA interface.
|
None. |
TCAx_Initialize()
void TCAx_Initialize (void )
Initializes the TCA interface.
|
None. |
TCAx_IsCMP0InterruptFlagSet()
bool TCAx_IsCMP0InterruptFlagSet (void )
Checks the Compare 0 Interrupt flag status for the TCA interface.
|
|
TCAx_IsCMP1InterruptFlagSet()
bool TCAx_IsCMP1InterruptFlagSet (void )
Checks the Compare 1 Interrupt flag status for the TCA interface.
|
|
TCAx_IsCMP2InterruptFlagSet()
bool TCAx_IsCMP2InterruptFlagSet (void )
Checks the Compare 2 Interrupt flag status for the TCA interface.
|
|
TCAx_IsOverflowInterruptFlagSet()
bool TCAx_IsOverflowInterruptFlagSet (void )
Checks the Overflow Interrupt flag status for the TCA interface.
|
|
TCAx_OverflowCallbackRegister()
void TCAx_OverflowCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called if the Overflow Interrupt flag is set.
|
None. |
TCAx_Read()
uint16_t TCAx_Read (void )
Reads the 16-bit timer/counter value for the TCA interface.
|
uint16_t - timer/counter value returns from the TCA0 interface. |
TCAx_Start()
void TCAx_Start (void )
Starts the 16-bit timer/counter for the TCA interface.
|
None. |
TCAx_Stop()
void TCAx_Stop (void )
Stops the 16-bit timer/counter for the TCA interface.
|
None. |
TCAx_Write()
void TCAx_Write (uint16_t timerVal)
Writes the timer value to load to the TCA.
|
None. |
4.14.4.5.2 TCA0 in Split mode
This file contains the API prototypes for the TCA0 driver in Split (8-bit) mode.
Module description
This file contains the API prototypes for the TCA0 driver in Split (8-bit) mode.
Functions
void TCAx_Initialize (void)
Initializes Split mode for the TCA interface.
void TCAx_Start (void)
Starts Split timer/counter for the TCA interface.
void TCAx_Stop (void)
Stops Split timer/counter for the TCA interface.
void TCAx_HighCountCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called when the high byte Underflow Interrupt flag is set.
void TCAx_LowCompare0CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 0 Interrupt flag is set.
void TCAx_LowCompare1CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 1 Interrupt flag is set.
void TCAx_LowCompare2CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 2 Interrupt flag is set.
void TCAx_LowCountCallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the low byte Underflow Interrupt flag is set.
void TCAx_EnableInterrupt (void)
Enables the Split timer/counter interrupt for the TCA interface.
void TCAx_DisableInterrupt (void)
Disables the Split timer/counter interrupt for the TCA interface.
uint8_t TCAx_ReadHighCount (void)
Reads the high 8-bit timer/counter1 value for the TCA interface.
void TCAx_WriteHighCount (uint8_t timerVal)
Writes the high 8-bit timer/counter1 value to load for the TCA interface.
uint8_t TCAx_ReadLowCount (void)
Reads the low 8-bit timer/counter2 value for the TCA interface.
void TCAx_WriteLowCount (uint8_t timerVal)
Writes the low 8-bit timer/counter2 value to load to the TCA interface.
void TCAx_ClearHUNFInterruptFlag (void)
Clears the high byte Underflow Interrupt flag, if the flag is set.
bool TCAx_IsHUNFInterruptFlagSet (void)
Checks the high byte Underflow Interrupt flag status for split timer/counter.
void TCAx_ClearLUNFInterruptFlag (void)
Clears the low byte Underflow Interrupt flag, if the flag is set.
bool TCAx_IsLUNFInterruptFlagSet (void)
Checks the low byte Underflow Interrupt flag status for Split timer/counter.
void TCAx_ClearLCMP0InterruptFlag (void)
Clears the low byte Compare Channel 0 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP0InterruptFlagSet (void)
Checks the low byte Compare Channel 0 Interrupt flag status for the TCA interface.
void TCAx_ClearLCMP1InterruptFlag (void)
Clears the low byte Compare Channel 1 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP1InterruptFlagSet (void)
Checks the low byte Compare Channel 1 Interrupt flag status for the TCA interface.
void TCAx_ClearLCMP2InterruptFlag (void)
Clears the low byte Compare Channel 2 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP2InterruptFlagSet (void)
Checks the low byte Compare Channel 2 Interrupt flag status for the TCA interface.
Function Documentation
TCAx_ClearHUNFInterruptFlag()
void TCAx_ClearHUNFInterruptFlag (void )
Clears the high byte Underflow Interrupt flag, if the flag is set.
|
None. |
TCAx_ClearLCMP0InterruptFlag()
void TCAx_ClearLCMP0InterruptFlag (void )
Clears the low byte Compare Channel 0 Interrupt Enable bit, if the flag is set for the TCA.
|
None. |
TCAx_ClearLCMP1InterruptFlag()
void TCAx_ClearLCMP1InterruptFlag (void )
Clears the low byte Compare Channel 1 Interrupt Enable bit, if the flag is set for the TCA.
|
None. |
TCAx_ClearLCMP2InterruptFlag()
void TCAx_ClearLCMP2InterruptFlag (void )
Clears the low byte Compare Channel 2 Interrupt Enable bit, if the flag is set for the TCA.
|
None. |
TCAx_ClearLUNFInterruptFlag()
void TCAx_ClearLUNFInterruptFlag (void )
Clears the low byte Underflow Interrupt flag, if the flag is set.
|
None. |
TCAx_DisableInterrupt()
void TCAx_DisableInterrupt (void )
Disables the Split timer/counter interrupt for the TCA interface.
|
None. |
TCAx_EnableInterrupt()
void TCAx_EnableInterrupt (void )
Enables the Split timer/counter interrupt for the TCA interface.
|
None. |
TCAx_HighCountCallbackRegister()
void TCAx_HighCountCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called when the high byte Underflow Interrupt flag is set.
|
None. |
TCAx_Initialize()
void TCAx_Initialize (void )
Initializes Split mode for the TCA interface.
|
None. |
Initializes Split mode for the TCA interface.
|
None. |
TCAx_IsHUNFInterruptFlagSet()
bool TCAx_IsHUNFInterruptFlagSet (void )
Checks the high byte Underflow Interrupt flag status for split timer/counter.
|
|
TCAx_IsLCMP0InterruptFlagSet()
bool TCAx_IsLCMP0InterruptFlagSet (void )
Checks the low byte Compare Channel 0 Interrupt flag status for the TCA interface.
|
|
TCAx_IsLCMP1InterruptFlagSet()
bool TCAx_IsLCMP1InterruptFlagSet (void )
Checks the low byte Compare Channel 1 Interrupt flag status for the TCA interface.
|
|
TCAx_IsLCMP2InterruptFlagSet()
bool TCAx_IsLCMP2InterruptFlagSet (void )
Checks the low byte Compare Channel 2 Interrupt flag status for the TCA interface.
|
|
TCAx_IsLUNFInterruptFlagSet()
bool TCAx_IsLUNFInterruptFlagSet (void )
Checks the low byte Underflow Interrupt flag status for Split timer/counter.
|
|
TCAx_LowCompare0CallbackRegister()
void TCAx_LowCompare0CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 0 Interrupt flag is set.
|
None. |
TCAx_LowCompare1CallbackRegister()
void TCAx_LowCompare1CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 1 Interrupt flag is set.
|
None. |
TCAx_LowCompare2CallbackRegister()
void TCAx_LowCompare2CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 2 Interrupt flag is set.
|
None. |
TCAx_LowCountCallbackRegister()
void TCAx_LowCountCallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the low byte Underflow Interrupt flag is set.
|
None. |
TCAx_ReadHighCount()
uint8_t TCAx_ReadHighCount (void )
Reads the high 8-bit timer/counter1 value for the TCA interface.
|
Timer/counter1 value returned from the TCA0 interface. |
TCAx_ReadLowCount()
uint8_t TCAx_ReadLowCount (void )
Reads the low 8-bit timer/counter2 value for the TCA interface.
|
uint8_t - Timer/counter2 value returned from the TCA0 interface. |
TCAx_Start()
void TCAx_Start (void )
Starts Split timer/counter for the TCA interface.
|
None. |
Starts Split timer/counter for the TCA interface.
|
None. |
TCAx_Stop()
void TCAx_Stop (void )
Stops Split timer/counter for the TCA interface.
|
None. |
Stops Split timer/counter for the TCA interface.
|
None. |
TCAx_WriteHighCount()
void TCAx_WriteHighCount (uint8_t timerVal)
Writes the high 8-bit timer/counter1 value to load for the TCA interface.
|
None. |
TCAx_WriteLowCount()
void TCAx_WriteLowCount (uint8_t timerVal)
Writes the low 8-bit timer/counter2 value to load to the TCA interface.
|
None. |
4.14.4.5.3 Timer Interface
This file contains API prototypes and other datatypes for TCA module.
Module description
This file contains API prototypes and other datatypes for TCA module.
@Company Microchip Technology Inc.
@File Name TMR_interface.h
@Summary This is the generated header file for Timer module interfaces.
@Description This header file provides interfaces to Timer driver APIs. Generation Information : Driver Version : 1.00 The generated drivers are tested against the following: MPLAB : MPLAB X v5.40
Data structures
struct TMR_INTERFACE
4.14.4.5.4 Timer/Counter Type A (TCA) Use Cases
Timer Use Case Code Snippet Instructions
-
Add TCA (or another timer) to the project
-
Configure:
-
Timer/Counter X as described in the use case.
-
Any other peripherals or pins needed for the use case.
-
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
Timer Use Case 1: 100 ms Timer
This use case configures Timer/Counter A (TCAx) to generate an overflow interrupt at a period of 100 ms, while toggling an LED.
-
TCAx > Hardware Settings:
-
Clock Selection: System Clock/x => Select so high limit of Requested Timeout(s) > needed
-
Requested Timeout(s): 0.1 (100 ms).
-
-
TCAx > Interrupt Settings:
-
Enable Overflow Interrupt: Yes
-
-
System > Interrupt Manager:
-
Global Interrupt Enable: Yes.
-
-
System > Pins:
-
Pin Grid View: Select LED pin as output (Check the schematic for your board).
-
Pins: Rename Custom Name to "LED".
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" /* 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 the portable API interface, which ensures that it's easy to change the peripheral instance the timer runs on. */ const struct TMR_INTERFACE *Timer = &TCA0_Interface;
void Timer_Callback_100ms(void){
LED_Toggle();
}
int main(void) { SYSTEM_Initialize(); Timer->TimeoutCallbackRegister(Timer_Callback_100ms); while(1){} }
Timer Use Case 2: Switching timer period 100 ms/500 ms
The period of a timer is changed at run-time, when pushing the switch(SW) pin. The timer period is changed in the pin change interrupt request (IRQ) callback.
-
CLKCTRL > Settings:
-
Oscillator Frequency Selection: 1 MHz system clock
-
-
TCAx > Hardware Settings:
-
Clock Selection: System Clock/8.
-
Requested Timeout(s): 0.1 (100 ms).
-
-
TCAx > Interrupt Settings:
-
Enable Overflow Interrupt: Yes.
-
-
System > Interrupt Manager:
-
Global Interrupt Enable: Yes.
-
-
System > Pins:
-
Pin Grid View: Select LED pin as output, switch pin as input (Check the schematic for your board).
-
Pins, LED pin: Rename Custom Name to "LED".
-
Pins, switch pin: Rename Custom Name for switch pin to "SW".
-
Pins, switch pin: Enable Pull-up if needed (Check the schematic for your board).
-
Pins, switch pin: Input/Sense Configuration: Sense Falling/Rising Edge on switch press (Check the schematic for your board).
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" #include <util/delay.h> /* 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; #define LED_100ms (0x30D3) #define LED_500ms (0xF423) volatile bool CHANGE_PERIOD = false; volatile bool PERIOD_100ms = true;
void Timer_Callback(void) { LED_Toggle(); } void SW_Callback(void) { CHANGE_PERIOD = true; } void Timer_Change_Frequency(void){ Timer->Stop(); if(PERIOD_100ms) { TCA0.SINGLE.CNT = 0x0; //Clear the Counter register Timer->PeriodCountSet(LED_500ms); PERIOD_100ms = false; } else { TCA0.SINGLE.CNT = 0x0; //Clear the Counter register Timer->PeriodCountSet(LED_100ms); PERIOD_100ms = true; } Timer->Start(); }
int main(void) { SYSTEM_Initialize(); Timer->TimeoutCallbackRegister(Timer_Callback); PB2_SetInterruptHandler(SW_Callback); while(1) { if(CHANGE_PERIOD) { Timer_Change_Frequency(); _delay_ms(100); //De-bounce delay CHANGE_PERIOD = false; } } }
Timer Use Case 3: Timer Wakes from Sleep Every 10s
This use case shows how to configure TCAx to wake the microcontroller (MCU) from sleep mode every ten seconds. The wake-up interrupt callback makes the LED blink on for 100 ms, then puts the MCU back to sleep mode. No callback is used, but The TCAx interrupt wakes up the MCU, which then continues to execute code in the while loop.
-
System > CLKCTRL:
-
Oscillator Frequency Selection: 1 MHz system clock
-
-
TCAx > Hardware Settings:
-
Clock Selection: System Clock/1024 (giving about 1 ms clock).
-
Requested Timeout(s): 10(s).
-
-
TCAx > Interrupt Settings:
-
Enable Overflow Interrupt: Yes. (Note: No callback is used, the interrupt is only used to wake MCU from sleep mode).
-
-
System > Interrupt Manager:
-
Global Interrupt Enable: Yes.
-
-
System > Pins:
-
Pin Grid View: Select LED pin as output (Check the schematic for your board).
-
Pins: Rename Custom Name to "LED".
-
-
System > SLPCTRL (Sleep Control):
-
System > SLPCTRL: Add to project.
-
Sleep Enable: Yes.
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" #include <util/delay.h> #include <avr/sleep.h>
int main(void) { SYSTEM_Initialize(); while(1){ LED_SetLow(); //Set LED High _delay_ms(100); //100ms Delay in between LED toggle LED_SetHigh(); //Set LED Low sleep_mode(); //Put microcontroller to Sleep } }
Timer Use Case 4: 250 Hz Output Signal on General Purpose Input/Output (GPIO) Pin
This use case shows how to generate a signal of a specified frequency on a pin.
Note: It is only possible to select a single output frequency, i.e. the frequency will be the same between output channels even when set to different values.
-
System > CLKCTRL:
-
Oscillator Frequency Selection: 1 MHz system clock.
-
-
TCAx > Hardware Settings:
-
Clock Selection: System Clock/4.
-
Requested Timeout(s): 0.004 (4 ms).
-
-
TCAx > Waveform Generation Mode:
-
Waveform Generation Mode: Frequency Generation Mode.
-
-
TCAx > Timer Channels:
-
Channel 0: Enabled, 250 Hz.
-
-
System > Pins:
-
Pin Grid View: TMR0 WO0, select GPIO to use for 250 Hz signal.
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h"
int main(void) { SYSTEM_Initialize(); while(1){} }
Timer Use Case 5: Single slope PWM
-
a period of 100 ms and 25% duty cycle
-
a period of 100 ms and 60% duty cycle
-
System > CLKCTRL:
-
Oscillator Frequency Selection: 1 MHz system clock.
-
-
TCAx > Hardware Settings:
-
Clock Selection: System Clock/2.
-
-
TCAx > Waveform Generation Mode:
-
Waveform Generation Mode: Single Slope PWM.
-
-
TCAx > Timer Channels:
-
Timer Channels: Select an output channel(s) to enable.
-
Timer Channels: RequestedDuty 25%, 60%.
-
-
System > Pins:
-
Pin Grid View: TCAx WO0 (Waveform Output): Select output pin.
-
Pin Grid View: TCAx WO1 (Waveform Output): Select output pin.
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h"
int main(void) { SYSTEM_Initialize(); while(1){} }
Timer Use Case 6: Single Slope PWM in Split mode
Generates PWM signals using timer split mode, generating two PWM waveforms on the selected Waveform Output pins:
-
a period of 10 ms and 20% duty cycle
-
a period of 5 ms and 40% duty cycle
-
System > CLKCTRL:
-
Oscillator Frequency Selection: 1 MHz system clock.
-
-
TCAx > Hardware Settings:
-
Clock Selection: System Clock/64.
-
Timer Mode: 8-bit (Split).
-
Requested time 1(s): Set to 0.01s (10 ms).
-
Requested time 2(s): Set to 0.005s (5 ms).
-
-
TCAx > Timer Channels:
-
Timer channels: Select two output channels to enable.
-
Timer channels: RequestedDuty 20(%), 40(%).
-
-
System > Pins:
-
Pin Grid View: TCAx WO0 (Waveform Output): Select output pin.
-
Pin Grid View: TCAx WO1 (Waveform Output): Select output pin.
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h"
int main(void) { SYSTEM_Initialize(); while(1){} }
4.14.4.6 Class Documentation
4.14.4.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.4.7 File Documentation
4.14.4.7.1 source/tca0_normal.c File Reference
This file contains the API implementations for TCA0 module driver in Normal (16-bit) mode.
#include "../tca0.h"
Functions
void TCAx_DefaultCompare0CallbackRegister (void)
void TCAx_DefaultCompare1CallbackRegister (void)
void TCAx_DefaultCompare2CallbackRegister (void)
void TCAx_DefaultOverflowCallbackRegister (void)
void TCAx_OverflowCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called if the Overflow Interrupt flag is set.
void TCAx_Compare0CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 0 Match Interrupt flag is set.
void TCAx_Compare1CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 1 Match Interrupt flag is set.
void TCAx_Compare2CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 2 Match Interrupt flag is set.
ISR (TCA0_CMP0_vect)
ISR (TCA0_CMP1_vect)
ISR (TCA0_CMP2_vect)
ISR (TCA0_OVF_vect)
void TCAx_Initialize (void)
Initializes the TCA interface.
void TCAx_Start (void)
Starts the 16-bit timer/counter for the TCA interface.
void TCAx_Stop (void)
Stops the 16-bit timer/counter for the TCA interface.
void TCAx_Write (uint16_t timerVal)
Writes the timer value to load to the TCA.
uint16_t TCAx_Read (void)
Reads the 16-bit timer/counter value for the TCA interface.
void TCAx_EnableInterrupt (void)
Enables the 16-bit timer/counter interrupt for the TCA interface.
void TCAx_DisableInterrupt (void)
Disables the 16-bit timer/counter interrupt for the TCA interface.
void TCAx_ClearOverflowInterruptFlag (void)
Clears the Overflow Interrupt flag after the Overflow flag set.
bool TCAx_IsOverflowInterruptFlagSet (void)
Checks the Overflow Interrupt flag status for the TCA interface.
void TCAx_ClearCMP0InterruptFlag (void)
Clears the Compare 0 Interrupt flag after the Compare 0 flag is set.
bool TCAx_IsCMP0InterruptFlagSet (void)
Checks the Compare 0 Interrupt flag status for the TCA interface.
void TCAx_ClearCMP1InterruptFlag (void)
Clears the Compare 1 Interrupt flag after the Compare 1 flag is set.
bool TCAx_IsCMP1InterruptFlagSet (void)
Checks the Compare 1 Interrupt flag status for the TCA interface.
void TCAx_ClearCMP2InterruptFlag (void)
Clears the Compare 2 Interrupt flag after the Compare 2 flag is set.
bool TCAx_IsCMP2InterruptFlagSet (void)
Checks the Compare 2 Interrupt flag status for the TCA interface.
Variables
const struct TMR_INTERFACE TCAx_Interface
void(* TCAx_CMP0_isr_cb )(void) = &TCAx_DefaultCompare0CallbackRegister
void(* TCAx_CMP1_isr_cb )(void) = &TCAx_DefaultCompare1CallbackRegister
void(* TCAx_CMP2_isr_cb )(void) = &TCAx_DefaultCompare2CallbackRegister
void(* TCAx_OVF_isr_cb )(void) = &TCAx_DefaultOverflowCallbackRegister
Detailed Description
This file contains the API implementations for TCA0 module driver in Normal (16-bit) mode.
TCA0 Generated Driver File
Function Documentation
ISR()[1/4]
ISR (TCA0_CMP0_vect )
ISR()[2/4]
ISR (TCA0_CMP1_vect )
ISR()[3/4]
ISR (TCA0_CMP2_vect )
ISR()[4/4]
ISR (TCA0_OVF_vect )
TCAx_DefaultCompare0CallbackRegister()
void TCAx_DefaultCompare0CallbackRegister (void )
TCAx_DefaultCompare1CallbackRegister()
void TCAx_DefaultCompare1CallbackRegister (void )
TCAx_DefaultCompare2CallbackRegister()
void TCAx_DefaultCompare2CallbackRegister (void )
TCAx_DefaultOverflowCallbackRegister()
void TCAx_DefaultOverflowCallbackRegister (void )
Variable Documentation
TCAx_CMP0_isr_cb
void(* TCAx_CMP0_isr_cb) (void) = &TCAx_DefaultCompare0CallbackRegister
TCAx_CMP1_isr_cb
void(* TCAx_CMP1_isr_cb) (void) = &TCAx_DefaultCompare1CallbackRegister
TCAx_CMP2_isr_cb
void(* TCAx_CMP2_isr_cb) (void) = &TCAx_DefaultCompare2CallbackRegister
TCAx_Interface
const struct TMR_INTERFACE TCAx_Interface
Initial value:
= { .Initialize = TCAx_Initialize, .Start = NULL, .Stop = NULL, .PeriodCountSet = TCAx_Write, .TimeoutCallbackRegister = TCAx_OverflowCallbackRegister, .Tasks = NULL }
TCAx_OVF_isr_cb
void(* TCAx_OVF_isr_cb) (void) = &TCAx_DefaultOverflowCallbackRegister
4.14.4.7.2 source/tca0_normal.h File Reference
#include <stdint.h> #include <stdbool.h> #include "../system/system.h" #include "timer_interface.h" #include "../system/utils/compiler.h"
Functions
void TCAx_Initialize (void)
Initializes the TCA interface.
void TCAx_Start (void)
Starts the 16-bit timer/counter for the TCA interface.
void TCAx_Stop (void)
Stops the 16-bit timer/counter for the TCA interface.
void TCAx_OverflowCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called if the Overflow Interrupt flag is set.
void TCAx_Compare0CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 0 Match Interrupt flag is set.
void TCAx_Compare1CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 1 Match Interrupt flag is set.
void TCAx_Compare2CallbackRegister (TCAx_cb_t cb)
ISR callback function to be called if the Compare 2 Match Interrupt flag is set.
void TCAx_EnableInterrupt (void)
Enables the 16-bit timer/counter interrupt for the TCA interface.
void TCAx_DisableInterrupt (void)
Disables the 16-bit timer/counter interrupt for the TCA interface.
uint16_t TCAx_Read (void)
Reads the 16-bit timer/counter value for the TCA interface.
void TCAx_Write (uint16_t timerVal)
Writes the timer value to load to the TCA.
void TCAx_ClearOverflowInterruptFlag (void)
Clears the Overflow Interrupt flag after the Overflow flag set.
bool TCAx_IsOverflowInterruptFlagSet (void)
Checks the Overflow Interrupt flag status for the TCA interface.
void TCAx_ClearCMP0InterruptFlag (void)
Clears the Compare 0 Interrupt flag after the Compare 0 flag is set.
bool TCAx_IsCMP0InterruptFlagSet (void)
Checks the Compare 0 Interrupt flag status for the TCA interface.
void TCAx_ClearCMP1InterruptFlag (void)
Clears the Compare 1 Interrupt flag after the Compare 1 flag is set.
bool TCAx_IsCMP1InterruptFlagSet (void)
Checks the Compare 1 Interrupt flag status for the TCA interface.
void TCAx_ClearCMP2InterruptFlag (void)
Clears the Compare 2 Interrupt flag after the Compare 2 flag is set.
bool TCAx_IsCMP2InterruptFlagSet (void)
Checks the Compare 2 Interrupt flag status for the TCA interface.
Typedefs
typedef void(* TCAx_cb_t) (void)
Function pointer to the callback function called by TCA when operating in Normal mode. The default value is set to NULL which means that no callback function will be used.
Variables
const struct TMR_INTERFACE TCAx_Interface
Detailed Description
TCA0 Generated Driver API Header File
Variable Documentation
TCAx_Interface
const struct TMR_INTERFACE TCAx_Interface
4.14.4.7.3 source/tca0_split.c File Reference
This file contains the API implementations for TCA0 module in Split (8-bit) mode.
#include "../tca0.h"
Functions
void TCAx_DefaultHighCountCallbackRegister (void)
void TCAx_DefaultLowCompare0CallbackRegister (void)
void TCAx_DefaultLowCompare1CallbackRegister (void)
void TCAx_DefaultLowCompare2CallbackRegister (void)
void TCAx_DefaultLowCountCallbackRegister (void)
void TCAx_HighCountCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called when the high byte Underflow Interrupt flag is set.
void TCAx_LowCompare0CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 0 Interrupt flag is set.
void TCAx_LowCompare1CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 1 Interrupt flag is set.
void TCAx_LowCompare2CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 2 Interrupt flag is set.
void TCAx_LowCountCallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the low byte Underflow Interrupt flag is set.
ISR (TCA0_HUNF_vect)
ISR (TCA0_LCMP0_vect)
ISR (TCA0_LCMP1_vect)
ISR (TCA0_LCMP2_vect)
ISR (TCA0_LUNF_vect)
void TCAx_Initialize (void)
Initializes the TCA interface.
void TCAx_Start (void)
Starts the 16-bit timer/counter for the TCA interface.
void TCAx_Stop (void)
Stops the 16-bit timer/counter for the TCA interface.
void TCAx_WriteLowCount (uint8_t timerVal)
Writes the low 8-bit Timer/Counter2 value to load to the TCA interface.
uint8_t TCAx_ReadLowCount (void)
Reads the low 8-bit Timer/Counter2 value for the TCA interface.
void TCAx_WriteHighCount (uint8_t timerVal)
Writes the high 8-bit Timer/Counter1 value to load for the TCA interface.
uint8_t TCAx_ReadHighCount (void)
Reads the high 8-bit Timer/Counter1 value for the TCA interface.
void TCAx_EnableInterrupt (void)
Enables the 16-bit timer/counter interrupt for the TCA interface.
void TCAx_DisableInterrupt (void)
Disables the 16-bit timer/counter interrupt for the TCA interface.
void TCAx_ClearHUNFInterruptFlag (void)
Clears the high byte Underflow Interrupt flag, if the flag is set.
bool TCAx_IsHUNFInterruptFlagSet (void)
Checks the high byte Underflow Interrupt flag status for split timer/counter.
void TCAx_ClearLUNFInterruptFlag (void)
Clears the low byte Underflow Interrupt flag, if the flag is set.
bool TCAx_IsLUNFInterruptFlagSet (void)
Checks the low byte Underflow Interrupt flag status for split timer/counter.
void TCAx_ClearLCMP0InterruptFlag (void)
Clears the low byte Compare Channel 0 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP0InterruptFlagSet (void)
Checks the low byte Compare Channel 0 Interrupt flag status for the TCA interface.
void TCAx_ClearLCMP1InterruptFlag (void)
Clears the low byte Compare Channel 1 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP1InterruptFlagSet (void)
Checks the low byte Compare Channel 1 Interrupt flag status for the TCA interface.
void TCAx_ClearLCMP2InterruptFlag (void)
Clears the low byte Compare Channel 2 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP2InterruptFlagSet (void)
Checks the low byte Compare Channel 2 Interrupt flag status for the TCA interface.
Variables
const struct TMR_INTERFACE TCAx_Interface
void(* TCAx_HCNT_isr_cb )(void) = &TCAx_DefaultHighCountCallbackRegister
void(* TCAx_LCMP0_isr_cb )(void) = &TCAx_DefaultLowCompare0CallbackRegister
void(* TCAx_LCMP1_isr_cb )(void) = &TCAx_DefaultLowCompare1CallbackRegister
void(* TCAx_LCMP2_isr_cb )(void) = &TCAx_DefaultLowCompare2CallbackRegister
void(* TCAx_LCNT_isr_cb )(void) = &TCAx_DefaultLowCountCallbackRegister
Detailed Description
This file contains the API implementations for TCA0 module in Split (8-bit) mode.
TCA0 Generated Driver File
Function Documentation
ISR()[1/5]
ISR (TCA0_HUNF_vect )
ISR()[2/5]
ISR (TCA0_LCMP0_vect )
ISR()[3/5]
ISR (TCA0_LCMP1_vect )
ISR()[4/5]
ISR (TCA0_LCMP2_vect )
ISR()[5/5]
ISR (TCA0_LUNF_vect )
TCAx_DefaultHighCountCallbackRegister()
void TCAx_DefaultHighCountCallbackRegister (void )
TCAx_DefaultLowCompare0CallbackRegister()
void TCAx_DefaultLowCompare0CallbackRegister (void )
TCAx_DefaultLowCompare1CallbackRegister()
void TCAx_DefaultLowCompare1CallbackRegister (void )
TCAx_DefaultLowCompare2CallbackRegister()
void TCAx_DefaultLowCompare2CallbackRegister (void )
TCAx_DefaultLowCountCallbackRegister()
void TCAx_DefaultLowCountCallbackRegister (void )
Variable Documentation
TCAx_HCNT_isr_cb
void(* TCAx_HCNT_isr_cb) (void) = &TCAx_DefaultHighCountCallbackRegister
TCAx_Interface
const struct TMR_INTERFACE TCAx_Interface
Initial value:
= { .Initialize = TCAx_Initialize, .Start = NULL, .Stop = NULL, .PeriodCountSet = NULL, .TimeoutCallbackRegister = NULL, .Tasks = NULL }
TCAx_LCMP0_isr_cb
void(* TCAx_LCMP0_isr_cb) (void) = &TCAx_DefaultLowCompare0CallbackRegister
TCAx_LCMP1_isr_cb
void(* TCAx_LCMP1_isr_cb) (void) = &TCAx_DefaultLowCompare1CallbackRegister
TCAx_LCMP2_isr_cb
void(* TCAx_LCMP2_isr_cb) (void) = &TCAx_DefaultLowCompare2CallbackRegister
TCAx_LCNT_isr_cb
void(* TCAx_LCNT_isr_cb) (void) = &TCAx_DefaultLowCountCallbackRegister
4.14.4.7.4 source/tca0_split.h File Reference
#include "../system/utils/compiler.h" #include "timer_interface.h"
Functions
void TCAx_Initialize (void)
Initializes Split mode for the TCA interface.
void TCAx_Start (void)
Starts Split timer/counter for the TCA interface.
void TCAx_Stop (void)
Stops Split timer/counter for the TCA interface.
void TCAx_HighCountCallbackRegister (TCAx_cb_t cb)
Interrupt Service Routine (ISR) callback function register to be called when the high byte Underflow Interrupt flag is set.
void TCAx_LowCompare0CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 0 Interrupt flag is set.
void TCAx_LowCompare1CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 1 Interrupt flag is set.
void TCAx_LowCompare2CallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the lower byte Compare 2 Interrupt flag is set.
void TCAx_LowCountCallbackRegister (TCAx_cb_t cb)
ISR callback function register to be called when the low byte Underflow Interrupt flag is set.
void TCAx_EnableInterrupt (void)
Enables the split timer/counter interrupt for the TCA interface.
void TCAx_DisableInterrupt (void)
Disables the split timer/counter interrupt for the TCA interface.
uint8_t TCAx_ReadHighCount (void)
Reads the high 8-bit Timer/Counter1 value for the TCA interface.
void TCAx_WriteHighCount (uint8_t timerVal)
Writes the high 8-bit Timer/Counter1 value to load for the TCA interface.
uint8_t TCAx_ReadLowCount (void)
Reads the low 8-bit Timer/Counter2 value for the TCA interface.
void TCAx_WriteLowCount (uint8_t timerVal)
Writes the low 8-bit Timer/Counter2 value to load to the TCA interface.
void TCAx_ClearHUNFInterruptFlag (void)
Clears the high byte Underflow Interrupt flag, if the flag is set.
bool TCAx_IsHUNFInterruptFlagSet (void)
Checks the high byte Underflow Interrupt flag status for split timer/counter.
void TCAx_ClearLUNFInterruptFlag (void)
Clears the low byte Underflow Interrupt flag, if the flag is set.
bool TCAx_IsLUNFInterruptFlagSet (void)
Checks the low byte Underflow Interrupt flag status for split timer/counter.
void TCAx_ClearLCMP0InterruptFlag (void)
Clears the low byte Compare Channel 0 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP0InterruptFlagSet (void)
Checks the low byte Compare Channel 0 Interrupt flag status for the TCA interface.
void TCAx_ClearLCMP1InterruptFlag (void)
Clears the low byte Compare Channel 1 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP1InterruptFlagSet (void)
Checks the low byte Compare Channel 1 Interrupt flag status for the TCA interface.
void TCAx_ClearLCMP2InterruptFlag (void)
Clears the low byte Compare Channel 2 Interrupt Enable bit, if the flag is set for the TCA.
bool TCAx_IsLCMP2InterruptFlagSet (void)
Checks the low byte Compare Channel 2 Interrupt flag status for the TCA interface.
Typedefs
typedef void(* TCAx_cb_t) (void)
Variables
const struct TMR_INTERFACE TCAx_Interface
Detailed Description
TCA0 Generated Driver API Header File
Typedef Documentation
TCAx_cb_t
typedef void(* TCAx_cb_t) (void)
Variable Documentation
TCAx_Interface
const struct TMR_INTERFACE TCAx_Interface
4.14.4.7.5 source/timer_interface.h File Reference
#include <stddef.h>
Data structures
struct TMR_INTERFACE