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 */