Jump to main content

##

# 3.9.25 Timer Counter for Control Applications (TCC)

Timer Counter for Control Applications (TCC) peripheral consists of counter, compare/capture channels and control logic. Waveform extensions are featured for motor control, ballast, LED, H-bridge, power converters, and other types of power control applications. They allow for low- and high-side output with optional dead-time insertion.

TCC provides below features:

- Up to four compare/capture channels (CC) with double buffering

- Waveform extensions:

- Configurable distribution of compare channels outputs across port pins

- Low- and high-side output with programmable dead-time insertion

- Waveform swap option with double buffer support

- Pattern generation with double buffer support

- Dithering support

- Fault protection for safe disabling of drivers

- Two non-recoverable fault sources

- Two recoverable fault sources

Timer mode

This section provides brief overview of the TC peripheral library in Timer mode

## Using The Library

When the timer is enabled, it increments by one on every rising edge of the input clock, and generates an interrupt on a period match (period is controlled by CC0 in MPWM waveform mode). Timer mode is used for periodic interrupt generation. It provides both polling and callback methods to indicate period match has occurred. With polling, the application will need to continuously poll to check if the timer has expired. With callback, the registered callback function will be called when the timer expires. This means the application do not have to poll continuously.

## Library Interface

Timer Counter for Control Applications peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
TCCx_TimerInitialize | Initializes given instance of TCC
TCCx_TimerStart | Starts the timer for given TCC instance
TCCx_TimerStop | Stops the timer for given TCC instance
TCCx_TimerFrequencyGet | Provides the given timer's counter-increment frequency
TCCx_Timer32bitPeriodSet | Sets the period value of a given timer
TCCx_Timer32bitPeriodGet | Reads the period value of given timer
TCCx_Timer32bitCounterGet | Reads the timer current count value
TCCx_Timer32bitCounterSet | Sets new timer counter value
TCCx_Timer24bitPeriodSet | Sets the period value of a given timer
TCCx_Timer24bitPeriodGet | Reads the period value of given timer
TCCx_Timer24bitCounterGet | Reads the timer current count value
TCCx_Timer24bitCounterSet | Sets new timer counter value
TCCx_Timer24bitCompareSet | Sets the compare value of a given timer channel
TCCx_Timer16bitPeriodSet | Sets the period value of a given timer
TCCx_Timer16bitPeriodGet | Reads the period value of given timer
TCCx_Timer16bitCounterGet | Reads the timer current count value
TCCx_Timer16bitCounterSet | Sets new timer counter value
TCCx_Timer16bitCompareSet | Sets the compare value of a given timer channel
TCCx_TimerCallbackRegister | Registers the function to be called from interrupt
TCCx_TimerPeriodHasExpired | Checks whether timer period is elapsed
TCCx_TimerCommandSet | Issues the command to TCC instance

Data types and constants

Name | Type | Description
--- | --- | ---
TCC_CALLBACK | Typedef | Defines the function pointer data type and function signature for the tcc callback function

Compare mode

This section provides brief overview of the TC peripheral library in Compare mode.

## Using The Library

When using the TC and the Compare/Capture Value registers (CCx) for compare operations, the counter value is continuously compared to the values in the CCx registers. The Channel x Compare Buffer (CCBUFx) registers provide double buffer capability. Output polarity can be reversed by inverting the output waveforms. In compare mode, overflow interrupt and compare match interrupts can be used to change the frequency or duty cycle of the waveform.

## Library Interface

Timer Counter for Control Applications peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
TCCx_CompareInitialize | Initializes given instance of TCC
TCCx_CompareStart | Starts the timer for given TCC instance
TCCx_CompareStop | Stops the timer for given TCC instance
TCCx_CompareFrequencyGet | Provides the given timer's counter-increment frequency
TCCx_Compare16bitPeriodSet | Sets the period value of a given timer
TCCx_Compare16bitPeriodGet | Reads the period value of given timer
TCCx_Compare16bitCounterGet | Reads the timer current count value
TCCx_Compare16bitCounterSet | Sets new timer counter value
TCCx_Compare16bitMatchSet | Writes compare value of the given compare channel
TCCx_Compare24bitPeriodSet | Sets the period value of a given timer
TCCx_Compare24bitPeriodGet | Reads the period value of given timer
TCCx_Compare24bitCounterGet | Reads the timer current count value
TCCx_Compare24bitCounterSet | Sets new timer counter value
TCCx_Compare24bitMatchSet | Writes compare value of the given compare channel
TCCx_Compare32bitPeriodSet | Sets the period value of a given timer
TCCx_Compare32bitPeriodGet | Reads the period value of given timer
TCCx_Compare32bitCounterGet | Reads the timer current count value
TCCx_Compare32bitCounterSet | Sets new timer counter value
TCCx_Compare32bitMatchSet | Writes compare value of the given compare channel
TCCx_CompareCallbackRegister | Registers the function to be called from interrupt
TCCx_CompareStatusGet | Reads status of compare operation
TCCx_CompareCommandSet | Issues the command to TCC instance

Data types and constants

Name | Type | Description
--- | --- | ---
TCC_CALLBACK | Typedef | Defines the function pointer data type and function signature for the tcc callback function

Capture mode

This section provides brief overview of the TC peripheral library in Capture mode.

## Using The Library

Capture trigger can be provided by

- Input event line TC_EV

- Two event input line is available

- This provides different capture event actions:

- Pulse width in CC0 and period in CC1

- Pulse width in CC1 and period in CC0

- Pulse width

- Input event line TC_MCEIx

- Each capture channel has associated input capture event line

It provides both polling and callback methods to indicate capture event has occurred.

- With polling, the application will need to continuously poll to check if the capture event has occurred.

- With callback, the registered callback function will be called when the capture event occurs. This means the application do not have to poll continuously.

## Library Interface

Timer Counter for Control Applications peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
TCCx_CaptureInitialize | Initializes given instance of TCC
TCCx_CaptureStart | Starts the timer for given TCC instance
TCCx_CaptureStop | Stops the timer for given TCC instance
TCCx_CaptureFrequencyGet | Provides the given timer's counter-increment frequency
TCCx_Capture16bitValueGet | Reads capture value from given channel
TCCx_Capture16bitCounterGet | Reads the timer current count value
TCCx_Capture24bitValueGet | Reads capture value from given channel
TCCx_Capture24bitCounterGet | Reads the timer current count value
TCCx_Capture32bitValueGet | Reads capture value from given channel
TCCx_Capture32bitCounterGet | Reads the timer current count value
TCCx_CaptureCommandSet | Issues the command to TCC instance
TCCx_CaptureCallbackRegister | Registers the function to be called from interrupt
TCCx_CaptureStatusGet | Reads status capture operation

Data types and constants

Name | Type | Description
--- | --- | ---
TCC_CALLBACK | Typedef | Defines the function pointer data type and function signature for the tcc callback function
TCCx_CAPTURE_STATUS | Enum | TCC capture status flags

PWM mode

This section provides brief overview of the TC peripheral library in PWM mode.

## Using The Library

TCC is used to generate single slope or dual slope PWM signals with dead time. This can generate four complimentary PWM signals.

Below example shows to generate 3 phase PWM signals for motor control application. Duty cycle is updated in interrupt handler.

    /* Duty cycle increment value */
    \#define DUTY_INCREMENT (10U)

    /* Save PWM period */
    uint32_t period;

    /* This function is called after TCC period event */
    void TCC_PeriodEventHandler(uint32_t status, uintptr_t context)
    {
        /* duty cycle values */
        static uint32_t duty1 = 0U;
        static uint32_t duty2 = 0U;
        static uint32_t duty3 = 0U;

        TCC0_PWM24bitDutySet(TCC0_CHANNEL1, duty1);
        TCC0_PWM24bitDutySet(TCC0_CHANNEL2, duty2);
        TCC0_PWM24bitDutySet(TCC0_CHANNEL3, duty3);

        /* Increment duty cycle values */
        duty1 += DUTY_INCREMENT;
        duty2 += DUTY_INCREMENT;
        duty3 += DUTY_INCREMENT;

        if (duty1 > period)
        {
                duty1 = 0U;
            if (duty2 > period)
                duty2 = 0U;
            if (duty3 > period)
                duty3 = 0U;
        }
    }

    int main ( void )
    {
        /* Initialize all modules */
        SYS_Initialize ( NULL );

            /* Register callback function for period event */
        TCC0_PWMCallbackRegister(TCC_PeriodEventHandler, (uintptr_t)NULL);

        /* Read the period */
        period = TCC0_PWM24bitPeriodGet();

        /* Start PWM*/
        TCC0_PWMStart();

        while(1);
    }

## Library Interface

Timer Counter for Control Applications peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
TCCx_PWMInitialize | Initializes given instance of TCC
TCCx_PWMStart | Starts PWM generation of given TCC instance
TCCx_PWMStop | Stops PWM generation of given TCC instance
TCCx_PWMPatternSet | Sets the output PWM pattern
TCCx_PWM24bitPeriodSet | Sets the period value of a given TCC instance
TCCx_PWM24bitPeriodGet | Reads the period value of a given TCC instance
TCCx_PWM24bitDutySet | Sets the duty value of a given TCC channel
TCCx_PWM24bitCounterSet | Sets the counter value of a given TCC instance
TCCx_PWM16bitPeriodSet | Sets the period value of a given TCC instance
TCCx_PWM16bitPeriodGet | Reads the period value of a given TCC instance
TCCx_PWM16bitDutySet | Sets the duty value of a given TCC channel
TCCx_PWM16bitCounterSet | Sets the counter value of a given TCC instance
TCCx_PWM32bitPeriodSet | Sets the period value of a given TCC instance
TCCx_PWM32bitPeriodGet | Reads the period value of a given TCC instance
TCCx_PWM32bitDutySet | Sets the duty value of a given TCC channel
TCCx_PWM32bitCounterSet | Sets the counter value of a given TCC instance
TCCx_PWMDeadTimeSet | Sets the dead time of a given TCC module
TCCx_PWMForceUpdate | Updates double buffer register value to actual register asynchronously
TCCx_PWMPeriodInterruptEnable | Enables period interrupt
TCCx_PWMPeriodInterruptDisable | Disables period interrupt
TCCx_PWMInterruptStatusGet | Reads the interrupt flags
TCCx_PWMCallbackRegister | Registers the function to be called from interrupt

Data types and constants

Name | Type | Description
--- | --- | ---
TCCx_CHANNEL_NUM | Enum | Identifies channel number within TCC module
TCC_CALLBACK | Typedef | Defines the function pointer data type and function signature for the tcc callback function