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

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.

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.

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

NameDescription
TCCx_TimerInitializeInitializes given instance of TCC
TCCx_TimerStartStarts the timer for given TCC instance
TCCx_TimerStopStops the timer for given TCC instance
TCCx_TimerFrequencyGetProvides the given timer's counter-increment frequency
TCCx_Timer32bitPeriodSetSets the period value of a given timer
TCCx_Timer32bitPeriodGetReads the period value of given timer
TCCx_Timer32bitCounterGetReads the timer current count value
TCCx_Timer32bitCounterSetSets new timer counter value
TCCx_Timer24bitPeriodSetSets the period value of a given timer
TCCx_Timer24bitPeriodGetReads the period value of given timer
TCCx_Timer24bitCounterGetReads the timer current count value
TCCx_Timer24bitCounterSetSets new timer counter value
TCCx_Timer24bitCompareSetSets the compare value of a given timer channel
TCCx_Timer16bitPeriodSetSets the period value of a given timer
TCCx_Timer16bitPeriodGetReads the period value of given timer
TCCx_Timer16bitCounterGetReads the timer current count value
TCCx_Timer16bitCounterSetSets new timer counter value
TCCx_Timer16bitCompareSetSets the compare value of a given timer channel
TCCx_TimerCallbackRegisterRegisters the function to be called from interrupt
TCCx_TimerPeriodHasExpiredChecks whether timer period is elapsed
TCCx_TimerCommandSetIssues the command to TCC instance
TCCx_CompareInitializeInitializes given instance of TCC
TCCx_CompareStartStarts the timer for given TCC instance
TCCx_CompareStopStops the timer for given TCC instance
TCCx_CompareFrequencyGetProvides the given timer's counter-increment frequency
TCCx_Compare16bitPeriodSetSets the period value of a given timer
TCCx_Compare16bitPeriodGetReads the period value of given timer
TCCx_Compare16bitCounterGetReads the timer current count value
TCCx_Compare16bitCounterSetSets new timer counter value
TCCx_Compare16bitMatchSetWrites compare value of the given compare channel
TCCx_Compare24bitPeriodSetSets the period value of a given timer
TCCx_Compare24bitPeriodGetReads the period value of given timer
TCCx_Compare24bitCounterGetReads the timer current count value
TCCx_Compare24bitCounterSetSets new timer counter value
TCCx_Compare24bitMatchSetWrites compare value of the given compare channel
TCCx_Compare32bitPeriodSetSets the period value of a given timer
TCCx_Compare32bitPeriodGetReads the period value of given timer
TCCx_Compare32bitCounterGetReads the timer current count value
TCCx_Compare32bitCounterSetSets new timer counter value
TCCx_Compare32bitMatchSetWrites compare value of the given compare channel
TCCx_CompareCallbackRegisterRegisters the function to be called from interrupt
TCCx_CompareStatusGetReads status of compare operation
TCCx_CompareCommandSetIssues the command to TCC instance
TCCx_CaptureInitializeInitializes given instance of TCC
TCCx_CaptureStartStarts the timer for given TCC instance
TCCx_CaptureStopStops the timer for given TCC instance
TCCx_CaptureFrequencyGetProvides the given timer's counter-increment frequency
TCCx_Capture16bitValueGetReads capture value from given channel
TCCx_Capture16bitCounterGetReads the timer current count value
TCCx_Capture24bitValueGetReads capture value from given channel
TCCx_Capture24bitCounterGetReads the timer current count value
TCCx_Capture32bitValueGetReads capture value from given channel
TCCx_Capture32bitCounterGetReads the timer current count value
TCCx_CaptureCommandSetIssues the command to TCC instance
TCCx_CaptureCallbackRegisterRegisters the function to be called from interrupt
TCCx_CaptureStatusGetReads status capture operation
TCCx_PWMInitializeInitializes given instance of TCC
TCCx_PWMStartStarts PWM generation of given TCC instance
TCCx_PWMStopStops PWM generation of given TCC instance
TCCx_PWMPatternSetSets the output PWM pattern
TCCx_PWM24bitPeriodSetSets the period value of a given TCC instance
TCCx_PWM24bitPeriodGetReads the period value of a given TCC instance
TCCx_PWM24bitDutySetSets the duty value of a given TCC channel
TCCx_PWM24bitCounterSetSets the counter value of a given TCC instance
TCCx_PWM16bitPeriodSetSets the period value of a given TCC instance
TCCx_PWM16bitPeriodGetReads the period value of a given TCC instance
TCCx_PWM16bitDutySetSets the duty value of a given TCC channel
TCCx_PWM16bitCounterSetSets the counter value of a given TCC instance
TCCx_PWM32bitPeriodSetSets the period value of a given TCC instance
TCCx_PWM32bitPeriodGetReads the period value of a given TCC instance
TCCx_PWM32bitDutySetSets the duty value of a given TCC channel
TCCx_PWM32bitCounterSetSets the counter value of a given TCC instance
TCCx_PWMDeadTimeSetSets the dead time of a given TCC module
TCCx_PWMForceUpdateUpdates double buffer register value to actual register asynchronously
TCCx_PWMPeriodInterruptEnableEnables period interrupt
TCCx_PWMPeriodInterruptDisableDisables period interrupt
TCCx_PWMInterruptStatusGetReads the interrupt flags
TCCx_PWMCallbackRegisterRegisters the function to be called from interrupt

Data types and constants

NameTypeDescription
TCC_CALLBACKTypedefDefines the function pointer data type and function signature for the tcc callback function
TCCx_CHANNEL_NUMEnumIdentifies channel number within TCC module
TCCx_CAPTURE_STATUSEnumTCC capture status flags
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.