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/TMS570LS1224: Reading multiple eCAP ports

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

Dear all,

I have followed the example "example_etpwm_ecap.c" and managed to get it working perfectly. I would like to know how I need to alter the code in order to read several ECAP modules, let's say ECAP3, 4 and 5. I currently have:

Is there a way I can now which ECAP is causing the interrupt event so that I can read the corresponding CAP1, CAP2 and CAP3? Thanks a million!

My code is as follows:

/* Include Files */

#include "sys_common.h"

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


/** @fn void main(void)
*   @brief Application main function
*
*/

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


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

	_enable_interrupt_();
	
#if 1
	/* Initialise EPWM and ECAP with GUI configuration */ 
	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 mthe 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);
	
#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);

}
/* USER CODE END */

  • Hi Sofia,

    You can use the same configuration on the other channel as well, you need to change only the register, so if you want to use ecap CH3 than change every where the register from ecapREG1 to ecapREG3. I think based on notification function parameter (ecapBASE_t *ecap) you can decide which ecap channel caused the trigger. 

    Kind regards,

    Norbert

  • Hello Sofia,

    1. enable ecap driver

    2. enable ecap interrupts in VIM: VIM channel 106 for ecap3, VIM channel 107 for ecap4, VIM channel 108 for ecap5

    3. enable ecap modules: ecap3, ecap4, ecap5

    4. configure ecap3, ecap4, ecap5: one-shot or continuous, capture polarity for all the events, enable interrupt for event3, etc

    5. HalCoGen will generate code with interrupt routine

    #pragma CODE_STATE(ecap3nterrupt, 32)
    #pragma INTERRUPT(ecap3nterrupt, IRQ)

    /* SourceId : ECAP_SourceId_034 */
    /* DesignId : ECAP_DesignId_021 */
    /* Requirements : HL_ECAP_SR15 */
    void ecap3nterrupt(void)
    {....

    /* Passing the Interrupt Flag to the user Notification Function */
    ecapNotification(ecapREG3,Int_Flag);

    }

    6. In ecapNotification function, use ecap to determine which module (ecap3/4/5) is the interrupt from

    void ecapNotification(ecapBASE_t *ecap,uint16 flags)
    {
        if (ecap == ecapREG3)
    {
            cap1 = ecapGetCAP1(ecapREG3);
    	cap2 = ecapGetCAP2(ecapREG3);
    	cap3 = ecapGetCAP3(ecapREG3);
    
    	duty = (cap2 - cap1)*1000/VCLK4_FREQ;
    	period = (cap3 - cap1)*1000/VCLK4_FREQ;
    
    	printf("Duty = %fns\n", duty);
    	printf("Period = %fns\n\n", period);
    }
        if (ecap == ecapREG4)
    ...............
        etc
    }