Hello everyone, I have encountered some problems when using the CAP module. After reading several eCAP examples from TI, I still have some questions about the configuration. The examples basically use interrupts, and CAP1-4 of the eCAP1 module are all used, and then calculate the frequency and so on.
The function I want to achieve is: for example, EPwm1A outputs a 50Hz square wave, and sends the square wave to the ECAP1 port for detection. When detecting the rising edge, EPwm1B is forced to be high, and when detecting the falling edge, EPwm1B is forced to be low (in fact, it is to detect the zero crossing point of the grid voltage to generate a 50Hz square wave to drive an inverter bridge). Then I saw that the eCAP module will set the corresponding status bit CEVTx in the ECFLG register when a capture event occurs.
But I have two questions:
1. If the interrupt is not configured, will the status bit CEVTx be set when a capture event occurs? (In fact, I don't need to configure the interrupt, because the last section of the program will run in the system's interrupt program, so there is no need to add another interrupt.)
2. When using ECAP1, can I only use CAP1-2 and not 3-4? Because I only need to capture a rising edge, set EPwm1B high, and wait for the next rising edge; capture a falling edge, set EPwm1B low, and wait for the next falling edge.
I wrote a test program based on this idea, but the correct phenomenon did not occur. I felt that there was something wrong with the configuration, so I was not sure whether it was the cause of the interruption. The 50Hz pwm wave was generated normally, and the wiring was correct.
My ECAP1 configuration is as follows:
void SetCap1Mode(void)
{
ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CTRRST1
= EC_ABS_MODE
; bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap1Regs.ECEINT.all = 0x0000; //stop all interrupt
ECap1Regs.ECCLR.all = 0xFFFF; //clare all flag
ECap1Regs.ECCTL2.bit.REARM = EC_ARM;
ECap1Regs.ECCTL2. bit.TSCTRSTOP = EC_RUN; // Start
ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2;
}
This is how it is judged in the main loop (I always feel like something is missing, for example, should ECAP be restarted?)
while(1)
{
if( ECap1Regs.ECFLG.bit.CEVT1 ==1 )//when cap the rising,the flag CEVT1 will be set automatically
{
LED1 = ~LED1;
EPwm1Regs.AQCSFRC.bit.CSFB = 2;
ECap1Regs. ECCLR.bit.CEVT1 = 1; //clear the flag CEVT1 to wait for the next rising
}
if( ECap1Regs.ECFLG.bit.CEVT2 == 1 )//when cap the falling,the flag CEVT2 will be set automatically
{
LED2 = ~LED2;
EPwm1Regs.AQCSFRC.bit.CSFB = 1;
ECap1Regs.ECCLR.bit.CEVT2 = 1; //clear the flag CEVT2 to wait for the next falling
}
}
Hope to get some advice from experts, thank you!
|