3.14.7 16-bit Timer/Counter E with PWM

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

3.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.

3.14.7.2 Supported Device Families

AVR® EB

3.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.

3.14.7.4 Module Documentation

3.14.7.4.1 Timer/Counter Type E (TCE)

Module description

Version:

TCE0 Driver Version 1.0.1

Copyright:

© 2024 Microchip Technology Inc. and its subsidiaries.

Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. You're responsible for complying with 3rd party license terms applicable to your use of 3rd party software (including open source software) that may accompany Microchip software.

SOFTWARE IS "AS IS." NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

Typedefs
  • typedef void(* TCE0_cb_t) (void)

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

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

    Converts from microseconds to clock increments for setting the period.

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

    Converts from milliseconds to clock increments for setting the period.

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

    Converts from seconds to clock increments for setting the period.

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

    Converts from microseconds to clock increments for setting the compare registers.

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

    Converts from milliseconds to clock increments for setting the compare registers.

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

    Converts from seconds to clock increments for setting the compare registers.

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

    Converts from hertz to clock increments.

Functions
  • ISR(TCE0_OVF_vect)

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

  • ISR(TCE0_CMP0_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 0 (CMP0) interrupt.

  • ISR(TCE0_CMP1_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 1 (CMP1) interrupt.

  • ISR(TCE0_CMP2_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 2 (CMP2) interrupt.

  • ISR(TCE0_CMP3_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 3 (CMP3) interrupt.

  • void TCE0_OverflowCallbackRegister (TCE0_cb_t callback)

    Sets the Overflow (OVF) interrupt callback for the TCE0 module.

  • void TCE0_Compare0CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 0 (CMP0) interrupt callback for the TCE0 module.

  • void TCE0_Compare1CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 1 (CMP1) interrupt callback for the TCE0 module.

  • void TCE0_Compare2CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 2 (CMP2) interrupt callback for the TCE0 module.

  • void TCE0_Compare3CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 3 (CMP3) interrupt callback for the TCE0 module.

  • void TCE0_Initialize (void)

    Initializes the TCE0 module.

  • void TCE0_Deinitialize (void)

    Deinitializes the TCE0 module.

  • void TCE0_Start (void)

    Starts the TCE0 module.

  • void TCE0_Stop (void)

    Stops the TCE0 module.

  • TCE0_status_t TCE0_StatusGet (void)

    Returns the status of the TCE0 module.

  • void TCE0_ModeSet (TCE_WGMODE_t mode)

    Sets the Waveform Generation mode for the TCE0 module.

  • void TCE0_Interrupts_Enable (uint8_t interrupts)

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

  • void TCE0_Interrupts_FlagsClear (uint8_t interrupts)

    Clears the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

  • uint8_t TCE0_Interrupts_FlagsGet (void)

    Returns the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

  • void TCE0_Interrupts_Disable (uint8_t interrupts)

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

  • void TCE0_Event_OutputMode (uint8_t mode)

    Sets the event output mode to Pulse or Waveform.

  • void TCE0_Event_InputConfig (uint8_t value)

    Configures the input events for the TCE0 module.

  • void TCE0_SoftwareCommand (TCE_CMD_t command)

    Sends a software command to the TCE0 module.

  • void TCE0_StandBySleep (bool state)

    Enables or disables the Run in Standby mode for the TCE0 module.

  • void TCE0_DebugRun (bool state)

    Enables or disables the Run in Debug mode for the TCE0 module.

  • uint16_t TCE0_CounterGet (void)

    Returns the Counter register value for the TCE0 module.

  • void TCE0_CounterSet (uint16_t value)

    Sets the Counter register value for the TCE0 module.

  • void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

    Sets the clock prescaler for the TCE0 module.

  • void TCE0_Compare0Set (uint16_t value)

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

  • void TCE0_Compare1Set (uint16_t value)

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

  • void TCE0_Compare2Set (uint16_t value)

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

  • void TCE0_Compare3Set (uint16_t value)

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

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

    Sets all the Compare (CMPn) registers for the TCE0 module.

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

    Sets the Compare Channel 0 (CMP0), Compare Channel 1 (CMP1), and Compare Channel 2 (CMP2) registers for the TCE0 module.

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

    Sets the Compare Channel 1 (CMP1), Compare Channel 2 (CMP2), and Compare Channel 3 (CMP3) registers for the TCE0 module.

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

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

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

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

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

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

  • void TCE0_OutputsEnable (uint8_t value)

    Enable the Waveform Outputs for the TCE0 module.

  • void TCE0_OutputsValueSet (uint8_t value)

    Sets the Waveform Outputs for the TCE0 module.

  • uint8_t TCE0_OutputsValueGet (void)

    Returns the Waveform Outputs value for the TCE0 module.

  • void TCE0_OutputPolaritySet (uint8_t value)

    Sets the Waveform Outputs Polarity for the TCE0 module.

  • uint8_t TCE0_OutputPolarityGet (void)

    Returns the Waveform Outputs Polarity for the TCE0 module.

  • void TCE0_HighResSet (TCE_HREN_t resolution)

    Sets the High Resolution mode for the TCE0 module.

  • void TCE0_ScaleModeSet (TCE_SCALEMODE_t mode)

    Sets the Scaling mode used for the TCE0 module.

  • void TCE0_ScaleEnable (bool state)

    Enables or disables the Scaling for the TCE0 module.

  • void TCE0_AmplitudeControlEnable (bool state)

    Enables or disables the Amplitude Control for the TCE0 module.

  • void TCE0_AmplitudeSet (uint16_t value)

    Sets the Amplitude (AMP) register of the TCE0 module.

  • uint16_t TCE0_AmplitudeGet (void)

    Returns the value of the Amplitude (AMP) register of the TCE0 module.

  • void TCE0_OffsetSet (uint16_t value)

    Sets the Offset (OFFSET) register for the TCE0 module.

  • uint16_t TCE0_OffsetGet (void)

    Returns the value of the Offset (OFFSET) register for the TCE0 module.

  • void TCE0_PeriodSet (uint16_t period)

    Sets the Period (PER) register for the TCE0 module.

  • uint16_t TCE0_PeriodGet (void)

    Returns the value of the Period (PER) register for the TCE0 module.

  • void TCE0_CountDirectionSet (void)

    Sets the counting direction to UP for the TCE0 module.

  • void TCE0_CountDirectionClear (void)

    Sets the counting direction to DOWN for the TCE0 module.

  • void TCE0_LockUpdateSet (void)

    Sets the Lock Update (LUPD) bit for the TCE0 module.

  • void TCE0_LockUpdateClear (void)

    Clears the Lock Update (LUPD) bit for the TCE0 module.

  • void TCE0_AutoLockUpdateSet (void)

    Sets the Auto-Lock Update (ALUPD) bit for the TCE0 module.

  • void TCE0_AutoLockUpdateClear (void)

    Clears the Auto-Lock Update (ALUPD) bit for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

    Sets the Compare Buffer Channel 0 (CMP0BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

    Sets the Compare Buffer Channel 1 (CMP1BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

    Sets the Compare Buffer Channel 2 (CMP2BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

    Sets the Compare Buffer Channel 3 (CMP3BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PeriodBufferSet (uint16_t value)

    Sets the Persiod Buffer (PERBUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • uint16_t TCE0_MaxCountGet (void)

    Returns the maximum counter value for the TCE0 module.

  • void TCE0_Tasks (void)

    Runs the callback functions in Polling mode.

Variables
  • static TCE0_cb_t TCE0_OVF_isr_cb = NULL

    Function pointer to the Overflow (OVF) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP0_isr_cb = NULL

    Function pointer to the Compare Channel 0 (CMP0) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP1_isr_cb = NULL

    Function pointer to the Compare Channel 1 (CMP1) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP2_isr_cb = NULL

    Function pointer to the Compare Channel 2 (CMP2) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP3_isr_cb = NULL

    Function pointer to the Compare Channel 3 (CMP3) interrupt callback function.

  • static volatile bool timerActive = false

    Mirrors the CTRLA.ENABLE bit of the TCE0 module.

  • static volatile uint8_t timerMode = TCE_WGMODE_FRQ_gc

    Mirrors the CTRLB.WGMODE bits of the TCE0 module.

Definition Documentation

TCE0_CMP_MS_TO_TICKS

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

Converts from milliseconds to clock increments for setting the compare registers.

TCE0_CMP_S_TO_TICKS

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

Converts from seconds to clock increments for setting the compare registers.

TCE0_CMP_US_TO_TICKS

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

Converts from microseconds to clock increments for setting the compare registers.

TCE0_HZ_TO_CLOCKS_FREQUENCYMODE

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

Converts from hertz to clock increments.

Note:

Used in Frequency mode.

TCE0_PER_MS_TO_TICKS

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

Converts from milliseconds to clock increments for setting the period.

TCE0_PER_S_TO_TICKS

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

Converts from seconds to clock increments for setting the period.

TCE0_PER_US_TO_TICKS

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

Converts from 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 interrupt event occurs.

Function Documentation

ISR(TCE0_CMP0_vect)

ISR(TCE0_CMP0_vect)

Interrupt Service Routine (ISR) for the Compare Channel 0 (CMP0) interrupt.

Parameters:
None.
Returns:

None.

ISR(TCE0_CMP1_vect)

ISR(TCE0_CMP1_vect)

Interrupt Service Routine (ISR) for the Compare Channel 1 (CMP1) interrupt.

Parameters:
None.
Returns:

None.

ISR(TCE0_CMP2_vect)

ISR(TCE0_CMP2_vect)

Interrupt Service Routine (ISR) for the Compare Channel 2 (CMP2) interrupt.

Parameters:
None.
Returns:

None.

ISR(TCE0_CMP3_vect)

ISR(TCE0_CMP3_vect)

Interrupt Service Routine (ISR) for the Compare Channel 3 (CMP3) interrupt.

Parameters:
None.
Returns:

None.

ISR(TCE0_OVF_vect)

ISR(TCE0_OVF_vect)

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

Parameters:
None.
Returns:

None.

TCE0_AmplitudeControlEnable()

void TCE0_AmplitudeControlEnable (bool state)

Enables or disables the Amplitude Control for the TCE0 module.

Parameters:
in state
Enable or disable:
  • true - Enable Amplitude Control

  • false - Disable Amplitude Control

Returns:

None.

TCE0_AmplitudeGet()

uint16_t TCE0_AmplitudeGet (void )

Returns the value of the Amplitude (AMP) register of the TCE0 module.

Parameters:
None.
Returns:

Amplitude value

TCE0_AmplitudeSet()

void TCE0_AmplitudeSet (uint16_t value)

Sets the Amplitude (AMP) register of the TCE0 module.

Parameters:
in value

Amplitude value

Returns:

None.

TCE0_AutoLockUpdateClear()

void TCE0_AutoLockUpdateClear (void )

Clears the Auto-Lock Update (ALUPD) bit for the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_AutoLockUpdateSet()

void TCE0_AutoLockUpdateSet (void )

Sets the Auto-Lock Update (ALUPD) bit for the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_Compare0CallbackRegister()

void TCE0_Compare0CallbackRegister (TCE0_cb_t callback)

Sets the Compare Channel 0 (CMP0) interrupt callback for the TCE0 module.

Parameters:
in callback

Pointer to custom callback

Returns:

None.

TCE0_Compare0Set()

void TCE0_Compare0Set (uint16_t value)

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

Parameters:
in value

Compare Channel 0 value

Returns:

None.

TCE0_Compare1CallbackRegister()

void TCE0_Compare1CallbackRegister (TCE0_cb_t callback)

Sets the Compare Channel 1 (CMP1) interrupt callback for the TCE0 module.

Parameters:
in callback

Pointer to custom callback

Returns:

None.

TCE0_Compare1Set()

void TCE0_Compare1Set (uint16_t value)

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

Parameters:
in value

Compare Channel 1 value

Returns:

None.

TCE0_Compare2CallbackRegister()

void TCE0_Compare2CallbackRegister (TCE0_cb_t callback)

Sets the Compare Channel 2 (CMP2) interrupt callback for the TCE0 module.

Parameters:
in callback

Pointer to custom callback

Returns:

None.

TCE0_Compare2Set()

void TCE0_Compare2Set (uint16_t value)

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

Parameters:
in value

Compare Channel 2 value

Returns:

None.

TCE0_Compare3CallbackRegister()

void TCE0_Compare3CallbackRegister (TCE0_cb_t callback)

Sets the Compare Channel 3 (CMP3) interrupt callback for the TCE0 module.

Parameters:
in callback

Pointer to custom callback

Returns:

None.

TCE0_Compare3Set()

void TCE0_Compare3Set (uint16_t value)

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

Parameters:
in value

Compare Channel 3 value

Returns:

None.

TCE0_CompareAllChannelsBufferedSet()

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

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

Parameters:
in value0

Compare Buffer Channel 0 value

in value1

Compare Buffer Channel 1 value

in value2

Compare Buffer Channel 2 value

in value3

Compare Buffer Channel 3 value

Returns:

None.

TCE0_CompareAllChannelsSet()

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

Sets all the Compare (CMPn) registers for the TCE0 module.

Parameters:
in value0

Compare Channel 0 value

in value1

Compare Channel 1 value

in value2

Compare Channel 2 value

in value3

Compare Channel 3 value

Returns:

None.

TCE0_CompareChannels012BufferedSet()

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

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

Parameters:
in value0

Compare Buffer Channel 0 value

in value1

Compare Buffer Channel 1 value

in value2

Compare Buffer Channel 2 value

Returns:

None.

TCE0_CompareChannels012Set()

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

Sets the Compare Channel 0 (CMP0), Compare Channel 1 (CMP1), and Compare Channel 2 (CMP2) registers for the TCE0 module.

Parameters:
in value0

Compare Channel 0 value

in value1

Compare Channel 1 value

in value2

Compare Channel 2 value

Returns:

None.

TCE0_CompareChannels123BufferedSet()

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

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

Parameters:
in value1

Compare Buffer Channel 1 value

in value2

Compare Buffer Channel 2 value

in value3

Compare Buffer Channel 3 value

Returns:

None.

TCE0_CompareChannels123Set()

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

Sets the Compare Channel 1 (CMP1), Compare Channel 2 (CMP2), and Compare Channel 3 (CMP3) registers for the TCE0 module.

Parameters:
in value1

Compare Channel 1 value

in value2

Compare Channel 2 value

in value3

Compare Channel 3 value

Returns:

None.

TCE0_CountDirectionClear()

void TCE0_CountDirectionClear (void )

Sets the counting direction to DOWN for the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_CountDirectionSet()

void TCE0_CountDirectionSet (void )

Sets the counting direction to UP for the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_CounterGet()

uint16_t TCE0_CounterGet (void )

Returns the Counter register value for the TCE0 module.

Parameters:
None.
Returns:

Counter value

TCE0_CounterSet()

void TCE0_CounterSet (uint16_t value)

Sets the Counter register value for the TCE0 module.

Parameters:
in value

Counter value

Returns:

None.

TCE0_DebugRun()

void TCE0_DebugRun (bool state)

Enables or disables the Run in Debug mode for the TCE0 module.

Parameters:
in state
Enable or disable:
  • 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.

Parameters:
None.
Returns:

None.

TCE0_Event_InputConfig()

void TCE0_Event_InputConfig (uint8_t value)

Configures the input events for the TCE0 module.

Parameters:
in value

Input events configuration

Returns:

None.

TCE0_Event_OutputMode()

void TCE0_Event_OutputMode (uint8_t mode)

Sets the event output mode to Pulse or Waveform.

Parameters:
in mode

Output mode

Returns:

None.

TCE0_HighResSet()

void TCE0_HighResSet (TCE_HREN_t resolution)

Sets the High Resolution mode for the TCE0 module.

Parameters:
in resolution
Resolution:
  • TCE_HREN_OFF_gc - High Resolution Disable

  • TCE_HREN_4X_gc - Resolution increased by 4 (two bits)

  • TCE_HREN_8X_gc - Resolution increased by 8 (three bits)

Returns:

None.

TCE0_Initialize()

void TCE0_Initialize (void )

Initializes the TCE0 module.

Note:

This routine must be called before any other TCE0 APIs.

Parameters:
None.
Returns:

None.

TCE0_Interrupts_Disable()

void TCE0_Interrupts_Disable (uint8_t interrupts)

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

Parameters:
in interrupts

Interrupt(s) to be disabled.

Returns:

None.

TCE0_Interrupts_Enable()

void TCE0_Interrupts_Enable (uint8_t interrupts)

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

Parameters:
in interrupts

Interrupt(s) to be enabled

Returns:

None.

TCE0_Interrupts_FlagsClear()

void TCE0_Interrupts_FlagsClear (uint8_t interrupts)

Clears the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

Parameters:
in interrupts

Interrupt(s) flags to be cleared

Returns:

None.

TCE0_Interrupts_FlagsGet()

uint8_t TCE0_Interrupts_FlagsGet (void )

Returns the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

Parameters:
None.
Returns:
Interrupt flag status:
  • Bit 0 is set by the the OVF interrupt

  • Bit 4 is set by the 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 (LUPD) bit for the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_LockUpdateSet()

void TCE0_LockUpdateSet (void )

Sets the Lock Update (LUPD) bit for the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_MaxCountGet()

uint16_t TCE0_MaxCountGet (void )

Returns the maximum counter value for the TCE0 module.

Parameters:
None.
Returns:

Maximum counter value

TCE0_ModeSet()

void TCE0_ModeSet (TCE_WGMODE_t mode)

Sets the Waveform Generation mode for the TCE0 module.

Parameters:
in mode
Operation mode:
  • TCE_WGMODE_NORMAL_gc - Normal mode

  • TCE_WGMODE_FRQ_gc - Frequency Generation mode

  • TCE_WGMODE_SINGLESLOPE_gc - Single-Slope PWM mode

  • TCE_WGMODE_DSTOP_gc - Dual-Slope PWM, overflow on TOP mode

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

  • TCE_WGMODE_DSBOTTOM_gc - Dual-Slope PWM, overflow on BOTTOM mode

Returns:

None.

TCE0_OffsetGet()

uint16_t TCE0_OffsetGet (void )

Returns the value of the Offset (OFFSET) register for the TCE0 module.

Parameters:
None.
Returns:

Offset value

TCE0_OffsetSet()

void TCE0_OffsetSet (uint16_t value)

Sets the Offset (OFFSET) register for the TCE0 module.

Parameters:
in value

Offset value

Returns:

None.

TCE0_OutputPolarityGet()

uint8_t TCE0_OutputPolarityGet (void )

Returns the Waveform Outputs Polarity for the TCE0 module.

Parameters:
None.
Returns:
Waveform Outputs Polarity:
  • Bit 4 determines the polarity of the CMP0 output

  • Bit 5 determines the polarity of the CMP1 output

  • Bit 6 determines the polarity of the CMP2 output

  • Bit 7 determines the polarity of the CMP3 output

TCE0_OutputPolaritySet()

void TCE0_OutputPolaritySet (uint8_t value)

Sets the Waveform Outputs Polarity for the TCE0 module.

Parameters:
in value

Bitmask value for the channels

Returns:

None.

TCE0_OutputsEnable()

void TCE0_OutputsEnable (uint8_t value)

Enable the Waveform Outputs for the TCE0 module.

Parameters:
in value

Bitmask value for the channels

Returns:

None.

TCE0_OutputsValueGet()

uint8_t TCE0_OutputsValueGet (void )

Returns the Waveform Outputs value for the TCE0 module.

Parameters:
None.
Returns:
Waveform Outputs Value:
  • Bit 0 is set by the the CMP0 output

  • Bit 1 is set by the the CMP1 output

  • Bit 2 is set by the the CMP2 output

  • Bit 3 is set by the the CMP3 output

TCE0_OutputsValueSet()

void TCE0_OutputsValueSet (uint8_t value)

Sets the Waveform Outputs for the TCE0 module.

Parameters:
in value

Bitmask value for the channels

Returns:

None.

TCE0_OverflowCallbackRegister()

void TCE0_OverflowCallbackRegister (TCE0_cb_t callback)

Sets the Overflow (OVF) interrupt callback for the TCE0 module.

Parameters:
in callback

Pointer to custom callback

Returns:

None.

TCE0_PeriodBufferSet()

void TCE0_PeriodBufferSet (uint16_t value)

Sets the Persiod Buffer (PERBUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

Parameters:
in value

Period buffer value

Returns:

None.

TCE0_PeriodGet()

uint16_t TCE0_PeriodGet (void )

Returns the value of the Period (PER) register for the TCE0 module.

Parameters:
None.
Returns:

Period value

TCE0_PeriodSet()

void TCE0_PeriodSet (uint16_t period)

Sets the Period (PER) register for the TCE0 module.

Parameters:
in period

Period value

Returns:

None.

TCE0_PrescalerSet()

void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

Sets the clock prescaler for the TCE0 module.

Parameters:
in prescaler
Clock prescaler
  • DIV1 - Direct clock source

  • DIV2 - Clock frequency divided by 2

  • DIV4 - Clock frequency divided by 4

  • DIV8 - Clock frequency divided by 8

  • DIV16 - Clock frequency divided by 16

  • DIV64 - Clock frequency divided by 64

  • DIV256 - Clock frequency divided by 256

  • DIV1024 - Clock frequency divided by 1024

Returns:

None.

TCE0_PWM_BufferedDutyCycle0Set()

void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

Sets the Compare Buffer Channel 0 (CMP0BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

Parameters:
in value

Compare Buffer Channel 0 value

Returns:

None.

TCE0_PWM_BufferedDutyCycle1Set()

void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

Sets the Compare Buffer Channel 1 (CMP1BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

Parameters:
in value

Compare Buffer Channel 1 value

Returns:

None.

TCE0_PWM_BufferedDutyCycle2Set()

void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

Sets the Compare Buffer Channel 2 (CMP2BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

Parameters:
in value

Compare Buffer Channel 2 value

Returns:

None.

TCE0_PWM_BufferedDutyCycle3Set()

void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

Sets the Compare Buffer Channel 3 (CMP3BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

Parameters:
in value

Compare Buffer Channel 3 value

Returns:

None.

TCE0_ScaleEnable()

void TCE0_ScaleEnable (bool state)

Enables or disables the Scaling for the TCE0 module.

Parameters:
in state
Enable or disable:
  • 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 module.

Parameters:
in mode
Scale mode:
  • TCE_SCALEMODE_CENTER_gc - CMPn scaled from CENTER (50% duty cycle)

  • TCE_SCALEMODE_BOTTOM_gc - CMPn scaled from BOTTOM (0% duty cycle)

  • TCE_SCALEMODE_TOP_gc - CMPn scaled from TOP (100% duty cycle)

  • TCE_SCALEMODE_TOPBOTTOM_gc - CMPn scaled from TOP or BOTTOM depending on the CMPn value

Returns:

None.

TCE0_SoftwareCommand()

void TCE0_SoftwareCommand (TCE_CMD_t command)

Sends a software command to the TCE0 module.

Parameters:
in command
Software command.
  • 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 or disables the Run in Standby mode for the TCE0 module.

Parameters:
in state
Enable or disable:
  • true - Enables Sleep

  • false - Disables Sleep

Returns:

None.

TCE0_Start()

void TCE0_Start (void )

Starts the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_StatusGet()

TCE0_status_t TCE0_StatusGet (void )

Returns the status of the TCE0 module.

Parameters:
None.
Returns:

Status of the TCE0 module

Return values:
TCE_STATUS_IDLE

The timer is not running

TCE_STATUS_RUNNING

The timer is running

TCE0_Stop()

void TCE0_Stop (void )

Stops the TCE0 module.

Parameters:
None.
Returns:

None.

TCE0_Tasks()

void TCE0_Tasks (void )

Runs the callback functions in Polling mode.

Parameters:
None.
Returns:

None.

Enumeration Type Documentation

TCE0_status_t

enum TCE0_status_t

Lists the possible states of the TCE0 module.

TCE_STATUS_IDLE

The timer is not running

TCE_STATUS_RUNNING

The timer is running

Variable Documentation

TCE0_CMP0_isr_cb

TCE0_cb_t TCE0_CMP0_isr_cb = NULL[static]

Function pointer to the Compare Channel 0 (CMP0) interrupt callback function.

TCE0_CMP1_isr_cb

TCE0_cb_t TCE0_CMP1_isr_cb = NULL[static]

Function pointer to the Compare Channel 1 (CMP1) interrupt callback function.

TCE0_CMP2_isr_cb

TCE0_cb_t TCE0_CMP2_isr_cb = NULL[static]

Function pointer to the Compare Channel 2 (CMP2) interrupt callback function.

TCE0_CMP3_isr_cb

TCE0_cb_t TCE0_CMP3_isr_cb = NULL[static]

Function pointer to the Compare Channel 3 (CMP3) interrupt callback function.

TCE0_OVF_isr_cb

TCE0_cb_t TCE0_OVF_isr_cb = NULL[static]

Function pointer to the Overflow (OVF) interrupt callback function.

timerActive

volatile bool timerActive = false[static]

Mirrors the CTRLA.ENABLE bit of the TCE0 module.

timerMode

volatile uint8_t timerMode = TCE_WGMODE_FRQ_gc[static]

Mirrors the CTRLB.WGMODE bits of the TCE0 module.

3.14.7.5 File Documentation

3.14.7.5.1 source/tce0.c File Reference

Timer/Counter Type E Driver API Source File.

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

Functions

  • ISR(TCE0_OVF_vect)

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

  • ISR(TCE0_CMP0_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 0 (CMP0) interrupt.

  • ISR(TCE0_CMP1_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 1 (CMP1) interrupt.

  • ISR(TCE0_CMP2_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 2 (CMP2) interrupt.

  • ISR(TCE0_CMP3_vect)

    Interrupt Service Routine (ISR) for the Compare Channel 3 (CMP3) interrupt.

  • void TCE0_OverflowCallbackRegister (TCE0_cb_t callback)

    Sets the Overflow (OVF) interrupt callback for the TCE0 module.

  • void TCE0_Compare0CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 0 (CMP0) interrupt callback for the TCE0 module.

  • void TCE0_Compare1CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 1 (CMP1) interrupt callback for the TCE0 module.

  • void TCE0_Compare2CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 2 (CMP2) interrupt callback for the TCE0 module.

  • void TCE0_Compare3CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 3 (CMP3) interrupt callback for the TCE0 module.

  • void TCE0_Initialize (void)

    Initializes the TCE0 module.

  • void TCE0_Deinitialize (void)

    Deinitializes the TCE0 module.

  • void TCE0_Start (void)

    Starts the TCE0 module.

  • void TCE0_Stop (void)

    Stops the TCE0 module.

  • TCE0_status_t TCE0_StatusGet (void)

    Returns the status of the TCE0 module.

  • void TCE0_ModeSet (TCE_WGMODE_t mode)

    Sets the Waveform Generation mode for the TCE0 module.

  • void TCE0_Interrupts_Enable (uint8_t interrupts)

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

  • void TCE0_Interrupts_FlagsClear (uint8_t interrupts)

    Clears the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

  • uint8_t TCE0_Interrupts_FlagsGet (void)

    Returns the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

  • void TCE0_Interrupts_Disable (uint8_t interrupts)

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

  • void TCE0_Event_OutputMode (uint8_t mode)

    Sets the event output mode to Pulse or Waveform.

  • void TCE0_Event_InputConfig (uint8_t value)

    Configures the input events for the TCE0 module.

  • void TCE0_SoftwareCommand (TCE_CMD_t command)

    Sends a software command to the TCE0 module.

  • void TCE0_StandBySleep (bool state)

    Enables or disables the Run in Standby mode for the TCE0 module.

  • void TCE0_DebugRun (bool state)

    Enables or disables the Run in Debug mode for the TCE0 module.

  • uint16_t TCE0_CounterGet (void)

    Returns the Counter register value for the TCE0 module.

  • void TCE0_CounterSet (uint16_t value)

    Sets the Counter register value for the TCE0 module.

  • void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

    Sets the clock prescaler for the TCE0 module.

  • void TCE0_Compare0Set (uint16_t value)

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

  • void TCE0_Compare1Set (uint16_t value)

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

  • void TCE0_Compare2Set (uint16_t value)

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

  • void TCE0_Compare3Set (uint16_t value)

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

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

    Sets all the Compare (CMPn) registers for the TCE0 module.

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

    Sets the Compare Channel 0 (CMP0), Compare Channel 1 (CMP1), and Compare Channel 2 (CMP2) registers for the TCE0 module.

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

    Sets the Compare Channel 1 (CMP1), Compare Channel 2 (CMP2), and Compare Channel 3 (CMP3) registers for the TCE0 module.

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

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

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

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

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

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

  • void TCE0_OutputsEnable (uint8_t value)

    Enable the Waveform Outputs for the TCE0 module.

  • void TCE0_OutputsValueSet (uint8_t value)

    Sets the Waveform Outputs for the TCE0 module.

  • uint8_t TCE0_OutputsValueGet (void)

    Returns the Waveform Outputs value for the TCE0 module.

  • void TCE0_OutputPolaritySet (uint8_t value)

    Sets the Waveform Outputs Polarity for the TCE0 module.

  • uint8_t TCE0_OutputPolarityGet (void)

    Returns the Waveform Outputs Polarity for the TCE0 module.

  • void TCE0_HighResSet (TCE_HREN_t resolution)

    Sets the High Resolution mode for the TCE0 module.

  • void TCE0_ScaleModeSet (TCE_SCALEMODE_t mode)

    Sets the Scaling mode used for the TCE0 module.

  • void TCE0_ScaleEnable (bool state)

    Enables or disables the Scaling for the TCE0 module.

  • void TCE0_AmplitudeControlEnable (bool state)

    Enables or disables the Amplitude Control for the TCE0 module.

  • void TCE0_AmplitudeSet (uint16_t value)

    Sets the Amplitude (AMP) register of the TCE0 module.

  • uint16_t TCE0_AmplitudeGet (void)

    Returns the value of the Amplitude (AMP) register of the TCE0 module.

  • void TCE0_OffsetSet (uint16_t value)

    Sets the Offset (OFFSET) register for the TCE0 module.

  • uint16_t TCE0_OffsetGet (void)

    Returns the value of the Offset (OFFSET) register for the TCE0 module.

  • void TCE0_PeriodSet (uint16_t period)

    Sets the Period (PER) register for the TCE0 module.

  • uint16_t TCE0_PeriodGet (void)

    Returns the value of the Period (PER) register for the TCE0 module.

  • void TCE0_CountDirectionSet (void)

    Sets the counting direction to UP for the TCE0 module.

  • void TCE0_CountDirectionClear (void)

    Sets the counting direction to DOWN for the TCE0 module.

  • void TCE0_LockUpdateSet (void)

    Sets the Lock Update (LUPD) bit for the TCE0 module.

  • void TCE0_LockUpdateClear (void)

    Clears the Lock Update (LUPD) bit for the TCE0 module.

  • void TCE0_AutoLockUpdateSet (void)

    Sets the Auto-Lock Update (ALUPD) bit for the TCE0 module.

  • void TCE0_AutoLockUpdateClear (void)

    Clears the Auto-Lock Update (ALUPD) bit for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

    Sets the Compare Buffer Channel 0 (CMP0BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

    Sets the Compare Buffer Channel 1 (CMP1BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

    Sets the Compare Buffer Channel 2 (CMP2BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

    Sets the Compare Buffer Channel 3 (CMP3BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PeriodBufferSet (uint16_t value)

    Sets the Persiod Buffer (PERBUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • uint16_t TCE0_MaxCountGet (void)

    Returns the maximum counter value for the TCE0 module.

  • void TCE0_Tasks (void)

    Runs the callback functions in Polling mode.

Variables

  • static TCE0_cb_t TCE0_OVF_isr_cb = NULL

    Function pointer to the Overflow (OVF) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP0_isr_cb = NULL

    Function pointer to the Compare Channel 0 (CMP0) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP1_isr_cb = NULL

    Function pointer to the Compare Channel 1 (CMP1) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP2_isr_cb = NULL

    Function pointer to the Compare Channel 2 (CMP2) interrupt callback function.

  • static TCE0_cb_t TCE0_CMP3_isr_cb = NULL

    Function pointer to the Compare Channel 3 (CMP3) interrupt callback function.

  • static volatile bool timerActive = false

    Mirrors the CTRLA.ENABLE bit of the TCE0 module.

  • static volatile uint8_t timerMode = TCE_WGMODE_FRQ_gc

    Mirrors the CTRLB.WGMODE bits of the TCE0 module.

Detailed Description

Timer/Counter Type E Driver API Source File.

Version:

TCE0 Driver Version 1.0.1

Copyright:

© 2024 Microchip Technology Inc. and its subsidiaries.

Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. You're responsible for complying with 3rd party license terms applicable to your use of 3rd party software (including open source software) that may accompany Microchip software.

SOFTWARE IS "AS IS." NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

3.14.7.5.2 source/tce0.h File Reference

Timer/Counter Type E Driver API Header File.

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

Functions

  • void TCE0_OverflowCallbackRegister (TCE0_cb_t callback)

    Sets the Overflow (OVF) interrupt callback for the TCE0 module.

  • void TCE0_Compare0CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 0 (CMP0) interrupt callback for the TCE0 module.

  • void TCE0_Compare1CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 1 (CMP1) interrupt callback for the TCE0 module.

  • void TCE0_Compare2CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 2 (CMP2) interrupt callback for the TCE0 module.

  • void TCE0_Compare3CallbackRegister (TCE0_cb_t callback)

    Sets the Compare Channel 3 (CMP3) interrupt callback for the TCE0 module.

  • void TCE0_Initialize (void)

    Initializes the TCE0 module.

  • void TCE0_Deinitialize (void)

    Deinitializes the TCE0 module.

  • void TCE0_Start (void)

    Starts the TCE0 module.

  • void TCE0_Stop (void)

    Stops the TCE0 module.

  • TCE0_status_t TCE0_StatusGet (void)

    Returns the status of the TCE0 module.

  • void TCE0_ModeSet (TCE_WGMODE_t mode)

    Sets the Waveform Generation mode for the TCE0 module.

  • void TCE0_Interrupts_Enable (uint8_t interrupts)

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

  • void TCE0_Interrupts_FlagsClear (uint8_t interrupts)

    Clears the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

  • uint8_t TCE0_Interrupts_FlagsGet (void)

    Returns the OVF, CMP0, CMP1, CMP2, or CMP3 interrupt flags of the TCE0 module.

  • void TCE0_Interrupts_Disable (uint8_t interrupts)

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

  • void TCE0_Event_OutputMode (uint8_t mode)

    Sets the event output mode to Pulse or Waveform.

  • void TCE0_Event_InputConfig (uint8_t value)

    Configures the input events for the TCE0 module.

  • void TCE0_SoftwareCommand (TCE_CMD_t command)

    Sends a software command to the TCE0 module.

  • void TCE0_StandBySleep (bool state)

    Enables or disables the Run in Standby mode for the TCE0 module.

  • void TCE0_DebugRun (bool state)

    Enables or disables the Run in Debug mode for the TCE0 module.

  • uint16_t TCE0_CounterGet (void)

    Returns the Counter register value for the TCE0 module.

  • void TCE0_CounterSet (uint16_t value)

    Sets the Counter register value for the TCE0 module.

  • void TCE0_PrescalerSet (TCE_CLKSEL_t prescaler)

    Sets the clock prescaler for the TCE0 module.

  • void TCE0_Compare0Set (uint16_t value)

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

  • void TCE0_Compare1Set (uint16_t value)

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

  • void TCE0_Compare2Set (uint16_t value)

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

  • void TCE0_Compare3Set (uint16_t value)

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

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

    Sets all the Compare (CMPn) registers for the TCE0 module.

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

    Sets the Compare Channel 0 (CMP0), Compare Channel 1 (CMP1), and Compare Channel 2 (CMP2) registers for the TCE0 module.

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

    Sets the Compare Channel 1 (CMP1), Compare Channel 2 (CMP2), and Compare Channel 3 (CMP3) registers for the TCE0 module.

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

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

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

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

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

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

  • void TCE0_OutputsEnable (uint8_t value)

    Enable the Waveform Outputs for the TCE0 module.

  • void TCE0_OutputsValueSet (uint8_t value)

    Sets the Waveform Outputs for the TCE0 module.

  • uint8_t TCE0_OutputsValueGet (void)

    Returns the Waveform Outputs value for the TCE0 module.

  • void TCE0_OutputPolaritySet (uint8_t value)

    Sets the Waveform Outputs Polarity for the TCE0 module.

  • uint8_t TCE0_OutputPolarityGet (void)

    Returns the Waveform Outputs Polarity for the TCE0 module.

  • void TCE0_HighResSet (TCE_HREN_t resolution)

    Sets the High Resolution mode for the TCE0 module.

  • void TCE0_ScaleModeSet (TCE_SCALEMODE_t mode)

    Sets the Scaling mode used for the TCE0 module.

  • void TCE0_ScaleEnable (bool state)

    Enables or disables the Scaling for the TCE0 module.

  • void TCE0_AmplitudeControlEnable (bool state)

    Enables or disables the Amplitude Control for the TCE0 module.

  • void TCE0_AmplitudeSet (uint16_t value)

    Sets the Amplitude (AMP) register of the TCE0 module.

  • uint16_t TCE0_AmplitudeGet (void)

    Returns the value of the Amplitude (AMP) register of the TCE0 module.

  • void TCE0_OffsetSet (uint16_t value)

    Sets the Offset (OFFSET) register for the TCE0 module.

  • uint16_t TCE0_OffsetGet (void)

    Returns the value of the Offset (OFFSET) register for the TCE0 module.

  • void TCE0_PeriodSet (uint16_t period)

    Sets the Period (PER) register for the TCE0 module.

  • uint16_t TCE0_PeriodGet (void)

    Returns the value of the Period (PER) register for the TCE0 module.

  • void TCE0_CountDirectionSet (void)

    Sets the counting direction to UP for the TCE0 module.

  • void TCE0_CountDirectionClear (void)

    Sets the counting direction to DOWN for the TCE0 module.

  • void TCE0_LockUpdateSet (void)

    Sets the Lock Update (LUPD) bit for the TCE0 module.

  • void TCE0_LockUpdateClear (void)

    Clears the Lock Update (LUPD) bit for the TCE0 module.

  • void TCE0_AutoLockUpdateSet (void)

    Sets the Auto-Lock Update (ALUPD) bit for the TCE0 module.

  • void TCE0_AutoLockUpdateClear (void)

    Clears the Auto-Lock Update (ALUPD) bit for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle0Set (uint16_t value)

    Sets the Compare Buffer Channel 0 (CMP0BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle1Set (uint16_t value)

    Sets the Compare Buffer Channel 1 (CMP1BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle2Set (uint16_t value)

    Sets the Compare Buffer Channel 2 (CMP2BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PWM_BufferedDutyCycle3Set (uint16_t value)

    Sets the Compare Buffer Channel 3 (CMP3BUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • void TCE0_PeriodBufferSet (uint16_t value)

    Sets the Persiod Buffer (PERBUF) register value in Pulse-Width Modulation (PWM) mode for the TCE0 module.

  • uint16_t TCE0_MaxCountGet (void)

    Returns the maximum counter value for the TCE0 module.

  • void TCE0_Tasks (void)

    Runs the callback functions in Polling mode.

Macros

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

    Converts from microseconds to clock increments for setting the period.

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

    Converts from milliseconds to clock increments for setting the period.

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

    Converts from seconds to clock increments for setting the period.

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

    Converts from microseconds to clock increments for setting the compare registers.

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

    Converts from milliseconds to clock increments for setting the compare registers.

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

    Converts from seconds to clock increments for setting the compare registers.

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

    Converts from hertz to clock increments.

Typedefs

  • typedef void(* TCE0_cb_t) (void)

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

Detailed Description

Timer/Counter Type E Driver API Header File.