4.14.7 16-bit Timer/Counter E with PWM

16-bit PWM Timer/Counter type E (TCE) with scale hardware accelerator

4.14.7.1 Introduction

The flexible 16-Bit PWM Timer/Counter type E (TCE) provides accurate program execution timing, frequency and waveform generation, and command execution. The Timer/Counter consists of a base counter and compare channels. The compare channels can be used with the base counter for compare match control, frequency generation, and pulse width waveform modulation.

4.14.7.2 Supported Device Families

AVR® EB

4.14.7.3 Required header files:


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

4.14.7.4 Module Documentation

4.14.7.4.1 TCE0

This document contains API prototypes and data types for the Timer Counter E module.

Module description

This document contains API prototypes and data types for the Timer Counter E module.

Version: TCE0 Driver Version 1.0.0
Typedefs
  • typedef void(* TCE0_cb_t) (void)

    Pointer to a function to be used as a callback handler when an overflow interrupt event occurs.

Definitions
  • #define TCE0_PER_US_TO_TICKS(US, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

    Defines the macro associated with the conversion from us(microseconds) to clock increments for setting the period.

  • #define TCE0_PER_MS_TO_TICKS(MS, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(MS)) / (1000.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

    Defines the macro associated with the conversion from ms(milliseconds) to clock increments for setting the period.

  • #define TCE0_PER_S_TO_TICKS(S, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(S)) / (1.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

    Defines the macro associated with the conversion from s(seconds) to clock increments for setting the period.

  • #define TCE0_CMP_US_TO_TICKS(US, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCE0_PRESCALER)) + 0.5)

    Defines the macro associated with the conversion from us(microseconds) to clock increments for setting the compare registers.

  • #define TCE0_CMP_MS_TO_TICKS(MS, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(MS)) / (1000.0 * (float)(TCE0_PRESCALER)) + 0.5)

    Defines the macro associated with the conversion from ms(milliseconds) to clock increments for setting the compare registers.

  • #define TCE0_CMP_S_TO_TICKS(S, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(S)) / (1.0 * (float)(TCE0_PRESCALER)) + 0.5)

    Defines the macro associated with the conversion from s(seconds) to clock increments for setting the compare registers.

  • #define TCE0_HZ_TO_CLOCKS_FREQUENCYMODE(HZ, F_CLOCK, TCE0_PRESCALER) (uint16_t)((float)(F_CLOCK) / (2 * (float)(HZ) * (float)(TCE0_PRESCALER)) - 1)

    Defines the macro associated with the conversion from Hz(Hertz) to clock increments. Used in Frequency mode.

Functions
  • ISR (TCE0_OVF_vect)

    Interrupt Service Routine (ISR) for the overflow (OVF) interrupt.

  • ISR (TCE0_CMP0_vect)

    ISR for the CMP0 interrupt.

  • ISR (TCE0_CMP1_vect)

    ISR for the CMP1 interrupt.

  • ISR (TCE0_CMP2_vect)

    ISR for the CMP2 interrupt.

  • ISR (TCE0_CMP3_vect)

    ISR for the CMP3 interrupt.

  • void TCE0_OverflowCallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 overflow callback.

  • void TCE0_Compare0CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare0 callback.

  • void TCE0_Compare1CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare1 callback.

  • void TCE0_Compare2CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare2 callback.

  • void TCE0_Compare3CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare3 callback.

  • void TCE0_Initialize (void)

    Initializes the TCE0 module. This routine must be called before other TCE0 APIs.

  • void TCE0_Deinitialize (void)

    Deinitializes the TCE0 module.

  • void TCE0_Start (void)

    Starts the TCE0.

  • void TCE0_Stop (void)

    Stops the TCE0.

  • TCE0_status_t TCE0_StatusGet (void)

    Returns the status of the TCE0 module.

  • void TCE0_ModeSet (TCE_WGMODE_t mode)

    Sets the Wave mode for the TCE0.

  • void TCE0_Interrupts_Enable (uint8_t value)

    Enables the TCE0 OVF, CMP0, CMP1, CMP2 or, CMP3 interrupts.

  • void TCE0_Interrupts_FlagsClear (uint8_t value)

    Clears the interrupt flags for the TCE0.

  • uint8_t TCE0_Interrupts_FlagsGet (void)

    Retrieves the interrupt flag status.

  • void TCE0_Interrupts_Disable (uint8_t value)

    Disables the TCE0 OVF, CMP0, CMP1, CMP2 or, CMP3 interrupts.

  • void TCE0_Event_OutputMode (uint8_t value)

    Controls the Waveform mode on the event output line for the TCE0.

  • void TCE0_Event_InputConfig (uint8_t value)

    Enables the input event for the TCE0.

  • void TCE0_SoftwareCommand (TCE_CMD_t com)

    Enables software control of the Update, Restart and Reset states of the TCE0.

  • void TCE0_StandBySleep (bool state)

    Enables/disables the Run-in-Standby mode (RUNSTBY register) for the TCE0.

  • void TCE0_DebugRun (bool state)

    Enables Debug mode for the TCE0.

  • uint16_t TCE0_CounterGet (void)

    Returns the Count (CNT) register value for the TCE0.

  • void TCE0_CounterSet (uint16_t value)

    Sets the Count (CNT) register value for the TCE0.

  • void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

    Selects the prescaler for the TCE0.

  • void TCE0_Compare0Set (uint16_t value)

    Sets the Compare 0 (CMP0) register value for the TCE0.

  • void TCE0_Compare1Set (uint16_t value)

    Sets the Compare 1 (CMP1) register value for the TCE0.

  • void TCE0_Compare2Set (uint16_t value)

    Sets the Compare 2 (CMP2) register value for the TCE0.

  • void TCE0_Compare3Set (uint16_t value)

    Sets the Compare 3 (CMP3) register value for the TCE0.

  • void TCE0_CompareAllChannelsSet (uint16_t value0, uint16_t value1, uint16_t value2, uint16_t value3)

    Sets all four CMP registers for the TCE0.

  • void TCE0_CompareChannels012Set (uint16_t value0, uint16_t value1, uint16_t value2)

    Sets the CMP0, CMP1 and, CMP2 registers for the TCE0.

  • void TCE0_CompareChannels123Set (uint16_t value1, uint16_t value2, uint16_t value3)

    Sets the CMP1, CMP2, and CMP3 registers for the TCE.

  • void TCE0_CompareAllChannelsBufferedSet (uint16_t value0, uint16_t value1, uint16_t value2, uint16_t value3)

    Sets all four Compare Buffer (CMPBUF) registers for the TCE0.

  • void TCE0_CompareChannels012BufferedSet (uint16_t value0, uint16_t value1, uint16_t value2)

    Sets the Compare 0 Buffer (CMP0BUF), Compare 1 Buffer (CMP1BUF) and, Compare 2 Buffer (CMP2BUF) registers for the TCE0.

  • void TCE0_CompareChannels123BufferedSet (uint16_t value1, uint16_t value2, uint16_t value3)

    Sets the Compare 1 Buffer (CMP1BUF), Compare 2 Buffer (CMP2BUF) and, Compare 3 Buffer (CMP3BUF) registers for the TCE0.

  • void TCE0_OutputsEnable (uint8_t value)

    Enables the Waveform outputs for the four TCE0 channels.

  • void TCE0_OutputsValueSet (uint8_t value)

    Sets the output values for the four TCE0 channels.

  • uint8_t TCE0_OutputsValueGet (void)

    Returns the values of the polarities and outputs for the four TCE0 channels.

  • void TCE0_HighResSet (TCE_HREN_t resolution)

    Sets the high resolution used for the TCE0.

  • void TCE0_ScaleModeSet (TCE_SCALEMODE_t mode)

    Sets the Scaling mode used for the TCE0.

  • void TCE0_ScaleEnable (bool state)

    Allows for fractional values to be written to the Compare (CMP), Amplitude (AMP) and, Compare Buffer (CMPBUF) registers for TCE0.

  • void TCE0_AmplitudeControlEnable (bool state)

    Allows the use of the AMP and OFFSET registers for the TCE0.

  • void TCE0_AmplitudeSet (uint16_t value)

    Sets the AMP register of the TCE0.

  • uint16_t TCE0_AmplitudeGet (void)

    Returns the value of the AMP register of the TCE0.

  • void TCE0_OffsetSet (uint16_t value)

    Sets the OFFSET register of the TCE0.

  • uint16_t TCE0_OffsetGet (void)

    Returns the value of the OFFSET register of the TCE0.

  • void TCE0_PeriodSet (uint16_t period)

    Sets the Period (PER) register for the TCE0.

  • void TCE0_CountDirectionSet (void)

    Sets the TCE0 to count UP.

  • void TCE0_CountDirectionClear (void)

    Sets the TCE0 to count DOWN.

  • void TCE0_LockUpdateSet (void)

    Sets the Lock Update (LUPD) bit for the TCE0 to 1. This ensures there will be no update on the buffered registers.

  • void TCE0_LockUpdateClear (void)

    Clears the Lock Update bit for the TCE0. This ensures that the buffered registers are updated when an UPDATE condition has occurred.

  • void TCE0_AutoLockUpdateSet (void)

    Sets the Auto-Lock Update (ALUPD) bit for the TCE0 to 1. This ensures that the Lock Update (LUPD) bit in the TCEn.CTRLE register is set and cleared automatically.

  • void TCE0_AutoLockUpdateClear (void)

    Clears the Auto-Lock Update bit for the TCE0. This ensures that the LUPD bit in the TCEn.CTRLE register is not altered by the system.

  • void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

    Sets the value of the CMP0BUF register used in the Pulse-Width Modulation (PWM) mode by the TCE0.

  • void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

    Sets the value of the CMP1BUF register used in PWM mode by the TCE0.

  • void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

    Sets the value of the CMP2BUF register used in PWM mode by the TCE0.

  • void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

    Sets the value of the CMP3BUF register used in PWM mode by the TCE0.

  • void TCE0_PeriodBufferSet (uint16_t value)

    Sets the value of the Period Buffer (PERBUF) register that serves as the buffer for the period register TCE0.PER.

Variables
  • static TCE0_cb_t TCE0_OVF_isr_cb = NULL

    Function pointers that store the callback addresses.

  • static volatile bool timerActive = false

    Boolean that is true when timer is active.

  • static volatile uint8_t timerMode = TCE_WGMODE_FRQ_gc

    8-bit variable that replicates TCE_WGMODE_t enum to reflect the active mode.

Definition Documentation

TCE0_CMP_MS_TO_TICKS

#define TCE0_CMP_MS_TO_TICKS( MS, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(MS)) / (1000.0 * (float)(TCE0_PRESCALER)) + 0.5)

Defines the macro associated with the conversion from ms(milliseconds) to clock increments for setting the compare registers.

TCE0_CMP_S_TO_TICKS

#define TCE0_CMP_S_TO_TICKS( S, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(S)) / (1.0 * (float)(TCE0_PRESCALER)) + 0.5)

Defines the macro associated with the conversion from s(seconds) to clock increments for setting the compare registers.

TCE0_CMP_US_TO_TICKS

#define TCE0_CMP_US_TO_TICKS( US, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCE0_PRESCALER)) + 0.5)

Defines the macro associated with the conversion from us(microseconds) to clock increments for setting the compare registers.

TCE0_HZ_TO_CLOCKS_FREQUENCYMODE

#define TCE0_HZ_TO_CLOCKS_FREQUENCYMODE( HZ, F_CLOCK, TCE0_PRESCALER) (uint16_t)((float)(F_CLOCK) / (2 * (float)(HZ) * (float)(TCE0_PRESCALER)) - 1)

Defines the macro associated with the conversion from Hz(Hertz) to clock increments. Used in Frequency mode.

TCE0_PER_MS_TO_TICKS

#define TCE0_PER_MS_TO_TICKS( MS, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(MS)) / (1000.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

Defines the macro associated with the conversion from ms(milliseconds) to clock increments for setting the period.

TCE0_PER_S_TO_TICKS

#define TCE0_PER_S_TO_TICKS( S, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(S)) / (1.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

Defines the macro associated with the conversion from s(seconds) to clock increments for setting the period.

TCE0_PER_US_TO_TICKS

#define TCE0_PER_US_TO_TICKS( US, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

Defines the macro associated with the conversion from us(microseconds) to clock increments for setting the period.

Typedef Documentation

TCE0_cb_t

typedef void(* TCE0_cb_t) (void)

Pointer to a function to be used as a callback handler when an overflow interrupt event occurs.

Parameters:
None.
Returns:

None.

Function Documentation

ISR()[1/5]

ISR (TCE0_CMP0_vect )

ISR for the CMP0 interrupt.

Parameters:
None.
Returns:

None.

ISR()[2/5]

ISR (TCE0_CMP1_vect )

ISR for the CMP1 interrupt.

Parameters:
None.
Returns:

None.

ISR()[3/5]

ISR (TCE0_CMP2_vect )

ISR for the CMP2 interrupt.

Parameters:
None.
Returns:

None.

ISR()[4/5]

ISR (TCE0_CMP3_vect )

ISR for the CMP3 interrupt.

Parameters:
None.
Returns:

None.

ISR()[5/5]

ISR (TCE0_OVF_vect )

Interrupt Service Routine (ISR) for the overflow (OVF) interrupt.

Parameters:
None.
Returns:

None.

TCE0_AmplitudeControlEnable()

void TCE0_AmplitudeControlEnable (bool state)

Allows the use of the AMP and OFFSET registers for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API. The SCALE bit needs to be set to "1".

Parameters:
bool
state:
  • True - enable amplitude control

  • False - disable amplitude control.

Returns:

None.

TCE0_AmplitudeGet()

uint16_t TCE0_AmplitudeGet (void )

Returns the value of the AMP register of the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

uint16_t, represents the value in the AMP register.  

NOTE: the value read may be different from the one that was previously written in the AMP register.

TCE0_AmplitudeSet()

void TCE0_AmplitudeSet (uint16_t value)

Sets the AMP register of the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value, represents the value to be written in the AMP register.

Returns:

None.

TCE0_AutoLockUpdateClear()

void TCE0_AutoLockUpdateClear (void )

Clears the Auto-Lock Update bit for the TCE0. This ensures that the LUPD bit in the TCEn.CTRLE register is not altered by the system.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_AutoLockUpdateSet()

void TCE0_AutoLockUpdateSet (void )

Sets the Auto-Lock Update (ALUPD) bit for the TCE0 to 1. This ensures that the Lock Update (LUPD) bit in the TCEn.CTRLE register is set and cleared automatically.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_Compare0CallbackRegister()

void TCE0_Compare0CallbackRegister (TCE0_cb_t cb)

Setter function for the TCE0 Capture-Compare0 callback.

Precondition:

None.

Parameters:
CallbackHandler

- Pointer to custom callback.

Returns:

None.

TCE0_Compare0Set()

void TCE0_Compare0Set (uint16_t value)

Sets the Compare 0 (CMP0) register value for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- TCE0 value to be written to the CMP0 register.

Returns:

None.

TCE0_Compare1CallbackRegister()

void TCE0_Compare1CallbackRegister (TCE0_cb_t cb)

Setter function for the TCE0 Capture-Compare1 callback.

Precondition:

None.

Parameters:
CallbackHandler

- Pointer to custom callback.

Returns:

None.

TCE0_Compare1Set()

void TCE0_Compare1Set (uint16_t value)

Sets the Compare 1 (CMP1) register value for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- TCE0 value to be written to the CMP1 register.

Returns:

None.

TCE0_Compare2CallbackRegister()

void TCE0_Compare2CallbackRegister (TCE0_cb_t cb)

Setter function for the TCE0 Capture-Compare2 callback.

Precondition:

None.

Parameters:
CallbackHandler

- Pointer to custom callback.

Returns:

None.

TCE0_Compare2Set()

void TCE0_Compare2Set (uint16_t value)

Sets the Compare 2 (CMP2) register value for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- TCE0 value to be written to the CMP2 register.

Returns:

None.

TCE0_Compare3CallbackRegister()

void TCE0_Compare3CallbackRegister (TCE0_cb_t cb)

Setter function for the TCE0 Capture-Compare3 callback.

Precondition:

None.

Parameters:
CallbackHandler

- Pointer to custom callback.

Returns:

None.

TCE0_Compare3Set()

void TCE0_Compare3Set (uint16_t value)

Sets the Compare 3 (CMP3) register value for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- TCE0 value to be written to the CMP3 register.

Returns:

None.  

TCE0_CompareAllChannelsBufferedSet()

void TCE0_CompareAllChannelsBufferedSet (uint16_t value0, uint16_t value1, uint16_t value2, uint16_t value3)

Sets all four Compare Buffer (CMPBUF) registers for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value0, uint16_t value1, uint16_t value2, uint16_t value3, represents values to be written to the registers CMP0, CMP1, CMP2 and, CMP3

Returns:

None.

TCE0_CompareAllChannelsSet()

void TCE0_CompareAllChannelsSet (uint16_t value0, uint16_t value1, uint16_t value2, uint16_t value3)

Sets all four CMP registers for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value0, uint16_t value1, uint16_t value2, uint16_t value3, represents values to be written to the registers CMP0, CMP1, CMP2 and, CMP3

Returns:

None.

TCE0_CompareChannels012BufferedSet()

void TCE0_CompareChannels012BufferedSet (uint16_t value0, uint16_t value1, uint16_t value2)

Sets the Compare 0 Buffer (CMP0BUF), Compare 1 Buffer (CMP1BUF) and, Compare 2 Buffer (CMP2BUF) registers for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value0, uint16_t value1, uint16_t value2, represents values to be written to the registers CMP0BUF, CMP1BUF and, CMP2BUF

Returns:

None.

TCE0_CompareChannels012Set()

void TCE0_CompareChannels012Set (uint16_t value0, uint16_t value1, uint16_t value2)

Sets the CMP0, CMP1 and, CMP2 registers for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value0, uint16_t value1, uint16_t value2, represents values to be written to the registers CMP0, CMP1 and, CMP2

Returns:

None.

TCE0_CompareChannels123BufferedSet()

void TCE0_CompareChannels123BufferedSet (uint16_t value1, uint16_t value2, uint16_t value3)

Sets the Compare 1 Buffer (CMP1BUF), Compare 2 Buffer (CMP2BUF) and, Compare 3 Buffer (CMP3BUF) registers for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value0, uint16_t value1, uint16_t value2, represents values to be written to the registers CMP1BUF, CMP2BUF and, CMP3BUF

Returns:

None.

TCE0_CompareChannels123Set()

void TCE0_CompareChannels123Set (uint16_t value1, uint16_t value2, uint16_t value3)

Sets the CMP1, CMP2, and CMP3 registers for the TCE.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value1, uint16_t value2, uint16_t value3, represents values to be written to the registers CMP1, CMP2 and, CMP3

Returns:

None.

TCE0_CountDirectionClear()

void TCE0_CountDirectionClear (void )

Sets the TCE0 to count DOWN.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_CountDirectionSet()

void TCE0_CountDirectionSet (void )

Sets the TCE0 to count UP.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_CounterGet()

uint16_t TCE0_CounterGet (void )

Returns the Count (CNT) register value for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

uint16_t - CNT register value for the TCE0.

TCE0_CounterSet()

void TCE0_CounterSet (uint16_t value)

Sets the Count (CNT) register value for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t-

TCE0 value to be written to the CNT register.

Returns:

None.

TCE0_DebugRun()

void TCE0_DebugRun (bool state)

Enables Debug mode for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
bool
state:
  • True - TCE0 continues running in Break Debug mode when the CPU is halted;

  • False - TCE0 is halted in Break Debug mode and ignores events.

Returns:

None.

TCE0_Deinitialize()

void TCE0_Deinitialize (void )

Deinitializes the TCE0 module.

Precondition:

None.

Parameters:
None.
Returns:

None.

TCE0_Event_InputConfig()

void TCE0_Event_InputConfig (uint8_t value)

Enables the input event for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint8_t

value.

Returns:

None.

TCE0_Event_OutputMode()

void TCE0_Event_OutputMode (uint8_t value)

Controls the Waveform mode on the event output line for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint8_t

state.

Returns:

None.

TCE0_HighResSet()

void TCE0_HighResSet (TCE_HREN_t resolution)

Sets the high resolution used for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
TCE_HREN_t
resolution:
  • TCE_HREN_OFF_gc = (0x00<<6) - High Resolution Disable

  • TCE_HREN_4X_gc = (0x01<<6) - Resolution increased by 4 (2 bits)

  • TCE_HREN_8X_gc = (0x02<<6) - Resolution increased by 4 (3 bits)

Returns:

None.

TCE0_Initialize()

void TCE0_Initialize (void )

Initializes the TCE0 module. This routine must be called before other TCE0 APIs.

Precondition:

None.

Parameters:
None.
Returns:

None.

TCE0_Interrupts_Disable()

void TCE0_Interrupts_Disable (uint8_t value)

Disables the TCE0 OVF, CMP0, CMP1, CMP2 or, CMP3 interrupts.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_Interrupts_Enable()

void TCE0_Interrupts_Enable (uint8_t value)

Enables the TCE0 OVF, CMP0, CMP1, CMP2 or, CMP3 interrupts.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_Interrupts_FlagsClear()

void TCE0_Interrupts_FlagsClear (uint8_t value)

Clears the interrupt flags for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint8_t

value.

Returns:

None.

TCE0_Interrupts_FlagsGet()

uint8_t TCE0_Interrupts_FlagsGet (void )

Retrieves the interrupt flag status.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:
uint8_t:
  • - Bit 0 is set by the OVF interrupt

  • - Bit 4 is set by the CMP0 interrupt

  • - Bit 5 is set by the the CMP1 interrupt

  • - Bit 6 is set by the the CMP2 interrupt

  • - Bit 7 is set by the the CMP3 interrupt

TCE0_LockUpdateClear()

void TCE0_LockUpdateClear (void )

Clears the Lock Update bit for the TCE0. This ensures that the buffered registers are updated when an UPDATE condition has occurred.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_LockUpdateSet()

void TCE0_LockUpdateSet (void )

Sets the Lock Update (LUPD) bit for the TCE0 to 1. This ensures there will be no update on the buffered registers.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_ModeSet()

void TCE0_ModeSet (TCE_WGMODE_t mode)

Sets the Wave mode for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
TCE_WGMODE_t
mode:
  • TCE_WGMODE_NORMAL_gc - Normal Mode

  • TCE_WGMODE_FRQ_gc - Frequency Generation Mode

  • TCE_WGMODE_SINGLESLOPE_gc - Single Slope PWM

  • TCE_WGMODE_DSTOP_gc - Dual Slope PWM, overflow on TOP

  • TCE_WGMODE_DSBOTH_gc - Dual Slope PWM, overflow on TOP and BOTTOM

  • TCE_WGMODE_DSBOTTOM_gc - Dual Slope PWM, overflow on BOTTOM

Returns:

None.

TCE0_OffsetGet()

uint16_t TCE0_OffsetGet (void )

Returns the value of the OFFSET register of the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

uint16_t - Value in the OFFSET register.

TCE0_OffsetSet()

void TCE0_OffsetSet (uint16_t value)

Sets the OFFSET register of the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- Value to be written in the OFFSET register.

Returns:

None.

TCE0_OutputsEnable()

void TCE0_OutputsEnable (uint8_t value)

Enables the Waveform outputs for the four TCE0 channels.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint8_t

- Bitmask value to enable the corresponding Compare Enable (CMPEN) bits in the Control B (CTRLB) register.

Returns:

None.  

TCE0_OutputsValueGet()

uint8_t TCE0_OutputsValueGet (void )

Returns the values of the polarities and outputs for the four TCE0 channels.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

uint8_t - The bits from 7 to 4 indicate the normal/inverted status of the polarities for channels 3 to 0. The bits from 0 to 3 indicate the set/clear status of the waveform output value for the channels from 3 to 0.

TCE0_OutputsValueSet()

void TCE0_OutputsValueSet (uint8_t value)

Sets the output values for the four TCE0 channels.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint8_t

- Bitmask corresponding to the channel that requires enabling or polarity inversion.

Returns:

None.

TCE0_OverflowCallbackRegister()

void TCE0_OverflowCallbackRegister (TCE0_cb_t cb)

Setter function for the TCE0 overflow callback.

Precondition:

None.

Parameters:
CallbackHandler

- Pointer to custom callback.

Returns:

None.

TCE0_PeriodBufferSet()

void TCE0_PeriodBufferSet (uint16_t value)

Sets the value of the Period Buffer (PERBUF) register that serves as the buffer for the period register TCE0.PER.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- Value to be written in the PERBUF register.

Returns:

None.

TCE0_PeriodSet()

void TCE0_PeriodSet (uint16_t period)

Sets the Period (PER) register for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

- Value to be written in the PER register.

Returns:

None.

TCE0_PrescalerSet()

void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

Selects the prescaler for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
TCE_CLKSEL_t
prescaler
  • -DIV1 - direct clock source

  • -DIV2 - clock speed divided by 2

  • -DIV4 - clock speed divided by 4

  • -DIV8 - clock speed divided by 8

  • -DIV16 - clock speed divided by 16

  • -DIV64 - clock speed divided by 64

  • -DIV256 - clock speed divided by 256

  • -DIV1024 - clock speed divided by 1024

Returns:

None.

TCE0_PWM_BufferedDutyCycle0Set()

void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

Sets the value of the CMP0BUF register used in the Pulse-Width Modulation (PWM) mode by the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value - Value to be written in the CMP0BUF register.

Returns:

None.

TCE0_PWM_BufferedDutyCycle1Set()

void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

Sets the value of the CMP1BUF register used in PWM mode by the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value - Value to be written in the CMP1BUF register.

Returns:

None.

TCE0_PWM_BufferedDutyCycle2Set()

void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

Sets the value of the CMP2BUF register used in PWM mode by the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value - Value to be written in the CMP2BUF register.

Returns:

None.

TCE0_PWM_BufferedDutyCycle3Set()

void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

Sets the value of the CMP3BUF register used in PWM mode by the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
uint16_t

value - Value to be written in the CMP3BUF register.

Returns:

None.

TCE0_ScaleEnable()

void TCE0_ScaleEnable (bool state)

Allows for fractional values to be written to the Compare (CMP), Amplitude (AMP) and, Compare Buffer (CMPBUF) registers for TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
bool
state:
  • True - Enable scaling.

  • False - Disables scaling.  

Returns:

None.

TCE0_ScaleModeSet()

void TCE0_ScaleModeSet (TCE_SCALEMODE_t mode)

Sets the Scaling mode used for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
TCE_SCALEMODE_t
mode:
  • TCE_SCALEMODE_CENTER_gc CMPn registers scaled vs center (50% duty cycle)

  • TCE_SCALEMODE_BOTTOM_gc CMPn registers scaled vs BOTTOM (0% duty cycle)

  • TCE_SCALEMODE_TOP_gc CMPn registers scaled vs TOP (100% duty cycle)  

  • TCE_SCALEMODE_TOPBOTTOM_gc CMPn registers scaled vs TOP or BOTTOM depending on written value

Returns:

None.

TCE0_SoftwareCommand()

void TCE0_SoftwareCommand (TCE_CMD_t com)

Enables software control of the Update, Restart and Reset states of the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
TCE_CMD_t
enum:
  • TCE_CMD_NONE_gc - No Command

  • TCE_CMD_UPDATE_gc - Force Update

  • TCE_CMD_RESTART_gc - Force Restart

  • TCE_CMD_RESET_gc - Force Hard Reset

Returns:

None.

TCE0_StandBySleep()

void TCE0_StandBySleep (bool state)

Enables/disables the Run-in-Standby mode (RUNSTBY register) for the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
bool
state:
  • True - Enables Sleep.

  • False - Disables Sleep.

Returns:

None.

TCE0_Start()

void TCE0_Start (void )

Starts the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

TCE0_StatusGet()

TCE0_status_t TCE0_StatusGet (void )

Returns the status of the TCE0 module.

Parameters:
None.
Returns:
enum TCE_status_t:
  • TCE_STATUS_IDLE = 0 - The timer is not running

  • TCE_STATUS_RUNNING = 1 - The timer is running

TCE0_Stop()

void TCE0_Stop (void )

Stops the TCE0.

Precondition:

Initialize the TCE0 with TCE0_Initialize() before calling this API.

Parameters:
None.
Returns:

None.

Enumeration Type Documentation

TCE0_status_t

enum TCE0_status_t

Lists the possible states of the TCE0.

  • TCE_STATUS_IDLE = 0 - The timer is not running

  • TCE_STATUS_RUNNING = 1 - The timer is running

TCE_STATUS_IDLE
TCE_STATUS_RUNNING

Variable Documentation

TCE0_OVF_isr_cb

TCE0_cb_t TCE0_OVF_isr_cb = NULL[static]

Function pointers that store the callback addresses.

Section: Included files Section: TCE0 Private data

timerActive

volatile bool timerActive = false[static]

Boolean that is true when timer is active.

timerMode

volatile uint8_t timerMode = TCE_WGMODE_FRQ_gc[static]

8-bit variable that replicates TCE_WGMODE_t enum to reflect the active mode.

4.14.7.5 File Documentation

4.14.7.5.1 source/tce0.c File Reference

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/atomic.h>
#include <stddef.h>
#include "tce0.h"

Functions

  • ISR (TCE0_OVF_vect)

    Interrupt Service Routine (ISR) for the overflow (OVF) interrupt.

  • ISR (TCE0_CMP0_vect)

    ISR for the CMP0 interrupt.

  • ISR (TCE0_CMP1_vect)

    ISR for the CMP1 interrupt.

  • ISR (TCE0_CMP2_vect)

    ISR for the CMP2 interrupt.

  • ISR (TCE0_CMP3_vect)

    ISR for the CMP3 interrupt.

  • void TCE0_OverflowCallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 overflow callback.

  • void TCE0_Compare0CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare0 callback.

  • void TCE0_Compare1CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare1 callback.

  • void TCE0_Compare2CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare2 callback.

  • void TCE0_Compare3CallbackRegister (TCE0_cb_t cb)

    Setter function for the TCE0 Capture-Compare3 callback.

  • void TCE0_Initialize (void)

    Initializes the TCE0 module. This routine must be called before other TCE0 APIs.

  • void TCE0_Deinitialize (void)

    Deinitializes the TCE0 module.

  • void TCE0_Start (void)

    Starts the TCE0.

  • void TCE0_Stop (void)

    Stops the TCE0.

  • TCE0_status_t TCE0_StatusGet (void)

    Returns the status of the TCE0 module.

  • void TCE0_ModeSet (TCE_WGMODE_t mode)

    Sets the Wave mode for the TCE0.

  • void TCE0_Interrupts_Enable (uint8_t value)

    Enables the TCE0 OVF, CMP0, CMP1, CMP2 or, CMP3 interrupts.

  • void TCE0_Interrupts_FlagsClear (uint8_t value)

    Clears the interrupt flags for the TCE0.

  • uint8_t TCE0_Interrupts_FlagsGet (void)

    Retrieves the interrupt flag status.

  • void TCE0_Interrupts_Disable (uint8_t value)

    Disables the TCE0 OVF, CMP0, CMP1, CMP2 or, CMP3 interrupts.

  • void TCE0_Event_OutputMode (uint8_t value)

    Controls the Waveform mode on the event output line for the TCE0.

  • void TCE0_Event_InputConfig (uint8_t value)

    Enables the input event for the TCE0.

  • void TCE0_SoftwareCommand (TCE_CMD_t com)

    Enables software control of the Update, Restart and Reset states of the TCE0.

  • void TCE0_StandBySleep (bool state)

    Enables/disables the Run-in-Standby mode (RUNSTBY register) for the TCE0.

  • void TCE0_DebugRun (bool state)

    Enables Debug mode for the TCE0.

  • uint16_t TCE0_CounterGet (void)

    Returns the Count (CNT) register value for the TCE0.

  • void TCE0_CounterSet (uint16_t value)

    Sets the Count (CNT) register value for the TCE0.

  • void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

    Selects the prescaler for the TCE0.

  • void TCE0_Compare0Set (uint16_t value)

    Sets the Compare 0 (CMP0) register value for the TCE0.

  • void TCE0_Compare1Set (uint16_t value)

    Sets the Compare 1 (CMP1) register value for the TCE0.

  • void TCE0_Compare2Set (uint16_t value)

    Sets the Compare 2 (CMP2) register value for the TCE0.

  • void TCE0_Compare3Set (uint16_t value)

    Sets the Compare 3 (CMP3) register value for the TCE0.

  • void TCE0_CompareAllChannelsSet (uint16_t value0, uint16_t value1, uint16_t value2, uint16_t value3)

    Sets all four CMP registers for the TCE0.

  • void TCE0_CompareChannels012Set (uint16_t value0, uint16_t value1, uint16_t value2)

    Sets the CMP0, CMP1 and, CMP2 registers for the TCE0.

  • void TCE0_CompareChannels123Set (uint16_t value1, uint16_t value2, uint16_t value3)

    Sets the CMP1, CMP2, and CMP3 registers for the TCE.

  • void TCE0_CompareAllChannelsBufferedSet (uint16_t value0, uint16_t value1, uint16_t value2, uint16_t value3)

    Sets all four Compare Buffer (CMPBUF) registers for the TCE0.

  • void TCE0_CompareChannels012BufferedSet (uint16_t value0, uint16_t value1, uint16_t value2)

    Sets the Compare 0 Buffer (CMP0BUF), Compare 1 Buffer (CMP1BUF) and, Compare 2 Buffer (CMP2BUF) registers for the TCE0.

  • void TCE0_CompareChannels123BufferedSet (uint16_t value1, uint16_t value2, uint16_t value3)

    Sets the Compare 1 Buffer (CMP1BUF), Compare 2 Buffer (CMP2BUF) and, Compare 3 Buffer (CMP3BUF) registers for the TCE0.

  • void TCE0_OutputsEnable (uint8_t value)

    Enables the Waveform outputs for the four TCE0 channels.

  • void TCE0_OutputsValueSet (uint8_t value)

    Sets the output values for the four TCE0 channels.

  • uint8_t TCE0_OutputsValueGet (void)

    Returns the values of the polarities and outputs for the four TCE0 channels.

  • void TCE0_HighResSet (TCE_HREN_t res)

    Sets the high resolution used for the TCE0.

  • void TCE0_ScaleModeSet (TCE_SCALEMODE_t mode)

    Sets the Scaling mode used for the TCE0.

  • void TCE0_ScaleEnable (bool state)

    Allows for fractional values to be written to the Compare (CMP), Amplitude (AMP) and, Compare Buffer (CMPBUF) registers for TCE0.

  • void TCE0_AmplitudeControlEnable (bool state)

    Allows the use of the AMP and OFFSET registers for the TCE0.

  • void TCE0_AmplitudeSet (uint16_t value)

    Sets the AMP register of the TCE0.

  • uint16_t TCE0_AmplitudeGet (void)

    Returns the value of the AMP register of the TCE0.

  • void TCE0_OffsetSet (uint16_t value)

    Sets the OFFSET register of the TCE0.

  • uint16_t TCE0_OffsetGet (void)

    Returns the value of the OFFSET register of the TCE0.

  • void TCE0_PeriodSet (uint16_t period)

    Sets the Period (PER) register for the TCE0.

  • void TCE0_CountDirectionSet (void)

    Sets the TCE0 to count UP.

  • void TCE0_CountDirectionClear (void)

    Sets the TCE0 to count DOWN.

  • void TCE0_LockUpdateSet (void)

    Sets the Lock Update (LUPD) bit for the TCE0 to 1. This ensures there will be no update on the buffered registers.

  • void TCE0_LockUpdateClear (void)

    Clears the Lock Update bit for the TCE0. This ensures that the buffered registers are updated when an UPDATE condition has occurred.

  • void TCE0_AutoLockUpdateSet (void)

    Sets the Auto-Lock Update (ALUPD) bit for the TCE0 to 1. This ensures that the Lock Update (LUPD) bit in the TCEn.CTRLE register is set and cleared automatically.

  • void TCE0_AutoLockUpdateClear (void)

    Clears the Auto-Lock Update bit for the TCE0. This ensures that the LUPD bit in the TCEn.CTRLE register is not altered by the system.

  • void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

    Sets the value of the CMP0BUF register used in the Pulse-Width Modulation (PWM) mode by the TCE0.

  • void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

    Sets the value of the CMP1BUF register used in PWM mode by the TCE0.

  • void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

    Sets the value of the CMP2BUF register used in PWM mode by the TCE0.

  • void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

    Sets the value of the CMP3BUF register used in PWM mode by the TCE0.

  • void TCE0_PeriodBufferSet (uint16_t value)

    Sets the value of the Period Buffer (PERBUF) register that serves as the buffer for the period register TCE0.PER.

Variable Documentation

TCE0_CMP0_isr_cb

TCE0_cb_t TCE0_CMP0_isr_cb = NULL[static]

TCE0_CMP1_isr_cb

TCE0_cb_t TCE0_CMP1_isr_cb = NULL[static]

TCE0_CMP2_isr_cb

TCE0_cb_t TCE0_CMP2_isr_cb = NULL[static]

TCE0_CMP3_isr_cb

TCE0_cb_t TCE0_CMP3_isr_cb = NULL[static]

4.14.7.5.2 source/tce0.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>

Functions

Macros

  • #define TCE0_PER_US_TO_TICKS(US, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

    Defines the macro associated with the conversion from us(microseconds) to clock increments for setting the period.

  • #define TCE0_PER_MS_TO_TICKS(MS, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(MS)) / (1000.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

    Defines the macro associated with the conversion from ms(milliseconds) to clock increments for setting the period.

  • #define TCE0_PER_S_TO_TICKS(S, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(S)) / (1.0 * (float)(TCE0_PRESCALER)) + 0.5) - 1

    Defines the macro associated with the conversion from s(seconds) to clock increments for setting the period.

  • #define TCE0_CMP_US_TO_TICKS(US, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(US)) / (1000000.0 * (float)(TCE0_PRESCALER)) + 0.5)

    Defines the macro associated with the conversion from us(microseconds) to clock increments for setting the compare registers.

  • #define TCE0_CMP_MS_TO_TICKS(MS, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(MS)) / (1000.0 * (float)(TCE0_PRESCALER)) + 0.5)

    Defines the macro associated with the conversion from ms(milliseconds) to clock increments for setting the compare registers.

  • #define TCE0_CMP_S_TO_TICKS(S, F_CLOCK, TCE0_PRESCALER) (uint16_t)(((float)(F_CLOCK) * (float)(S)) / (1.0 * (float)(TCE0_PRESCALER)) + 0.5)

    Defines the macro associated with the conversion from s(seconds) to clock increments for setting the compare registers.

  • #define TCE0_HZ_TO_CLOCKS_FREQUENCYMODE(HZ, F_CLOCK, TCE0_PRESCALER) (uint16_t)((float)(F_CLOCK) / (2 * (float)(HZ) * (float)(TCE0_PRESCALER)) - 1)

    Defines the macro associated with the conversion from Hz(Hertz) to clock increments. Used in Frequency mode.

Typedefs

  • typedef void(* TCE0_cb_t) (void)

    Pointer to a function to be used as a callback handler when an overflow interrupt event occurs.

Detailed Description

Timer/Counter E Embedded Driver API Header File