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.

TMS570LS1224: Problem using ECAP and EPWM Example with Hercules Launchpad

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

Hello,

I have been trying to follow and implement the 'example_etpwm_ecap.c' under THMS570LS12x help in HALCoGen.  So far, I cannot get the code to work, even thought the sys_main.c files are exactly the same as that of the example.

Are there any issues with this example, or any common issues not addressed in this example I should be aware of??  I have tried stepping through multiple files with breakpoints and have kind of hit a dead end.

I will provide my code, but aside from the HALCoGen generated files the remaining code is identical.  Maybe it is a HALCoGen problem?  I did follow the instructions to the best of my ability.

/** @file sys_main.c 
*   @brief Application main file
*   @date 11-Dec-2018
*   @version 04.07.01
*
*   This file contains an empty main function,
*   which can be used for the application.
*/

/* 
* Copyright (C) 2009-2018 Texas Instruments Incorporated - 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.
*
*/


/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include "stdio.h"
#include "system.h"
#include "etpwm.h"
#include "ecap.h"
#include "sys_core.h"
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

void main(void)
{
/* USER CODE BEGIN (3) */

    _enable_interrupt_();

#if 1
    etpwmInit();
    ecapInit();

#else
    /* Alternate code for configuring ETPWM and ECAP */
        /* Configure ETPWM1 */
    /* Set the TBCLK frequency =  VCLK4 frequency = 90MHz */
    etpwmSetClkDiv(etpwmREG1, ClkDiv_by_1, HspClkDiv_by_1);

    /* Set the time period as 1000 ns (Divider value = (1000ns * 90MHz) - 1 = 89)*/
    etpwmSetTimebasePeriod(etpwmREG1, 89);

    /* Configure Compare A value as half the time period */
    etpwmSetCmpA(etpwmREG1, 45);

    /* Configure the module to set PWMA value as 1 when CTR=0 and as 0 when CTR=CmpA  */
    etpwmActionQualConfig_t configPWMA;
    configPWMA.CtrEqZero_Action = ActionQual_Set;
    configPWMA.CtrEqCmpAUp_Action = ActionQual_Clear;
    configPWMA.CtrEqPeriod_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpADown_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpBUp_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpBDown_Action = ActionQual_Disabled;
    etpwmSetActionQualPwmA(etpwmREG1, configPWMA);

    /* Start counter in CountUp mode */
    etpwmSetCount(etpwmREG1, 0);
    etpwmSetCounterMode(etpwmREG1, CounterMode_Up);
    etpwmStartTBCLK();

    /* Configure ECAP1 */
    /* Configure Event 1 to Capture the rising edge */
    ecapSetCaptureEvent1(ecapREG1, RISING_EDGE, RESET_DISABLE);

    /* Configure Event 2 to Capture the falling edge */
    ecapSetCaptureEvent2(ecapREG1, FALLING_EDGE, RESET_DISABLE);

    /* Configure Event 3 to Capture the rising edge with reset counter enable */
    ecapSetCaptureEvent3(ecapREG1, RISING_EDGE, RESET_ENABLE);

    /* Set Capure mode as Continuous and Wrap event as CAP3  */
    ecapSetCaptureMode(ecapREG1, CONTINUOUS, CAPTURE_EVENT3);

    /* Start counter */
    ecapStartCounter(ecapREG1);

    /* Enable Loading on Capture */
    ecapEnableCapture(ecapREG1);

    /* Enable Interrupt for CAP3 event */
    ecapEnableInterrupt(ecapREG1, ecapInt_CEVT3);

    printf("You messed up, my dude!");
    fflush(stdout);
#endif
    /*  ... run forever  */
    while(1);

/* USER CODE END */
}


/* USER CODE BEGIN (4) */
void ecapNotification(ecapBASE_t *ecap,uint16 flags)
{
    uint32 cap1, cap2, cap3;
    float64 duty, period;

    cap1 = ecapGetCAP1(ecapREG1);
    cap2 = ecapGetCAP2(ecapREG1);
    cap3 = ecapGetCAP3(ecapREG1);

    duty = (cap2 - cap1)*1000/VCLK4_FREQ;
    period = (cap3 - cap1)*1000/VCLK4_FREQ;

    printf("Duty = %fns\n", duty);
    printf("Period = %fns\n\n", period);
    fflush(stdout);

}
/* USER CODE END */

Thanks for your time, I have a feeling I am missing something minor.

-Alec

  • Hello,

    I just tried the example from HALCoGen example and it works. Please, check whether you have connected pin J4.7 (Connector J4, pin 7) to J11.35 (Connector J11, pin 35). Please, comment ecapNotification from notification.c as well

    Best regards,
    Miro

  • Hello Miro,

    I had the correct pins, but commenting out ecapNotification and making sure ETPWM1SYNCO was enabled on PINMUX helped.  Oddly enough, when I run the code with just etpwmInit() and ecapInit(), I get the appropriate output with all zeros.  When I switch to the manual setup (the else statement), I get correct numbers.

    Any idea why that is??

    And thank you again for the assistance.

    Alec