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.

TMS320F280049C: The CBC code review

Part Number: TMS320F280049C

Hi Expert,

I have modified the example "cmpss_ex1_asynch" as below to enable CBC function to trip EPWM8B. 

From the test result, the EPWM8B could be tripped CBC in oscilloscope when changing the ADCINB6 input voltage level. However, in the expression window, it shows the TZFLG of DCBEVT1 is set but not DCBEVT2, and the epwm8TZISR() function could not be triggered.

Could you help me to review the register configuration? I just don't know where the issue is now. Really appreciate!

5430.cmpss_ex1_asynch.c
//#############################################################################
//
// FILE:   cmpss_ex1_asynch.c
//
// TITLE:  CMPSS Asynchronous Trip
//
//! \addtogroup driver_example_list
//! <h1> CMPSS Asynchronous Trip </h1>
//!
//! This example enables the CMPSS1 COMPH comparator and feeds the asynchronous
//! CTRIPOUTH signal to the GPIO14/OUTPUTXBAR3 pin and CTRIPH to GPIO15/EPWM8B.
//!
//! CMPSS is configured to generate trip signals to trip the EPWM signals.
//! CMPIN1P is used to give positive input and internal DAC is configured 
//! to provide the negative input. Internal DAC is configured to provide a
//! signal at VDD/2. An EPWM signal is generated at GPIO15 and is configured
//! to be tripped by CTRIPOUTH.
//!
//! When a low input(VSS) is provided to CMPIN1P,
//!     - Trip signal(GPIO14) output is low
//!     - PWM8B(GPIO15) gives a PWM signal
//!
//! When a high input(higher than VDD/2) is provided to CMPIN1P,
//!     - Trip signal(GPIO14) output turns high
//!     - PWM8B(GPIO15) gets tripped and outputs as high
//!
//! \b External \b Connections \n
//!  - Give input on CMPIN1P (The pin is shared with ADCINB6)
//!  - Outputs can be observed on GPIO14 and GPIO15 using an oscilloscope
//!
//! \b Watch \b Variables \n
//!  - None
//!
//
//#############################################################################
// $TI Release: F28004x Support Library v1.10.00.00 $
// $Release Date: Tue May 26 17:06:03 IST 2020 $
// $Copyright:
// Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions 
// are met:
// 
//   Redistributions of source code must retain the above copyright 
//   notice, this list of conditions and the following disclaimer.
// 
//   Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the 
//   documentation and/or other materials provided with the   
//   distribution.
// 
//   Neither the name of Texas Instruments Incorporated nor the names of
//   its contributors may be used to endorse or promote products derived
//   from this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################

//
// Included Files
//
#include "driverlib.h"
#include "device.h"

//
// Function Prototypes
//
void initCMPSS(void);
void initEPWM(void);

__interrupt void epwm8TZISR(void);
uint32_t epwm8TZIntCount=0;

//
// Main
//
void main(void)
{
    //
    // Initialize device clock and peripherals
    //
    Device_init();

    //
    // Disable pin locks and enable internal pullups.
    //
    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();

    Interrupt_register(INT_EPWM8_TZ, &epwm8TZISR);

    //
    // Configure GPIO14 to output CTRIPOUT1H (routed through XBAROUTPUT3) and
    // GPIO15 to output CTRIPH (routed through ePWM TRIP4 and ePWM8)
    //
    GPIO_setPinConfig(GPIO_14_OUTPUTXBAR3);

    GPIO_setPadConfig(15, GPIO_PIN_TYPE_STD);
    GPIO_setPinConfig(GPIO_15_EPWM8B);

    //
    // Set up COMP1H
    //
    initCMPSS();

    //
    // Set up ePWM8 to take CTRIPH as TRIP4 for its DC trip input
    //

    //
    // Disable the ePWM time base clock before configuring the module
    //
    SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

    initEPWM();

    //
    // Sync the ePWM time base clock
    //
    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

    Interrupt_enable(INT_EPWM8_TZ);

    //
    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    //
    EINT;
    ERTM;

    //
    // Loop indefinitely
    //
    while(1)
    {
//        //
//        // Trip flag is set when CTRIP signal is asserted
//        //
//        if((EPWM_getTripZoneFlagStatus(EPWM8_BASE) &
//            EPWM_TZ_FLAG_OST) != 0U)
//        {
//            //
//            // Wait for comparator CTRIP to de-assert
//            //
//            while((CMPSS_getStatus(CMPSS1_BASE) & CMPSS_STS_HI_FILTOUT) != 0U)
//            {
//                ;
//            }
//
//            //
//            // Clear trip flags
//            //
//            EPWM_clearTripZoneFlag(EPWM8_BASE, EPWM_TZ_INTERRUPT |
//                                   EPWM_TZ_FLAG_OST);
//        }


    }
}

//
// epwm1TZISR - ePWM1 TZ ISR
//
__interrupt void epwm8TZISR(void)
{
    epwm8TZIntCount++;


    //
    // Clear the CBC flags using TRIPIN1 as DCAEVT2
    //
    EPWM_clearCycleByCycleTripZoneFlag(EPWM8_BASE, EPWM_TZ_CBC_FLAG_1 |
                                       EPWM_TZ_CBC_FLAG_DCBEVT2);

    //
    // re-enable the interrupts and the ePWM output if using CBC
    //
    EPWM_clearTripZoneFlag(EPWM8_BASE, EPWM_TZ_CBC_FLAG_DCBEVT2 |
                                       EPWM_TZ_FLAG_CBC);

    //
    // Acknowledge this interrupt to receive more interrupts from group 2
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP2);

}

//
// initCMPSS - Function to configure the high comparator of CMPSS1
//
void initCMPSS(void)
{
    //
    // Enable CMPSS and configure the negative input signal to come from
    // the DAC
    //
    CMPSS_enableModule(CMPSS1_BASE);
    CMPSS_configHighComparator(CMPSS1_BASE, CMPSS_INSRC_DAC);

    //
    // Use VDDA as the reference for the DAC and set DAC value to midpoint for
    // arbitrary reference.
    //
    CMPSS_configDAC(CMPSS1_BASE, CMPSS_DACREF_VDDA | CMPSS_DACVAL_SYSCLK |
                    CMPSS_DACSRC_SHDW);
    CMPSS_setDACValueHigh(CMPSS1_BASE, 2048);

    //
    // Configure the output signals. Both CTRIPH and CTRIPOUTH will be fed by
    // the asynchronous comparator output.
    //
    CMPSS_configOutputsHigh(CMPSS1_BASE, CMPSS_TRIP_ASYNC_COMP |
                            CMPSS_TRIPOUT_ASYNC_COMP);

    //
    // Setup the Output X-BAR to output CTRIPOUTH on OUTPUTXBAR3
    //
    XBAR_setOutputMuxConfig(XBAR_OUTPUT3, XBAR_OUT_MUX00_CMPSS1_CTRIPOUTH);
    XBAR_enableOutputMux(XBAR_OUTPUT3, XBAR_MUX00);
}

//
// initEPWM - Function to configure ePWM8 and the ePWM X-BAR to take CTRIPH as
//            the DC trip input
//
void initEPWM(void)
{

    //
    // Set the time base clock prescalers to /1
    //
    EPWM_setClockPrescaler(EPWM8_BASE, EPWM_CLOCK_DIVIDER_1,
                           EPWM_HSCLOCK_DIVIDER_1);

    //
    // Initializing dummy values for ePWM counter and period
    //
    EPWM_setTimeBaseCounter(EPWM8_BASE, 0);
    EPWM_setTimeBasePeriod(EPWM8_BASE, 0xFFFF);
    EPWM_setTimeBaseCounterMode(EPWM8_BASE, EPWM_COUNTER_MODE_UP);

    //
    // Set-up compare
    //
    EPWM_setCounterCompareValue(EPWM8_BASE,
                          EPWM_COUNTER_COMPARE_B, 0x8000);

    //
    // Set actions
    //
    EPWM_setActionQualifierAction(EPWM8_BASE,
                                  EPWM_AQ_OUTPUT_B,
                                  EPWM_AQ_OUTPUT_HIGH,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);

    EPWM_setActionQualifierAction(EPWM8_BASE,
                                  EPWM_AQ_OUTPUT_B,
                                  EPWM_AQ_OUTPUT_LOW,
                                  EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);



    //
    // Enable DCB as OST,//change to CBC
    //
    EPWM_enableTripZoneSignals(EPWM8_BASE, EPWM_TZ_SIGNAL_DCBEVT2);

    //
    // Configure ePWM8B to output LOW on TZB TRIP
    //
    EPWM_setTripZoneAction(EPWM8_BASE, EPWM_TZ_ACTION_EVENT_TZB,
                           EPWM_TZ_ACTION_LOW);

    //
    // Enable TZ interrupt
    //
    EPWM_enableTripZoneInterrupt(EPWM8_BASE, EPWM_TZ_INTERRUPT_DCBEVT2|
                                 EPWM_TZ_INTERRUPT_CBC);

    //
    // CBC latch is reset and EPWMA is re-enabled, when CNTR=ZERO and the TRIPIN/DCAEVT2
    // is no longer present
    //
    EPWM_selectCycleByCycleTripZoneClearEvent(EPWM8_BASE,
                                    EPWM_TZ_CBC_PULSE_CLR_CNTR_ZERO);

    //
    // Trigger event when DCBH is high
    //
    EPWM_setTripZoneDigitalCompareEventCondition(EPWM8_BASE,
                                                 EPWM_TZ_DC_OUTPUT_B1,
                                                 EPWM_TZ_EVENT_DCXH_HIGH);

    //
    // Configure DCBH to use TRIP4 as an input
    //
    EPWM_enableDigitalCompareTripCombinationInput(EPWM8_BASE,
                                                  EPWM_DC_COMBINATIONAL_TRIPIN4,
                                                  EPWM_DC_TYPE_DCBH);


    //
    // Configure the DCB path to be unfiltered and asynchronous
    //
    EPWM_setDigitalCompareEventSource(EPWM8_BASE,
                                      EPWM_DC_MODULE_B,
                                      EPWM_DC_EVENT_1,
                                      EPWM_DC_EVENT_SOURCE_ORIG_SIGNAL);


    //
    // Configure TRIP4 to be CTRIP1H using the ePWM X-BAR
    //
    XBAR_setEPWMMuxConfig(XBAR_TRIP4, XBAR_EPWM_MUX00_CMPSS1_CTRIPH);
    XBAR_enableEPWMMux(XBAR_TRIP4, XBAR_MUX00);

    //
    // Clear trip flags, change to CBC
    //
    EPWM_clearTripZoneFlag(EPWM8_BASE, EPWM_TZ_FLAG_CBC|
                           EPWM_TZ_FLAG_DCBEVT2);

    //what's the difference with above setting
    EPWM_clearCycleByCycleTripZoneFlag(EPWM8_BASE, EPWM_TZ_CBC_FLAG_1|
                                       EPWM_TZ_CBC_FLAG_DCBEVT2);



}


Best Regards

Rayna