我现在是采样50Hz的频率,配置如下:
void InitECap(void)
{
// Initialize eCAP1
ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
// Configure peripheral registers
ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap1Regs.ECCTL1.bit.CAP1POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CAP2POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CAP3POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CAP4POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 0; // ABS operation
ECap1Regs.ECCTL1.bit.CTRRST2 = 0; // ABS operation
ECap1Regs.ECCTL1.bit.CTRRST3 = 0; // ABS operation
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // ABS operation
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // Continuous
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; // Disable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2; // Pass through
void InitECap(void)
{
// Initialize eCAP1
ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
// Configure peripheral registers
ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap1Regs.ECCTL1.bit.CAP1POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CAP2POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CAP3POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CAP4POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 0; // ABS operation
ECap1Regs.ECCTL1.bit.CTRRST2 = 0; // ABS operation
ECap1Regs.ECCTL1.bit.CTRRST3 = 0; // ABS operation
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // ABS operation
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // Continuous
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; // Disable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2; // Pass through
ECap1Regs.ECCTL2.bit.CAP_APWM = 0; //eCap Mode
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap1Regs.ECEINT.bit.CEVT1 = 1; // 1 events = interrupt
ECap1Regs.ECEINT.bit.CEVT2 = 1; // 2 events = interrupt
ECap1Regs.ECEINT.bit.CEVT3 = 1; // 3 events = interrupt
ECap1Regs.ECEINT.bit.CEVT4 = 1; // 4 events = interrupt
}
这是监视到中断里捕获的值,前面都正常,你看下[34]~[36],为什么会有相同的几个值?