我尝试利用ECAP抓取几个脉冲,中断后修改PWM信号的占空比。但是一直不成功。我PWM发生是参考例程“Example_2802xEPwmUpDownAQ”,这里面有3个中断。可以利用外部按键产生中断,然后占空比成功改变。我ECAP抓取参考的例程“Example_2802xECap_Capture_Pwm”。但是当我吧ECAP中断加入到第一个程序中后,一直进入不了中断。按键依旧可以控制PWM,但是就是ECAP中断进入不了。我也尝试修改了这些中断的优先级,参考的是例程“Example_2802xSWPrioritizedInterrupts”,还是不成功。当这四个中断在一起时,总也无法触发ECAP中断。
请问我的问题出在了哪里?谢谢帮助
我的配置程序如下:
#define ISRS_GROUP3 (M_INT1|M_INT2|M_INT3|M_INT4) #define ISRS_GROUP4 (M_INT1|M_INT3|M_INT4)IER = 0x0000;IFR &= 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in f2802x_DefaultIsr.c. // This function is found in f2802x_PieVect.c.InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file.EALLOW; // This is needed to write to EALLOW protected registersPieVectTable.EPWM1_INT = &epwm1_isr;PieVectTable.EPWM2_INT = &epwm2_isr;PieVectTable.EPWM3_INT = &epwm3_isr;PieVectTable.ECAP1_INT = &ecap1_isr;EDIS;// This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in f2802x_InitPeripherals.c // InitPeripherals(); // Not required for this example // For this example, only initialize the ePWMEALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();InitECapture();EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;EDIS; // Step 5. User specific code, enable interrupts: // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr() // EPwm3_timer_isr and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker.memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // Call Flash Initialization to setup flash waitstates // This function must reside in RAMInitFlash(); // Enable CPU INT3 which is connected to EPWM1-3 INT:ECap1IntCount = 0;ECap1PassCount = 0;PieCtrlRegs.PIECTRL.bit.ENPIE = 1;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;PieCtrlRegs.PIEIER3.bit.INTx2 = 1;PieCtrlRegs.PIEIER3.bit.INTx3 = 1;PieCtrlRegs.PIEIER4.bit.INTx1 = 1; //PieCtrlRegs.PIEIER3.all = 0x00FF; //PieCtrlRegs.PIEIER4.all = 0x00FF;PieCtrlRegs.PIEACK.all = (M_INT3|M_INT4);IER |= (M_INT3|M_INT4); //PieCtrlRegs.PIEIFR3.all = ISRS_GROUP3; //PieCtrlRegs.PIEIFR4.all = ISRS_GROUP4; // Enable global Interrupts and higher priority real-time debug events:EINT;// Enable Global interrupt INTMERTM;// Enable Global realtime interrupt DBGM
ECAP 初始化程序如下
void InitECapture() {ECap1Regs.ECEINT.all = 0x0000;// Disable all capture interruptsECap1Regs.ECCLR.all = 0xFFFF;// Clear all CAP interrupt flagsECap1Regs.ECCTL1.bit.CAPLDEN = 0;// Disable CAP1-CAP4 register loadsECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;// Make sure the counter is stopped// Configure peripheral registersECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;// One-shotECap1Regs.ECCTL2.bit.STOP_WRAP = 3;// Stop at 4 eventsECap1Regs.ECCTL1.bit.CAP1POL = 1;// Falling edgeECap1Regs.ECCTL1.bit.CAP2POL = 0;// Rising edgeECap1Regs.ECCTL1.bit.CAP3POL = 1;// Falling edgeECap1Regs.ECCTL1.bit.CAP4POL = 0;// Rising edgeECap1Regs.ECCTL1.bit.CTRRST1 = 1;// Difference operationECap1Regs.ECCTL1.bit.CTRRST2 = 1;// Difference operationECap1Regs.ECCTL1.bit.CTRRST3 = 1;// Difference operationECap1Regs.ECCTL1.bit.CTRRST4 = 1;// Difference operationECap1Regs.ECCTL2.bit.SYNCI_EN = 0;// Enable sync inECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;// Pass throughECap1Regs.ECCTL1.bit.CAPLDEN = 1;// Enable capture unitsECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;// Start CounterECap1Regs.ECCTL2.bit.REARM = 1;// arm one-shotECap1Regs.ECCTL1.bit.CAPLDEN = 1;// Enable CAP1-CAP4 register loadsECap1Regs.ECEINT.bit.CEVT4 = 1;// 4 events = interrupt }
4个中断程序如下:
__interrupt void epwm1_isr(void){my code} __interrupt void epwm2_isr(void){my code} __interrupt void epwm3_isr(void){my code} __interrupt void ecap1_isr(void){my code}
ChuShan Zhang:
同问,最后解决了吗?我用ecap中断测速,用ewpm中断进行转速电流双闭环控制,碰到了一样的情况,进不去ecap中断
我尝试利用ECAP抓取几个脉冲,中断后修改PWM信号的占空比。但是一直不成功。我PWM发生是参考例程“Example_2802xEPwmUpDownAQ”,这里面有3个中断。可以利用外部按键产生中断,然后占空比成功改变。我ECAP抓取参考的例程“Example_2802xECap_Capture_Pwm”。但是当我吧ECAP中断加入到第一个程序中后,一直进入不了中断。按键依旧可以控制PWM,但是就是ECAP中断进入不了。我也尝试修改了这些中断的优先级,参考的是例程“Example_2802xSWPrioritizedInterrupts”,还是不成功。当这四个中断在一起时,总也无法触发ECAP中断。
请问我的问题出在了哪里?谢谢帮助
我的配置程序如下:
#define ISRS_GROUP3 (M_INT1|M_INT2|M_INT3|M_INT4) #define ISRS_GROUP4 (M_INT1|M_INT3|M_INT4)IER = 0x0000;IFR &= 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in f2802x_DefaultIsr.c. // This function is found in f2802x_PieVect.c.InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file.EALLOW; // This is needed to write to EALLOW protected registersPieVectTable.EPWM1_INT = &epwm1_isr;PieVectTable.EPWM2_INT = &epwm2_isr;PieVectTable.EPWM3_INT = &epwm3_isr;PieVectTable.ECAP1_INT = &ecap1_isr;EDIS;// This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in f2802x_InitPeripherals.c // InitPeripherals(); // Not required for this example // For this example, only initialize the ePWMEALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();InitECapture();EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;EDIS; // Step 5. User specific code, enable interrupts: // Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr() // EPwm3_timer_isr and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker.memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // Call Flash Initialization to setup flash waitstates // This function must reside in RAMInitFlash(); // Enable CPU INT3 which is connected to EPWM1-3 INT:ECap1IntCount = 0;ECap1PassCount = 0;PieCtrlRegs.PIECTRL.bit.ENPIE = 1;PieCtrlRegs.PIEIER3.bit.INTx1 = 1;PieCtrlRegs.PIEIER3.bit.INTx2 = 1;PieCtrlRegs.PIEIER3.bit.INTx3 = 1;PieCtrlRegs.PIEIER4.bit.INTx1 = 1; //PieCtrlRegs.PIEIER3.all = 0x00FF; //PieCtrlRegs.PIEIER4.all = 0x00FF;PieCtrlRegs.PIEACK.all = (M_INT3|M_INT4);IER |= (M_INT3|M_INT4); //PieCtrlRegs.PIEIFR3.all = ISRS_GROUP3; //PieCtrlRegs.PIEIFR4.all = ISRS_GROUP4; // Enable global Interrupts and higher priority real-time debug events:EINT;// Enable Global interrupt INTMERTM;// Enable Global realtime interrupt DBGM
ECAP 初始化程序如下
void InitECapture() {ECap1Regs.ECEINT.all = 0x0000;// Disable all capture interruptsECap1Regs.ECCLR.all = 0xFFFF;// Clear all CAP interrupt flagsECap1Regs.ECCTL1.bit.CAPLDEN = 0;// Disable CAP1-CAP4 register loadsECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;// Make sure the counter is stopped// Configure peripheral registersECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;// One-shotECap1Regs.ECCTL2.bit.STOP_WRAP = 3;// Stop at 4 eventsECap1Regs.ECCTL1.bit.CAP1POL = 1;// Falling edgeECap1Regs.ECCTL1.bit.CAP2POL = 0;// Rising edgeECap1Regs.ECCTL1.bit.CAP3POL = 1;// Falling edgeECap1Regs.ECCTL1.bit.CAP4POL = 0;// Rising edgeECap1Regs.ECCTL1.bit.CTRRST1 = 1;// Difference operationECap1Regs.ECCTL1.bit.CTRRST2 = 1;// Difference operationECap1Regs.ECCTL1.bit.CTRRST3 = 1;// Difference operationECap1Regs.ECCTL1.bit.CTRRST4 = 1;// Difference operationECap1Regs.ECCTL2.bit.SYNCI_EN = 0;// Enable sync inECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;// Pass throughECap1Regs.ECCTL1.bit.CAPLDEN = 1;// Enable capture unitsECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;// Start CounterECap1Regs.ECCTL2.bit.REARM = 1;// arm one-shotECap1Regs.ECCTL1.bit.CAPLDEN = 1;// Enable CAP1-CAP4 register loadsECap1Regs.ECEINT.bit.CEVT4 = 1;// 4 events = interrupt }
4个中断程序如下:
__interrupt void epwm1_isr(void){my code} __interrupt void epwm2_isr(void){my code} __interrupt void epwm3_isr(void){my code} __interrupt void ecap1_isr(void){my code}
user4669117:
回复 ChuShan Zhang:
同问,我测速的时候也进不去中断,请问解决了吗?