3.14.8 24-bit Timer/Counter F with PWM
24-bit Timer/Counter type F (TCF) offering three Counter Operation Modes.
3.14.8.1 Introduction
The 24-bit Timer/Counter type F (TCF) offers three Counter Operation Modes up to 24-bit, with a 7 bit Prescaler and Overflow and compare match: Frequency generation, Numerical Controller Oscillator and 8-bit Pulse-Width Modulation. It has Event generation as pulse or waveform output and it allows clocking from multiple sources.
3.14.8.2 Supported Device Families
AVR® EB |
3.14.8.3 Required header files:
#include "mcc_generated_files/timer/tcf[X].h"
3.14.8.4 Module Documentation
3.14.8.4.1 TCF0
This document contains the implementation of the public and private functions for the Timer Counter F (TCF0) module.
Module description
This document contains the implementation of the public and private functions for the Timer Counter F (TCF0) module.
This document contains the API prototypes and data types for the Timer Counter F (TCF0) module.
Typedefs
typedef void(* TCF0_cb_t) (void)
Pointer to a function to be used as a callback handler when an overflow interrupt event occurs.
Used as a callback function pointer.
Definitions
#define TCF0_F_US_TO_CLOCKS(US, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(US)) / (2000000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from us(microseconds) to clock cycles.
#define TCF0_F_MS_TO_CLOCKS(MS, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(MS)) / (2000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from ms(milliseconds) to clock cycles.
#define TCF0_F_S_TO_CLOCKS(S, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(S)) / (2.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from seconds to clock cycles.
#define TCF0_F_HZ_TO_CLOCKS(HZ, F_CLOCK, TCF0_PRESCALER) (uint32_t)((float)(F_CLOCK) / (2.0 * (HZ) * (TCF0_PRESCALER)) - 1)
Performs the conversion from Hz to clock cycles.
#define TCF0_NCOPL_HZ_TO_INCREMENT(HZ, F_CLOCK) (uint32_t)(((float)(HZ) * 16777216.0) / (float)(F_CLOCK) + 0.5)
Performs the conversion from Hz to Numeric Controlled Oscillator (NCO) increment.
#define TCF0_NCOFD_HZ_TO_INCREMENT(HZ, F_CLOCK, TCF0_PRESCALER) (uint32_t)(((float)(HZ) * 33554432.0 * (TCF0_PRESCALER)) / ((float)(F_CLOCK)) + 0.5)
Performs the conversion from Hz to NCO increment.
#define TCF0_PWM_PER_HZ_TO_CLOCKS(HZ, F_CLOCK, TCF0_PRESCALER) (uint8_t)((float)(F_CLOCK) / ((float)(TCF0_PRESCALER) * (HZ)) - 1)
Performs the conversion from Hz to clock cycles.
#define TCF0_PWM_PER_US_TO_CLOCKS(US, F_CLOCK, TCF0_PRESCALER) (uint8_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1
Performs the conversion from ms(microseconds) to clock cycles.
#define TCF0_PWM_DCY_TO_CLOCKS(dcy, PER) (uint8_t)(float)((dcy) * (PER))
Performs the conversion from duty cycle to clock cycles.
Enumerations
enum TCF0_status_t { TCF_STATUS_IDLE = 0, TCF_STATUS_RUNNING = 1 }
Lists the possible states of TCF0:
Functions
static void TCF0_WaitWhile_CMP0_IsBusy (void)
This function blocks the execution until the CMP0 register is no longer busy.
static void TCF0_WaitWhile_CMP1_IsBusy (void)
This function blocks the execution until the CMP1 register is no longer busy.
static void TCF0_WaitWhile_CTRLA_IsBusy (void)
This function blocks the execution until the CTRLA register is no longer busy.
static void TCF0_WaitWhile_CTRLC_IsBusy (void)
This function blocks the execution until the CTRLC register is no longer busy.
static void TCF0_WaitWhile_CTRLD_IsBusy (void)
This function blocks the execution until the CTRLD register is no longer busy.
static void TCF0_WaitWhile_PER_IsBusy (void)
This function blocks the execution until the PER register is no longer busy.
static void TCF0_WaitWhile_CNT_IsBusy (void)
This function blocks the execution until the CNT register is no longer busy.
static void TCF0_Internal_Start (void)
This private function runs the TCF0. It is used only within driver.
static void TCF0_Internal_Stop (void)
This private function stops TCF0. It is used only within driver.
ISR (TCF0_INT_vect)
Interrupt Service Routine (ISR).
void TCF0_OverflowCallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 overflow callback.
void TCF0_Compare0CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare0 callback function.
void TCF0_Compare1CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare1 callback function.
void TCF0_Initialize (void)
Initializes the TCF0 module and is the first routine called.
void TCF0_Deinitialize (void)
Resets the TCF0 module to the Default state.
TCF0_status_t TCF0_StatusGet (void)
Returns the status of the TCF0 module.
void TCF0_Start (void)
Starts TCF0.
void TCF0_Stop (void)
Stops TCF0.
void TCF0_PrescalerSet (TCF_PRESC_t config)
Selects the prescaler for TCF0.
void TCF0_StandBySleep (bool state)
Enables or disables the Run-in-Standby mode for TCF0.
void TCF0_ModeSet (TCF_WGMODE_t mode)
Sets the Waveform Generation mode for TCF0.
void TCF0_ClockSet (TCF_CLKSEL_t config)
Sets the clock source for TCF0.
void TCF0_Event_OutputMode (uint8_t value)
Controls the Event Output mode for TCF0.
void TCF0_OutputsSet (uint8_t value)
Controls the Waveform outputs for TCF0.
void TCF0_SoftwareCommand (TCF_CMD_t command)
Issues the software commands of Update, Restart or Reset over the TCF0.
void TCF0_Event_InputConfig (uint8_t config)
Configures the input event for TCF0.
void TCF0_Interrupts_Enable (uint8_t mask)
Enables the TCF0 Overflow, CMP0 or CMP1 interrupts.
void TCF0_Interrupts_Disable (uint8_t mask)
Disables the TCF0 Overflow, CMP0 or CMP1 interrupts.
uint8_t TCF0_Interrupts_FlagsGet (void)
Retrieves the interrupt flags.
void TCF0_Interrupts_FlagsClear (uint8_t mask)
Clears the interrupt flags.
uint32_t TCF0_CounterGet (void)
Gets the CNT register value.
void TCF0_CounterSet (uint32_t value)
Sets the CNT register value.
void TCF0_CompareSet (uint32_t value)
Sets the CMP register value for TCF0.
void TCF0_NCO_PulseLengthSet (TCF_WGPULSE_t config)
Sets the pulse length of the generated waveform for TCF0.
void TCF0_PWM_DutyCycle0Set (uint8_t value)
Sets the CMP0 register value for TCF0.
void TCF0_PWM_DutyCycle1Set (uint8_t value)
Sets the CMP1 register value for TCF0.
void TCF0_PWM_PeriodSet (uint8_t value)
Sets the CNT1 register value for TCF0 in PWM mode.
Variables
static TCF0_cb_t TCF0_OVF_isr_cb = NULL
Function pointers that store the callback addresses.
static volatile bool timerActive = false
Boolean that is true when the timer is active.
static volatile uint8_t timerMode = TCF_WGMODE_FRQ_gc
8-bit variable that replicates TCF_WGMODE_t enum to reflect the active mode.
Definition Documentation
TCF0_F_HZ_TO_CLOCKS
#define TCF0_F_HZ_TO_CLOCKS( HZ, F_CLOCK, TCF0_PRESCALER) (uint32_t)((float)(F_CLOCK) / (2.0 * (HZ) * (TCF0_PRESCALER)) - 1)
Performs the conversion from Hz to clock cycles.
-
The first argument is the output frequency expressed in Hertz
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in Frequency mode to compute the argument for the TCF0_CompareSet() function.
TCF0_F_MS_TO_CLOCKS
#define TCF0_F_MS_TO_CLOCKS( MS, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(MS)) / (2000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from ms(milliseconds) to clock cycles.
-
The first argument is the output period expressed in milliseconds
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in Frequency mode to compute the argument for the TCF0_CompareSet() function.
TCF0_F_S_TO_CLOCKS
#define TCF0_F_S_TO_CLOCKS( S, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(S)) / (2.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from seconds to clock cycles.
-
The first argument is the output period expressed in seconds
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in Frequency mode to compute the argument for the TCF0_CompareSet() function.
TCF0_F_US_TO_CLOCKS
#define TCF0_F_US_TO_CLOCKS( US, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(US)) / (2000000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from us(microseconds) to clock cycles.
Section: Included files Section: TCF0 Macro definitions
-
The first argument is the output period expressed in microseconds
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in Frequency mode to compute the argument for the TCF0_CompareSet() function.
TCF0_NCOFD_HZ_TO_INCREMENT
#define TCF0_NCOFD_HZ_TO_INCREMENT( HZ, F_CLOCK, TCF0_PRESCALER) (uint32_t)(((float)(HZ) * 33554432.0 * (TCF0_PRESCALER)) / ((float)(F_CLOCK)) + 0.5)
Performs the conversion from Hz to NCO increment.
-
The first argument is the NCO frequency expressed in Hertz
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in NCO Fixed Duty Cycle mode to compute the argument for the TCF0_CompareSet() function.
TCF0_NCOPL_HZ_TO_INCREMENT
#define TCF0_NCOPL_HZ_TO_INCREMENT( HZ, F_CLOCK) (uint32_t)(((float)(HZ) * 16777216.0) / (float)(F_CLOCK) + 0.5)
Performs the conversion from Hz to Numeric Controlled Oscillator (NCO) increment.
-
The first argument is the NCO frequency expressed in Hertz
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in NCO Pulse Length mode to compute the argument for the TCF0_CompareSet() function.
TCF0_PWM_DCY_TO_CLOCKS
#define TCF0_PWM_DCY_TO_CLOCKS( dcy, PER) (uint8_t)(float)((dcy) * (PER))
Performs the conversion from duty cycle to clock cycles.
-
The first argument is the duty cycle expressed as a real value between 0.0 and 1.0
-
The second argument is an integer expressing the period in clock cycles
Used in PWM mode to compute arguments for the TCF0_PWM_DutyCycle0Set() and TCF0_PWM_DutyCycle1Set() functions.
TCF0_PWM_PER_HZ_TO_CLOCKS
#define TCF0_PWM_PER_HZ_TO_CLOCKS( HZ, F_CLOCK, TCF0_PRESCALER) (uint8_t)((float)(F_CLOCK) / ((float)(TCF0_PRESCALER) * (HZ)) - 1)
Performs the conversion from Hz to clock cycles.
-
The first argument is the Pulse-Width Modulation (PWM) frequency expressed in Hertz
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in PWM mode to compute the argument for the TCF0_PWM_PeriodSet() function.
TCF0_PWM_PER_US_TO_CLOCKS
#define TCF0_PWM_PER_US_TO_CLOCKS( US, F_CLOCK, TCF0_PRESCALER) (uint8_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1
Performs the conversion from ms(microseconds) to clock cycles.
-
The first argument is the PWM period expressed in microseconds
-
The second argument is the TCF peripheral clock frequency expressed in Hertz
-
The third argument is the TCF prescaler value as an integer
Used in PWM mode to compute the argument for the TCF0_PWM_PeriodSet() function.
Typedef Documentation
TCF0_cb_t
typedef void(* TCF0_cb_t) (void)
Pointer to a function to be used as a callback handler when an overflow interrupt event occurs.
Used as a callback function pointer.Section: TCF0 Custom data types
Function Documentation
ISR()
ISR (TCF0_INT_vect )
Interrupt Service Routine (ISR).
None. |
None. |
None. |
TCF0_ClockSet()
void TCF0_ClockSet (TCF_CLKSEL_t config)
Sets the clock source for TCF0.
None. |
TCF_CLKSEL_t |
|
None. |
TCF0_Compare0CallbackRegister()
void TCF0_Compare0CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare0 callback function.
None. |
TCF0_cb_t |
Pointer to custom callback function. |
None. |
TCF0_Compare1CallbackRegister()
void TCF0_Compare1CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare1 callback function.
None. |
TCF0_cb_t |
Pointer to custom callback function. |
None. |
TCF0_CompareSet()
void TCF0_CompareSet (uint32_t value)
Sets the CMP register value for TCF0.
None. |
uint32_t. |
Only 24-bit data is used. |
None. |
TCF0_CounterGet()
uint32_t TCF0_CounterGet (void )
Gets the CNT register value.
TCF0_Initialize() is already called. |
None. |
uint32_t. |
TCF0_CounterSet()
void TCF0_CounterSet (uint32_t value)
Sets the CNT register value.
None. |
uint32_t. |
Only 24-bit data is used. |
None. |
TCF0_Deinitialize()
void TCF0_Deinitialize (void )
Resets the TCF0 module to the Default state.
None. |
None. |
None. |
TCF0_Event_InputConfig()
void TCF0_Event_InputConfig (uint8_t config)
Configures the input event for TCF0.
TCF0_Initialize() is already called. |
uint8_t |
where only bits 0-3 are used:
|
None. |
TCF0_Event_OutputMode()
void TCF0_Event_OutputMode (uint8_t value)
Controls the Event Output mode for TCF0.
TCF0_Initialize() is already called. |
uint8_t |
where only bits 6-7 are used:
|
None. |
TCF0_Initialize()
void TCF0_Initialize (void )
Initializes the TCF0 module and is the first routine called.
None. |
None. |
None. |
TCF0_Internal_Start()
inline static void TCF0_Internal_Start (void )
This private function runs the TCF0. It is used only within driver.
None. |
None. |
None. |
TCF0_Internal_Stop()
inline static void TCF0_Internal_Stop (void )
This private function stops TCF0. It is used only within driver.
None. |
None. |
None. |
TCF0_Interrupts_Disable()
void TCF0_Interrupts_Disable (uint8_t mask)
Disables the TCF0 Overflow, CMP0 or CMP1 interrupts.
TCF0_Initialize() is already called. |
uint8_t |
where only bits 0-2 are used:
|
None. |
TCF0_Interrupts_Enable()
void TCF0_Interrupts_Enable (uint8_t mask)
Enables the TCF0 Overflow, CMP0 or CMP1 interrupts.
TCF0_Initialize() is already called. |
uint8_t |
where only bits 0-2 are used:
|
None. |
TCF0_Interrupts_FlagsClear()
void TCF0_Interrupts_FlagsClear (uint8_t mask)
Clears the interrupt flags.
TCF0_Initialize() is already called. |
uint8_t |
where only bits 0-2 are used:
|
None. |
TCF0_Interrupts_FlagsGet()
uint8_t TCF0_Interrupts_FlagsGet (void )
Retrieves the interrupt flags.
TCF0_Initialize() is already called. |
None. |
uint8_t From the returned 8-bit word, only bits TCF_OVF_bm, TCF_CMP0_bm and TCF_CMP1_bm are used. |
TCF0_ModeSet()
void TCF0_ModeSet (TCF_WGMODE_t mode)
Sets the Waveform Generation mode for TCF0.
None. |
TCF_WGMODE_t |
|
None. |
TCF0_NCO_PulseLengthSet()
void TCF0_NCO_PulseLengthSet (TCF_WGPULSE_t config)
Sets the pulse length of the generated waveform for TCF0.
None. |
TCF_WGPULSE_WIDTH_t |
|
None. |
TCF0_OutputsSet()
void TCF0_OutputsSet (uint8_t value)
Controls the Waveform outputs for TCF0.
None. |
uint8_t |
where only bits 0-3 are used:
|
None. |
TCF0_OverflowCallbackRegister()
void TCF0_OverflowCallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 overflow callback.
Section: TCF0 Module APIs
None. |
TCF0_cb_t |
Pointer to custom callback function. |
None. |
TCF0_PrescalerSet()
void TCF0_PrescalerSet (TCF_PRESC_t config)
Selects the prescaler for TCF0.
None. |
TCF_PRESC_t |
|
None. |
TCF0_PWM_DutyCycle0Set()
void TCF0_PWM_DutyCycle0Set (uint8_t value)
Sets the CMP0 register value for TCF0.
None. |
uint8_t. |
None. |
TCF0_PWM_DutyCycle1Set()
void TCF0_PWM_DutyCycle1Set (uint8_t value)
Sets the CMP1 register value for TCF0.
None. |
uint8_t. |
None. |
TCF0_PWM_PeriodSet()
void TCF0_PWM_PeriodSet (uint8_t value)
Sets the CNT1 register value for TCF0 in PWM mode.
None. |
uint8_t. |
None. |
TCF0_SoftwareCommand()
void TCF0_SoftwareCommand (TCF_CMD_t command)
Issues the software commands of Update, Restart or Reset over the TCF0.
TCF0_Initialize() is already called. |
enum |
TCF_CMD_t:
|
None. |
TCF0_StandBySleep()
void TCF0_StandBySleep (bool state)
Enables or disables the Run-in-Standby mode for TCF0.
TCF0_Initialize() is already called. |
boolean |
|
None. |
TCF0_Start()
void TCF0_Start (void )
Starts TCF0.
TCF0_Initialize() is already called. |
None. |
None. |
TCF0_StatusGet()
TCF0_status_t TCF0_StatusGet (void )
Returns the status of the TCF0 module.
None. |
None. |
enum TCF_status_t:
|
TCF0_Stop()
void TCF0_Stop (void )
Stops TCF0.
TCF0_Initialize() is already called. |
None. |
None. |
TCF0_WaitWhile_CMP0_IsBusy()
inline static void TCF0_WaitWhile_CMP0_IsBusy (void )
This function blocks the execution until the CMP0 register is no longer busy.
Section: TCF0 Private functions
None. |
None. |
None. |
TCF0_WaitWhile_CMP1_IsBusy()
inline static void TCF0_WaitWhile_CMP1_IsBusy (void )
This function blocks the execution until the CMP1 register is no longer busy.
None. |
None. |
None. |
TCF0_WaitWhile_CNT_IsBusy()
inline static void TCF0_WaitWhile_CNT_IsBusy (void )
This function blocks the execution until the CNT register is no longer busy.
None. |
None. |
None. |
TCF0_WaitWhile_CTRLA_IsBusy()
inline static void TCF0_WaitWhile_CTRLA_IsBusy (void )
This function blocks the execution until the CTRLA register is no longer busy.
None. |
None. |
None. |
TCF0_WaitWhile_CTRLC_IsBusy()
inline static void TCF0_WaitWhile_CTRLC_IsBusy (void )
This function blocks the execution until the CTRLC register is no longer busy.
None. |
None. |
None. |
TCF0_WaitWhile_CTRLD_IsBusy()
inline static void TCF0_WaitWhile_CTRLD_IsBusy (void )
This function blocks the execution until the CTRLD register is no longer busy.
None. |
None. |
None. |
TCF0_WaitWhile_PER_IsBusy()
inline static void TCF0_WaitWhile_PER_IsBusy (void )
This function blocks the execution until the PER register is no longer busy.
None. |
None. |
None. |
Enumeration Type Documentation
TCF0_status_t
enum TCF0_status_t
Lists the possible states of TCF0:
-
TCF_STATUS_IDLE = 0 - The timer is not running
-
TCF_STATUS_RUNNING = 1 - The timer is running
TCF_STATUS_IDLE | |
TCF_STATUS_RUNNING |
Variable Documentation
TCF0_OVF_isr_cb
TCF0_cb_t TCF0_OVF_isr_cb = NULL[static]
Function pointers that store the callback addresses.
Section: Included files Section: TCF0 Private data
timerActive
volatile bool timerActive = false[static]
Boolean that is true when the timer is active.
timerMode
volatile uint8_t timerMode = TCF_WGMODE_FRQ_gc[static]
8-bit variable that replicates TCF_WGMODE_t enum to reflect the active mode.
3.14.8.5 File Documentation
3.14.8.5.1 source/tcf0.c File Reference
#include <avr/interrupt.h> #include <util/atomic.h> #include <stddef.h> #include "tcf0.h"
Functions
static void TCF0_WaitWhile_CMP0_IsBusy (void)
This function blocks the execution until the CMP0 register is no longer busy.
static void TCF0_WaitWhile_CMP1_IsBusy (void)
This function blocks the execution until the CMP1 register is no longer busy.
static void TCF0_WaitWhile_CTRLA_IsBusy (void)
This function blocks the execution until the CTRLA register is no longer busy.
static void TCF0_WaitWhile_CTRLC_IsBusy (void)
This function blocks the execution until the CTRLC register is no longer busy.
static void TCF0_WaitWhile_CTRLD_IsBusy (void)
This function blocks the execution until the CTRLD register is no longer busy.
static void TCF0_WaitWhile_PER_IsBusy (void)
This function blocks the execution until the PER register is no longer busy.
static void TCF0_WaitWhile_CNT_IsBusy (void)
This function blocks the execution until the CNT register is no longer busy.
static void TCF0_Internal_Start (void)
This private function runs the TCF0. It is used only within driver.
static void TCF0_Internal_Stop (void)
This private function stops TCF0. It is used only within driver.
ISR (TCF0_INT_vect)
Interrupt Service Routine (ISR).
void TCF0_OverflowCallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 overflow callback.
void TCF0_Compare0CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare0 callback function.
void TCF0_Compare1CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare1 callback function.
void TCF0_Initialize (void)
Initializes the TCF0 module and is the first routine called.
void TCF0_Deinitialize (void)
Resets the TCF0 module to the Default state.
TCF0_status_t TCF0_StatusGet (void)
Returns the status of the TCF0 module.
void TCF0_Start (void)
Starts TCF0.
void TCF0_Stop (void)
Stops TCF0.
void TCF0_PrescalerSet (TCF_PRESC_t config)
Selects the prescaler for TCF0.
void TCF0_StandBySleep (bool state)
Enables or disables the Run-in-Standby mode for TCF0.
void TCF0_ModeSet (TCF_WGMODE_t mode)
Sets the Waveform Generation mode for TCF0.
void TCF0_ClockSet (TCF_CLKSEL_t config)
Sets the clock source for TCF0.
void TCF0_Event_OutputMode (uint8_t value)
Controls the Event Output mode for TCF0.
void TCF0_OutputsSet (uint8_t value)
Controls the Waveform outputs for TCF0.
void TCF0_SoftwareCommand (TCF_CMD_t command)
Issues the software commands of Update, Restart or Reset over the TCF0.
void TCF0_Event_InputConfig (uint8_t config)
Configures the input event for TCF0.
void TCF0_Interrupts_Enable (uint8_t mask)
Enables the TCF0 Overflow, CMP0 or CMP1 interrupts.
void TCF0_Interrupts_Disable (uint8_t mask)
Disables the TCF0 Overflow, CMP0 or CMP1 interrupts.
uint8_t TCF0_Interrupts_FlagsGet (void)
Retrieves the interrupt flags.
void TCF0_Interrupts_FlagsClear (uint8_t mask)
Clears the interrupt flags.
uint32_t TCF0_CounterGet (void)
Gets the CNT register value.
void TCF0_CounterSet (uint32_t value)
Sets the CNT register value.
void TCF0_CompareSet (uint32_t value)
Sets the CMP register value for TCF0.
void TCF0_NCO_PulseLengthSet (TCF_WGPULSE_t config)
Sets the pulse length of the generated waveform for TCF0.
void TCF0_PWM_DutyCycle0Set (uint8_t value)
Sets the CMP0 register value for TCF0.
void TCF0_PWM_DutyCycle1Set (uint8_t value)
Sets the CMP1 register value for TCF0.
void TCF0_PWM_PeriodSet (uint8_t value)
Sets the CNT1 register value for TCF0 in PWM mode.
Variables
static TCF0_cb_t TCF0_OVF_isr_cb = NULL
Function pointers that store the callback addresses.
static TCF0_cb_t TCF0_CMP0_isr_cb = NULL
static TCF0_cb_t TCF0_CMP1_isr_cb = NULL
static volatile bool timerActive = false
Boolean that is true when the timer is active.
static volatile uint8_t timerMode = TCF_WGMODE_FRQ_gc
8-bit variable that replicates TCF_WGMODE_t enum to reflect the active mode.
Detailed Description
TCF0 Generated Driver API SOURCE File
Variable Documentation
TCF0_CMP0_isr_cb
TCF0_cb_t TCF0_CMP0_isr_cb = NULL[static]
TCF0_CMP1_isr_cb
TCF0_cb_t TCF0_CMP1_isr_cb = NULL[static]
3.14.8.5.2 source/tcf0.h File Reference
#include <stdbool.h> #include <stdint.h>
Functions
void TCF0_OverflowCallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 overflow callback.
void TCF0_Compare0CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare0 callback function.
void TCF0_Compare1CallbackRegister (TCF0_cb_t cb)
Setter function for TCF0 Capture-Compare1 callback function.
void TCF0_Initialize (void)
Initializes the TCF0 module and is the first routine called.
void TCF0_Deinitialize (void)
Resets the TCF0 module to the Default state.
TCF0_status_t TCF0_StatusGet (void)
Returns the status of the TCF0 module.
void TCF0_Start (void)
Starts TCF0.
void TCF0_Stop (void)
Stops TCF0.
void TCF0_PrescalerSet (TCF_PRESC_t config)
Selects the prescaler for TCF0.
void TCF0_StandBySleep (bool state)
Enables or disables the Run-in-Standby mode for TCF0.
void TCF0_ModeSet (TCF_WGMODE_t mode)
Sets the Waveform Generation mode for TCF0.
void TCF0_ClockSet (TCF_CLKSEL_t config)
Sets the clock source for TCF0.
void TCF0_Event_OutputMode (uint8_t value)
Controls the Event Output mode for TCF0.
void TCF0_OutputsSet (uint8_t value)
Controls the Waveform outputs for TCF0.
void TCF0_SoftwareCommand (TCF_CMD_t command)
Issues the software commands of Update, Restart or Reset over the TCF0.
void TCF0_Event_InputConfig (uint8_t config)
Configures the input event for TCF0.
void TCF0_Interrupts_Enable (uint8_t mask)
Enables the TCF0 Overflow, CMP0 or CMP1 interrupts.
void TCF0_Interrupts_Disable (uint8_t mask)
Disables the TCF0 Overflow, CMP0 or CMP1 interrupts.
uint8_t TCF0_Interrupts_FlagsGet (void)
Retrieves the interrupt flags.
void TCF0_Interrupts_FlagsClear (uint8_t mask)
Clears the interrupt flags.
uint32_t TCF0_CounterGet (void)
Gets the CNT register value.
void TCF0_CounterSet (uint32_t value)
Sets the CNT register value.
void TCF0_CompareSet (uint32_t value)
Sets the CMP register value for TCF0.
void TCF0_NCO_PulseLengthSet (TCF_WGPULSE_t config)
Sets the pulse length of the generated waveform for TCF0.
void TCF0_PWM_DutyCycle0Set (uint8_t value)
Sets the CMP0 register value for TCF0.
void TCF0_PWM_DutyCycle1Set (uint8_t value)
Sets the CMP1 register value for TCF0.
void TCF0_PWM_PeriodSet (uint8_t value)
Sets the CNT1 register value for TCF0 in PWM mode.
Macros
#define TCF0_F_US_TO_CLOCKS(US, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(US)) / (2000000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from us(microseconds) to clock cycles.
#define TCF0_F_MS_TO_CLOCKS(MS, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(MS)) / (2000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from ms(milliseconds) to clock cycles.
#define TCF0_F_S_TO_CLOCKS(S, F_CLOCK, TCF0_PRESCALER) (uint32_t)((((float)(F_CLOCK) * (float)(S)) / (2.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1)
Performs the conversion from seconds to clock cycles.
#define TCF0_F_HZ_TO_CLOCKS(HZ, F_CLOCK, TCF0_PRESCALER) (uint32_t)((float)(F_CLOCK) / (2.0 * (HZ) * (TCF0_PRESCALER)) - 1)
Performs the conversion from Hz to clock cycles.
#define TCF0_NCOPL_HZ_TO_INCREMENT(HZ, F_CLOCK) (uint32_t)(((float)(HZ) * 16777216.0) / (float)(F_CLOCK) + 0.5)
Performs the conversion from Hz to Numeric Controlled Oscillator (NCO) increment.
#define TCF0_NCOFD_HZ_TO_INCREMENT(HZ, F_CLOCK, TCF0_PRESCALER) (uint32_t)(((float)(HZ) * 33554432.0 * (TCF0_PRESCALER)) / ((float)(F_CLOCK)) + 0.5)
Performs the conversion from Hz to NCO increment.
#define TCF0_PWM_PER_HZ_TO_CLOCKS(HZ, F_CLOCK, TCF0_PRESCALER) (uint8_t)((float)(F_CLOCK) / ((float)(TCF0_PRESCALER) * (HZ)) - 1)
Performs the conversion from Hz to clock cycles.
#define TCF0_PWM_PER_US_TO_CLOCKS(US, F_CLOCK, TCF0_PRESCALER) (uint8_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCF0_PRESCALER)) + 0.5) - 1
Performs the conversion from ms(microseconds) to clock cycles.
#define TCF0_PWM_DCY_TO_CLOCKS(dcy, PER) (uint8_t)(float)((dcy) * (PER))
Performs the conversion from duty cycle to clock cycles.
Typedefs
typedef void(* TCF0_cb_t) (void)
Pointer to a function to be used as a callback handler when an overflow interrupt event occurs.
Used as a callback function pointer.
Enumerations
enum TCF0_status_t { TCF_STATUS_IDLE = 0, TCF_STATUS_RUNNING = 1 }
Lists the possible states of TCF0:
Detailed Description
TCF0 Generated Driver API Header File