This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28032: A question about TZCLR and PWM

Part Number: TMS320F28032

Tool/software: Code Composer Studio

Hi, We has a question,

After the OST event was trigged by PWM module, if we clear the OST flag by TZCLR, the PWM output immediately or in next period?

Thanks  

  • I believe it is immediate. I will double check.
  • For CBC - the output changes per TZCTL[TZA/B] settings immediately upon detection of event, but output returns back to original state when TBCTR = 0x0000.

    For OSHT - the output changes per TZCTL[TZA/B] settings immediately upon detection of event and remains in changed condition until user manually writes clear bit to clear the event.

    And Yes I double checked with an example code. Clearing the OST flag at random times manually. The output resumes when you clear the register and does not wait for TBCTR = 0.

    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Globals
    //
    uint32_t  epwm1TZIntCount;
    uint32_t  epwm2TZIntCount;
    
    //
    // Function Prototypes
    //
    void initEPWM1(void);
    void initEPWM2(void);
    void initTZGPIO(void);
    void initEPWMGPIO(void);
    __interrupt void epwm1TZISR(void);
    __interrupt void epwm2TZISR(void);
    
    void main(void)
    {
        //
        // Initialize global variables
        //
        epwm1TZIntCount = 0U;
        epwm2TZIntCount = 0U;
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pull-ups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Interrupts that are used in this example are re-mapped to ISR functions
        // found within this file.
        //
        Interrupt_register(INT_EPWM1_TZ, &epwm1TZISR);
        Interrupt_register(INT_EPWM2_TZ, &epwm2TZISR);
    
        //
        // Configure ePWM1, ePWM2, and TZ GPIOs
        //
        initEPWMGPIO();
        initTZGPIO();
    
        //
        // Disable sync(Freeze clock to PWM as well)
        //
        SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
        //
        // Initialize ePWM1 and ePWM2
        //
        initEPWM1();
        initEPWM2();
    
        //
        // Enable sync and clock to PWM
        //
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
        //
        // Enable interrupts required for this example
        //
        Interrupt_enable(INT_EPWM1_TZ);
        Interrupt_enable(INT_EPWM2_TZ);
    
        //
        // Enable Global Interrupt (INTM) and real time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // IDLE loop. Just sit and loop forever (optional):
        //
        for(;;)
        {
            NOP;
        }
    }
    
    //
    // epwm1TZISR - ePWM1 TZ ISR
    //
    __interrupt void epwm1TZISR(void)
    {
        epwm1TZIntCount++;
    
        //
        // To re-enable the OST Interrupt, uncomment the below code:
        //
        // EPWM_clearTripZoneFlag(EPWM1_BASE,
        //                        (EPWM_TZ_INTERRUPT | EPWM_TZ_FLAG_OST));
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 2
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP2);
    }
    
    //
    // epwm2TZISR - ePWM2 TZ ISR
    //
    __interrupt void epwm2TZISR(void)
    {
        epwm2TZIntCount++;
    
        //
        // Toggle GPIO to notify when TZ is entered
        //
        GPIO_togglePin(11);
    
        //
        // Clear the flags - we will continue to take this interrupt until the TZ
        // pin goes high.
        //
        EPWM_clearTripZoneFlag(EPWM2_BASE, (EPWM_TZ_INTERRUPT | EPWM_TZ_FLAG_CBC));
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 2
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP2);
    }
    
    //
    // initEPWM1 - Configure ePWM1
    //
    void initEPWM1()
    {
        //
        // Enable TZ1 as one shot trip sources
        //
        EPWM_enableTripZoneSignals(EPWM1_BASE, EPWM_TZ_SIGNAL_OSHT1);
    
        //
        // Action on TZ1
        //
        EPWM_setTripZoneAction(EPWM1_BASE,
                               EPWM_TZ_ACTION_EVENT_TZA,
                               EPWM_TZ_ACTION_HIGH);
    
        //
        // Enable TZ interrupt
        //
        EPWM_enableTripZoneInterrupt(EPWM1_BASE, EPWM_TZ_INTERRUPT_OST);
    
        //
        // Set-up TBCLK
        //
        EPWM_setTimeBasePeriod(EPWM1_BASE, 12000U);
        EPWM_setPhaseShift(EPWM1_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);
        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_disablePhaseShiftLoad(EPWM1_BASE);
    
        //
        // Set ePWM clock pre-scaler
        //
        EPWM_setClockPrescaler(EPWM1_BASE,
                               EPWM_CLOCK_DIVIDER_64,
                               EPWM_HSCLOCK_DIVIDER_8);
    
        //
        // Set up shadowing
        //
        EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE,
                                             EPWM_COUNTER_COMPARE_A,
                                             EPWM_COMP_LOAD_ON_CNTR_ZERO);
    
        //
        // Set-up compare
        //
        EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 6000U);
    
        //
        // Set actions
        //
        EPWM_setActionQualifierAction(EPWM1_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
        EPWM_setActionQualifierAction(EPWM1_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    }
    
    //
    // initEPWM2 - Configure ePWM2
    //
    void initEPWM2()
    {
        //
        // Enable TZ1 as one cycle-by-cycle trip sources
        //
        EPWM_enableTripZoneSignals(EPWM2_BASE, EPWM_TZ_SIGNAL_CBC1);
    
        //
        // Action on TZ1
        //
        EPWM_setTripZoneAction(EPWM2_BASE,
                               EPWM_TZ_ACTION_EVENT_TZA,
                               EPWM_TZ_ACTION_HIGH);
    
        //
        // Enable TZ interrupt
        //
        EPWM_enableTripZoneInterrupt(EPWM2_BASE,
                                     EPWM_TZ_INTERRUPT_CBC);
    
        //
        // Set-up TBCLK
        //
        EPWM_setTimeBasePeriod(EPWM2_BASE, 6000U);
        EPWM_setPhaseShift(EPWM2_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM2_BASE, 0U);
        EPWM_setTimeBaseCounterMode(EPWM2_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_disablePhaseShiftLoad(EPWM2_BASE);
    
        //
        // Set ePWM clock pre-scaler
        //
        EPWM_setClockPrescaler(EPWM2_BASE,
                               EPWM_CLOCK_DIVIDER_4,
                               EPWM_HSCLOCK_DIVIDER_4);
    
        //
        // Set-up compare
        //
        EPWM_setCounterCompareValue(EPWM2_BASE, EPWM_COUNTER_COMPARE_A, 3000U);
    
        //
        // Set actions
        //
        EPWM_setActionQualifierAction(EPWM2_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
        EPWM_setActionQualifierAction(EPWM2_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    }
    
    //
    // initTZGPIO - Configure TZ GPIO
    //
    void initTZGPIO(void)
    {
        //
        // Set GPIO 12 as as Asynchronous input with pull up enabled
        //
        GPIO_setPadConfig(16, GPIO_PIN_TYPE_PULLUP);
        GPIO_setPinConfig(GPIO_16_GPIO16);
        GPIO_setDirectionMode(16, GPIO_DIR_MODE_IN);
        GPIO_setQualificationMode(16, GPIO_QUAL_ASYNC);
    
        //
        // Set GPIO 12 as TZ1 input
        //
        XBAR_setInputPin(XBAR_INPUT1, 16);
    
        //
        // Configure GPIO 11 as general purpose GPIO for monitoring when the TZ
        // Interrupt has been entered
        //
        GPIO_setPadConfig(11, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_11_GPIO11);
        GPIO_setDirectionMode(11, GPIO_DIR_MODE_OUT);
    }
    
    //
    // initEPWMGPIO - Configure ePWM GPIO
    //
    void initEPWMGPIO(void)
    {
        //
        // Disable pull up on GPIO 0 and GPIO 2 and configure them as PWM1A and
        // PWM2A output respectively.
        //
        GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_0_EPWM1A);
    
        GPIO_setPadConfig(2, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_2_EPWM2A);
    }
    

  • Nima ,
    Thanks for your help!
    Erwin