TI中文支持网
TI专业的中文技术问题搜集分享网站

ECAP1不会中断

我想用F28035的ECAP1引脚作为外部中断引脚,配置如下:

//———————-ECAP1设置——————————-

 EALLOW;

 GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // 0=GPIO,  1=SPISTE-A,  2=LINRX-A,  3=ECAP1  

GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;  // 1=OUTput,  0=INput  

GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;     // Enable pull-up on GPIO19 (CAP1)  

GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 0;   // Synch to SYSCLKOUT GPIO19 (CAP1)  

PieVectTable.ECAP1_INT = &ECAP1_ISR;

 EDIS;  

InitECapture();

 IER |= M_INT4;  

PieCtrlRegs.PIEIER4.bit.INTx1 = 1;   // Enable interrupt ECAP1_INT

 

void InitECapture() {   

ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts   

ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags   

ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads   

 ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped

   // Configure peripheral registers   

ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // One-shot   

ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // Stop at 4 events   

ECap1Regs.ECCTL1.bit.CAP1POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CAP3POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP4POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST2 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST3 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST4 = 1;          // Difference operation   

ECap1Regs.ECCTL2.bit.SYNCI_EN = 1;         // Enable sync in   

ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;        // Pass through   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units

   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter   

ECap1Regs.ECCTL2.bit.REARM = 1;            // arm one-shot   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads   

 ECap1Regs.ECEINT.bit.CEVT4 = 1;            // 4 events = interrupt

}

interrupt void ECAP1_ISR(void)

GpioDataRegs.GPBTOGGLE.bit.GPIO43 = 1;

 ECap1Regs.ECCLR.bit.CEVT4 = 1;

 ECap1Regs.ECCLR.bit.INT = 1;    

ECap1Regs.ECCTL2.bit.REARM = 1;    

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;

}

仿真时给ECAP1引脚输入方波信号,但程序始终不会进入中断,但将ECFRC相应的位置1就能进入中断。不知为何?

mangui zhang:

配置代码供你参考     还有输入的方波幅值保证在一定的电压范围

 ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts禁止所有的捕获中断                   ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags清除所有的捕获标志位                   ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads禁止加载CAP1-CAP4寄存器                   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped确保计数器停止计数                   ECap1Regs.TSCTR = 0;                   // Configure peripheral registers                   ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0;      // 连续触发模式                   ECap1Regs.ECCTL1.bit.CAP1POL = 0;          // 上升沿                   ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // 上升沿                   ECap1Regs.ECCTL1.bit.CAP3POL = 0;          // 上升沿                   ECap1Regs.ECCTL1.bit.CAP4POL = 0;          // 上升沿                   ECap1Regs.ECCTL1.bit.CTRRST1 = 0;          // 不使能重新计数                   ECap1Regs.ECCTL1.bit.CTRRST2 = 0;          // 不使能重新计数                   ECap1Regs.ECCTL1.bit.CTRRST3 = 0;          // 不使能重新计数                   ECap1Regs.ECCTL1.bit.CTRRST4 = 0;          // 不使能重新计数                   ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;         // 禁止                   ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2;        // 旁路时钟                   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // 使能捕获单元加载                   ECap1Regs.ECCTL1.bit.PRESCALE = 0;         // 不分频                   ECap1Regs.ECCTL2.bit.CAP_APWM = 0;         // 运行在CAP模式下                   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;                   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // 开启计数器                   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads                  ECap1Regs.ECEINT.bit.CEVT4 = 1;

我想用F28035的ECAP1引脚作为外部中断引脚,配置如下:

//———————-ECAP1设置——————————-

 EALLOW;

 GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // 0=GPIO,  1=SPISTE-A,  2=LINRX-A,  3=ECAP1  

GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;  // 1=OUTput,  0=INput  

GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;     // Enable pull-up on GPIO19 (CAP1)  

GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 0;   // Synch to SYSCLKOUT GPIO19 (CAP1)  

PieVectTable.ECAP1_INT = &ECAP1_ISR;

 EDIS;  

InitECapture();

 IER |= M_INT4;  

PieCtrlRegs.PIEIER4.bit.INTx1 = 1;   // Enable interrupt ECAP1_INT

 

void InitECapture() {   

ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts   

ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags   

ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads   

 ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped

   // Configure peripheral registers   

ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // One-shot   

ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // Stop at 4 events   

ECap1Regs.ECCTL1.bit.CAP1POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CAP3POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP4POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST2 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST3 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST4 = 1;          // Difference operation   

ECap1Regs.ECCTL2.bit.SYNCI_EN = 1;         // Enable sync in   

ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;        // Pass through   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units

   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter   

ECap1Regs.ECCTL2.bit.REARM = 1;            // arm one-shot   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads   

 ECap1Regs.ECEINT.bit.CEVT4 = 1;            // 4 events = interrupt

}

interrupt void ECAP1_ISR(void)

GpioDataRegs.GPBTOGGLE.bit.GPIO43 = 1;

 ECap1Regs.ECCLR.bit.CEVT4 = 1;

 ECap1Regs.ECCLR.bit.INT = 1;    

ECap1Regs.ECCTL2.bit.REARM = 1;    

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;

}

仿真时给ECAP1引脚输入方波信号,但程序始终不会进入中断,但将ECFRC相应的位置1就能进入中断。不知为何?

mangui zhang:

还有  相关设置请参考TI的手册

http://www.ti.com/cn/litv/pdf/sprufz8a

我想用F28035的ECAP1引脚作为外部中断引脚,配置如下:

//———————-ECAP1设置——————————-

 EALLOW;

 GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // 0=GPIO,  1=SPISTE-A,  2=LINRX-A,  3=ECAP1  

GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;  // 1=OUTput,  0=INput  

GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;     // Enable pull-up on GPIO19 (CAP1)  

GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 0;   // Synch to SYSCLKOUT GPIO19 (CAP1)  

PieVectTable.ECAP1_INT = &ECAP1_ISR;

 EDIS;  

InitECapture();

 IER |= M_INT4;  

PieCtrlRegs.PIEIER4.bit.INTx1 = 1;   // Enable interrupt ECAP1_INT

 

void InitECapture() {   

ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts   

ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags   

ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads   

 ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped

   // Configure peripheral registers   

ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // One-shot   

ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // Stop at 4 events   

ECap1Regs.ECCTL1.bit.CAP1POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CAP3POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP4POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST2 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST3 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST4 = 1;          // Difference operation   

ECap1Regs.ECCTL2.bit.SYNCI_EN = 1;         // Enable sync in   

ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;        // Pass through   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units

   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter   

ECap1Regs.ECCTL2.bit.REARM = 1;            // arm one-shot   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads   

 ECap1Regs.ECEINT.bit.CEVT4 = 1;            // 4 events = interrupt

}

interrupt void ECAP1_ISR(void)

GpioDataRegs.GPBTOGGLE.bit.GPIO43 = 1;

 ECap1Regs.ECCLR.bit.CEVT4 = 1;

 ECap1Regs.ECCLR.bit.INT = 1;    

ECap1Regs.ECCTL2.bit.REARM = 1;    

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;

}

仿真时给ECAP1引脚输入方波信号,但程序始终不会进入中断,但将ECFRC相应的位置1就能进入中断。不知为何?

shi xiaming:

回复 mangui zhang:

谢谢你的回复,后来我自己发现错误地配置了两个ECAP1口,去掉了另外一个就行了。

我想用F28035的ECAP1引脚作为外部中断引脚,配置如下:

//———————-ECAP1设置——————————-

 EALLOW;

 GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // 0=GPIO,  1=SPISTE-A,  2=LINRX-A,  3=ECAP1  

GpioCtrlRegs.GPADIR.bit.GPIO19 = 0;  // 1=OUTput,  0=INput  

GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;     // Enable pull-up on GPIO19 (CAP1)  

GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 0;   // Synch to SYSCLKOUT GPIO19 (CAP1)  

PieVectTable.ECAP1_INT = &ECAP1_ISR;

 EDIS;  

InitECapture();

 IER |= M_INT4;  

PieCtrlRegs.PIEIER4.bit.INTx1 = 1;   // Enable interrupt ECAP1_INT

 

void InitECapture() {   

ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts   

ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags   

ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads   

 ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped

   // Configure peripheral registers   

ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // One-shot   

ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // Stop at 4 events   

ECap1Regs.ECCTL1.bit.CAP1POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CAP3POL = 1;          // Falling edge   

ECap1Regs.ECCTL1.bit.CAP4POL = 0;          // Rising edge   

ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST2 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST3 = 1;          // Difference operation   

ECap1Regs.ECCTL1.bit.CTRRST4 = 1;          // Difference operation   

ECap1Regs.ECCTL2.bit.SYNCI_EN = 1;         // Enable sync in   

ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;        // Pass through   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units

   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter   

ECap1Regs.ECCTL2.bit.REARM = 1;            // arm one-shot   

ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads   

 ECap1Regs.ECEINT.bit.CEVT4 = 1;            // 4 events = interrupt

}

interrupt void ECAP1_ISR(void)

GpioDataRegs.GPBTOGGLE.bit.GPIO43 = 1;

 ECap1Regs.ECCLR.bit.CEVT4 = 1;

 ECap1Regs.ECCLR.bit.INT = 1;    

ECap1Regs.ECCTL2.bit.REARM = 1;    

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;

}

仿真时给ECAP1引脚输入方波信号,但程序始终不会进入中断,但将ECFRC相应的位置1就能进入中断。不知为何?

mangui zhang:

回复 shi xiaming:

两个CAP是能够同时工作的   相互不会影响   

各自都有自己的通用定时器

赞(0)
未经允许不得转载:TI中文支持网 » ECAP1不会中断
分享到: 更多 (0)