level 5
我想用定时器计时,用cap捕获,但都有中断,不能同时进行,该怎么办呢求大神指点!!!



ECAP的数值变化。定时器的不变化。没有脉冲之后,ecap的数值不变化,定时器的才变化。不能同时进行,求指点!!!!!下面是程序:
#include "DSP28x_Project.h"
interrupt void cpu_timer0_isr(void);
__interrupt void ecap1_isr(void);
void InitECapture(void);
Uint32 num;
float64 time_a,time_b,time;
Uint32 ECap1IntCount;
Uint32 ECap1PassCount;
void main(void)
{
InitSysCtrl();
InitECap1Gpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.ECAP1_INT = &ecap1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
InitECapture();
InitCpuTimers(); // For this example, only initialize the Cpu Timers
#if (CPU_FRQ_150MHZ)
ConfigCpuTimer(&CpuTimer0, 150, 500000);
#endif
#if (CPU_FRQ_100MHZ)
ConfigCpuTimer(&CpuTimer0, 100, 500000);
#endif
CpuTimer0Regs.TCR.all = 0x4011; // Use write-only instruction to set TSS bit = 0
num=0;
ECap1IntCount = 0;
ECap1PassCount = 0;
time_a=0;
time_b=0;
time=0;
IER |= M_INT1;
IER |= M_INT4;
PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;);
}
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 = 0; // 连续模式
ECap1Regs.ECCTL2.bit.STOP_WRAP = 0; // Stop at 3 events
ECap1Regs.ECCTL1.bit.CAP1POL = 0; // Rising edge
//ECap1Regs.ECCTL1.bit.CAP2POL = 1; // Falling edge
//ECap1Regs.ECCTL1.bit.CAP3POL = 0; // Rising edge
// ECap1Regs.ECCTL1.bit.CAP4POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // Difference operation
//ECap1Regs.ECCTL1.bit.CTRRST2 = 0; // 不复位.
//ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation
//ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Disable 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; // 使能捕获寄存器装载
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap1Regs.ECEINT.bit.CEVT1 = 1; // 0 events = interrupt
}
__interrupt void ecap1_isr(void)
{
CpuTimer0Regs.TCR.bit.TSS=0;
ECap1IntCount++;
if(ECap1IntCount==11)
{
CpuTimer0Regs.TCR.bit.TSS=1;
ECap1IntCount=0;
time_b=CpuTimer0.InterruptCount*0.5+(75000000-CpuTimer0Regs.PRD.all)*(1.0/150000000);
CpuTimer0Regs.TCR.bit.TRB=1;
CpuTimer0.InterruptCount=0;
time=time_b-time_a;
time_a=time_b;
}
ECap1PassCount++;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
2019年03月29日 02点03分
1



ECAP的数值变化。定时器的不变化。没有脉冲之后,ecap的数值不变化,定时器的才变化。不能同时进行,求指点!!!!!下面是程序:#include "DSP28x_Project.h"
interrupt void cpu_timer0_isr(void);
__interrupt void ecap1_isr(void);
void InitECapture(void);
Uint32 num;
float64 time_a,time_b,time;
Uint32 ECap1IntCount;
Uint32 ECap1PassCount;
void main(void)
{
InitSysCtrl();
InitECap1Gpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.ECAP1_INT = &ecap1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
InitECapture();
InitCpuTimers(); // For this example, only initialize the Cpu Timers
#if (CPU_FRQ_150MHZ)
ConfigCpuTimer(&CpuTimer0, 150, 500000);
#endif
#if (CPU_FRQ_100MHZ)
ConfigCpuTimer(&CpuTimer0, 100, 500000);
#endif
CpuTimer0Regs.TCR.all = 0x4011; // Use write-only instruction to set TSS bit = 0
num=0;
ECap1IntCount = 0;
ECap1PassCount = 0;
time_a=0;
time_b=0;
time=0;
IER |= M_INT1;
IER |= M_INT4;
PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;);
}
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 = 0; // 连续模式
ECap1Regs.ECCTL2.bit.STOP_WRAP = 0; // Stop at 3 events
ECap1Regs.ECCTL1.bit.CAP1POL = 0; // Rising edge
//ECap1Regs.ECCTL1.bit.CAP2POL = 1; // Falling edge
//ECap1Regs.ECCTL1.bit.CAP3POL = 0; // Rising edge
// ECap1Regs.ECCTL1.bit.CAP4POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // Difference operation
//ECap1Regs.ECCTL1.bit.CTRRST2 = 0; // 不复位.
//ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation
//ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Disable 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; // 使能捕获寄存器装载
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap1Regs.ECEINT.bit.CEVT1 = 1; // 0 events = interrupt
}
__interrupt void ecap1_isr(void)
{
CpuTimer0Regs.TCR.bit.TSS=0;
ECap1IntCount++;
if(ECap1IntCount==11)
{
CpuTimer0Regs.TCR.bit.TSS=1;
ECap1IntCount=0;
time_b=CpuTimer0.InterruptCount*0.5+(75000000-CpuTimer0Regs.PRD.all)*(1.0/150000000);
CpuTimer0Regs.TCR.bit.TRB=1;
CpuTimer0.InterruptCount=0;
time=time_b-time_a;
time_a=time_b;
}
ECap1PassCount++;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}