Tool/software: Code Composer Studio
Hi,
Actually, I need to detect the grid voltage when it passes through the zero point(if it is from negative to positive, output a high level; if it is from positive to negative, output a low level.).
so, I write a test program to verify this function. I use EPwm1A to generate a 50HZ pwm with a 50% duty. Then the ECap1 will capture this pwm. If ECap capture the rising edge, force the EPwm1B to output a high level; if the falling edge, force the EPwm1B to output a low level. The ideal result is that I will detect a Synchronous 50Hz pwm with a 50% duty in pin GPIO1(EPwm1B) by an Oscilloscope.
However, I came across some problems after the dsp run. I didn't see the ideal result.
At first, the GPIO1 didn't output a pwm. It output either high or low. Then I changed some configuration. The GPIO1 output a 25Hz pwm with a 50% duty.
And I compared the output EPwm1B with the input EPwm1A. I found the output of EPwm1B didn't change at the rising or falling edge of EPwm1A. It changed at the mid point of the high level or low level of EPwm1A. It seems that ECap1 didn't capture the rising edge or falling edge.
I know there must be some wrong configurations with my ECap1 module. the following is my configuration code:
void SetCap1Mode(void)
{
ECap1Regs.ECEINT.all = 0x0000; // disable all interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // clear all flag
ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING; // rising edge
ECap1Regs.ECCTL1.bit.CAP1POL = EC_FALLING; // falling edge
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_DISABLE; // disable CAP1-CAP4 register loads
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; // input / 1
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; // work at cap mode
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_ONESHOT; // work at one-shot mode
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS; // Disable sync out signal
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; // Disable sync in
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_FREEZE; // stop the counter when not used
ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2; // stop at event 2
ECap1Regs.ECCTL2.bit.REARM = EC_ARM; // arm one-shot
ECap1Regs.ECEINT.bit.CEVT1 = 1;
ECap1Regs.ECEINT.bit.CEVT2 = 1;
}
interrupt void ISRCap1(void)
{
if( ( ECap1Regs.ECFLG.bit.CEVT1 == 1 )&&(EPwm1Regs.AQCSFRC.bit.CSFB == 1 ) )
{
capcount1++;
LED1 = ~LED1;
EPwm1Regs.AQCSFRC.bit.CSFB = 2;
ECap1Regs.ECCLR.bit.CEVT1 = 1; // clear the flag for event 1
ECap1Regs.ECCLR.bit.CEVT2 = 1;
ECap1Regs.ECEINT.bit.CEVT1 = 0;
ECap1Regs.ECEINT.bit.CEVT2 = 1;
}
if( ( ECap1Regs.ECFLG.bit.CEVT2 == 1 )&&( EPwm1Regs.AQCSFRC.bit.CSFB == 2 ) )
{
capcount2++;
LED2 = ~LED2;
EPwm1Regs.AQCSFRC.bit.CSFB = 1;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
ECap1Regs.ECCLR.bit.CEVT2 = 1; // clear the flag for event 2
ECap1Regs.ECEINT.bit.CEVT1 = 1;
ECap1Regs.ECEINT.bit.CEVT2 = 0;
}
ECap1Regs.ECCLR.bit.INT = 1; // clear the global interrupt flag;
ECap1Regs.ECCTL2.bit.REARM = EC_ARM; // acknowledge next interrupt
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
I look up the registers, it indicates that every time when it goes into the interrupt, the ECap1Regs.ECFLG.bit.CEVT1 and ECap1Regs.ECFLG.bit.CEVT2 will both chaned to 1, I guess the configuration
ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2; // stop at event 2
might be the cause. but if this bit is set at EC_EVENT1, it can't detect the falling edge,right?
So I wonder if there any solutions to solve this problem, better not use the interrupt.
Thank you.
Regards,