Other Parts Discussed in Thread: C2000WARE
Hello to everyone,
I´m using a LAUNCHXL-F28379D for my project. I need to use different peripherals and, between these, I´m using ePWM and eCAP.
I´m using eCAP in order to measure the frequency of a squared signal. I´m doing it using an interrupt and the eCAP module1 connected to the 11 pin.
I´m using another interrupt (with higher priority) to update ePWMs comparators values (I´m using ePWM 1A,1B,3B).
These two operations work perfectly alone but, as soon the ePWMs values start to be updated, eCAP starts measuring wrong. It seems that the problem is the updating of the ePWM 1A that affects the eCAP.
I´ve tried also with a smaller code with just eCAP and ePWM in which I´ve a single eCAP interrupt and I set the compare value of the ePWM to a fixed value in the main. I also have problems but, in that case, it seems that the eCAP doesn´t work at all.
My question is: Is there some kind of incompatibility of using both (eCAP and ePWM) at the same time? Maybe I´ve missed something in the datasheet were it´s explained.
Attached the simple code used for the only eCAP + ePWM test:
void main(void)
{
Device_init();
Device_initGPIO();
Interrupt_initModule();
Interrupt_initVectorTable();
GPIO_setPinConfig(GPIO_11_GPIO11);
GPIO_setDirectionMode(11, GPIO_DIR_MODE_IN);
GPIO_setQualificationMode(11, GPIO_QUAL_ASYNC);
Interrupt_register(INT_ECAP1, &ecap1ISR);
initECAP();
tbcpr_pwm=(int)((100000000/(12500))-1);
init_PWM(tbcpr_pwm);
cap1Count = 0U;
cap2Count = 0U;
cap3Count = 0U;
cap4Count = 0U;
Interrupt_enable(INT_ECAP1);
EINT;
ERTM;
Init_SCI();
uint16_t compA=0;
compA=(uint16_t)(0.97*(tbcpr_pwm));
EPWM_setCounterCompareValue(Base_PWMRete_A,Comparatore_PWMRete_A,compA);
while(1)
{
if (flag>0)
{
freq_diff_1=(clock/(cap3Count-cap1Count));
freq_diff_2=(clock/(cap4Count-cap2Count));
freq_diff=(freq_diff_1+freq_diff_2)/2;
sprintf(&stampa[0],"%g\r\n",freq_diff);
len=strlen(&stampa[0]);
SCI_writeCharArray(SCIA_BASE, (uint16_t*)stampa, len);
flag=0;
}
}
}
void Inizializza_SCI()
{
GPIO_setMasterCore(43, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_43_SCIRXDA);
GPIO_setDirectionMode(43, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(43, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(43, GPIO_QUAL_ASYNC);
GPIO_setMasterCore(42, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_42_SCITXDA);
GPIO_setDirectionMode(42, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(42, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(42, GPIO_QUAL_ASYNC);
SCI_performSoftwareReset(SCIA_BASE);
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_resetChannels(SCIA_BASE);
SCI_resetRxFIFO(SCIA_BASE);
SCI_resetTxFIFO(SCIA_BASE);
SCI_enableInterrupt(SCIA_BASE, (SCI_INT_RXFF));
SCI_disableInterrupt(SCIA_BASE, SCI_INT_RXERR);
SCI_enableFIFO(SCIA_BASE);
SCI_enableModule(SCIA_BASE);
SCI_performSoftwareReset(SCIA_BASE);
}
void initECAP()
{
cap1Count = 0U;
cap2Count = 0U;
cap3Count = 0U;
cap4Count = 0U;
flag=0;
ECAP_disableInterrupt(ECAP1_BASE,
(ECAP_ISR_SOURCE_CAPTURE_EVENT_1 |
ECAP_ISR_SOURCE_CAPTURE_EVENT_2 |
ECAP_ISR_SOURCE_CAPTURE_EVENT_3 |
ECAP_ISR_SOURCE_CAPTURE_EVENT_4 |
ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
ECAP_ISR_SOURCE_COUNTER_PERIOD |
ECAP_ISR_SOURCE_COUNTER_COMPARE));
ECAP_clearInterrupt(ECAP1_BASE,
(ECAP_ISR_SOURCE_CAPTURE_EVENT_1 |
ECAP_ISR_SOURCE_CAPTURE_EVENT_2 |
ECAP_ISR_SOURCE_CAPTURE_EVENT_3 |
ECAP_ISR_SOURCE_CAPTURE_EVENT_4 |
ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
ECAP_ISR_SOURCE_COUNTER_PERIOD |
ECAP_ISR_SOURCE_COUNTER_COMPARE));
ECAP_disableTimeStampCapture(ECAP1_BASE);
ECAP_stopCounter(ECAP1_BASE);
ECAP_enableCaptureMode(ECAP1_BASE);
ECAP_setEventPrescaler(ECAP1_BASE,0);
ECAP_setCaptureMode(ECAP1_BASE, ECAP_CONTINUOUS_CAPTURE_MODE, ECAP_EVENT_4);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_1, ECAP_EVNT_FALLING_EDGE);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_2, ECAP_EVNT_RISING_EDGE);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_3, ECAP_EVNT_FALLING_EDGE);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_4, ECAP_EVNT_RISING_EDGE);
ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_4);
XBAR_setInputPin(XBAR_INPUT7, 11);
ECAP_enableLoadCounter(ECAP1_BASE);
ECAP_setSyncOutMode(ECAP1_BASE, ECAP_SYNC_OUT_DISABLED);
ECAP_startCounter(ECAP1_BASE);
ECAP_enableTimeStampCapture(ECAP1_BASE);
ECAP_reArm(ECAP1_BASE);
ECAP_enableInterrupt(ECAP1_BASE, ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
}
void config_PWM(uint32_t pin,uint16_t period,uint32_t PIN_config,uint32_t base_PWM,
EPWM_CounterCompareModule Comparatore, EPWM_ActionQualifierOutputModule Comp_Qualif,
EPWM_ActionQualifierOutputEvent Comp_action)
{
GPIO_setPadConfig(pin, GPIO_PIN_TYPE_STD);
GPIO_setPinConfig(PIN_config);
EPWM_setTimeBasePeriod(base_PWM, period);
EPWM_setPhaseShift(base_PWM, 0);
EPWM_setTimeBaseCounter(base_PWM, 0);
EPWM_setCounterCompareValue(base_PWM, Comparatore, 0);
EPWM_setTimeBaseCounterMode(base_PWM, EPWM_COUNTER_MODE_UP);
EPWM_disablePhaseShiftLoad(base_PWM);
EPWM_setClockPrescaler(base_PWM,EPWM_CLOCK_DIVIDER_1,EPWM_HSCLOCK_DIVIDER_1);
EPWM_setCounterCompareShadowLoadMode(base_PWM,Comparatore,EPWM_COMP_LOAD_ON_CNTR_ZERO);
EPWM_setActionQualifierAction(base_PWM,Comp_Qualif,EPWM_AQ_OUTPUT_LOW,Comp_action);
EPWM_setActionQualifierAction(base_PWM,Comp_Qualif,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
}
void init_PWM(uint16_t tbcpr_pwm)
{
config_PWM(0,tbcpr_pwm,GPIO_0_EPWM1A, EPWM1_BASE,EPWM_COUNTER_COMPARE_A, EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
}
__interrupt void ecap1ISR(void)
{
cap1Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_1);
cap2Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_2);
cap3Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_3);
cap4Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_4);
flag=1;
ECAP_clearInterrupt(ECAP1_BASE,ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
ECAP_clearGlobalInterrupt(ECAP1_BASE);
ECAP_reArm(ECAP1_BASE);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP4);
}
In the code also SCI is configured in order to check the eCAP out.
(I know it´s not a good code but it´s to verify if the problem was in the bigger project code or in something in the peripherals)
Thank you in advance, Gaetano.
