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

eCAP模块配置问题

我想使用eCAP模块每个PWM波的上升下降沿都触发中断,并且计算两两中断之间的时间,可是遇到了问题,利用event4触发中断也就是第四个边沿触发中断可以读取寄存器ECap1Regs.CAP1、ECap1Regs.CAP2、ECap1Regs.CAP3、ECap1Regs.CAP4的数据得到三段脉冲之间的时间数据,可是我设置使能event1,event2,event3,event4都触发中断,却每次只能在寄存器ECap1Regs.CAP1读到数据,且读取到的数据是每个PWM波一个周期的时间也就是说,只是获取了上升沿或则下降沿的时间。我的配置如下,需要修改哪里呢?

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; // Operate in one-Shot mode
// ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; // Operate in continuous mode

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

ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING; // Rising edge
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING; // Falling edge
ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING; // Rising edge
ECap1Regs.ECCTL1.bit.CAP4POL = EC_FALLING; // Falling edge
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE; // Difference operation

ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Enable sync in
// ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; // Disable sync-in option
// ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0; // Select sync-in event to be the sync-out signal (pass through)
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS; // Disable sync out signal
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units

ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;   // 预分频系数 1 // 20170410
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; // CAP模式

ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; // Start Counter (TSCTR free-running)
ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE; // 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

HeiHei:

这个在ecap模块的datasheet里都有专门的例子和代码设置 你可以去参考下

我想使用eCAP模块每个PWM波的上升下降沿都触发中断,并且计算两两中断之间的时间,可是遇到了问题,利用event4触发中断也就是第四个边沿触发中断可以读取寄存器ECap1Regs.CAP1、ECap1Regs.CAP2、ECap1Regs.CAP3、ECap1Regs.CAP4的数据得到三段脉冲之间的时间数据,可是我设置使能event1,event2,event3,event4都触发中断,却每次只能在寄存器ECap1Regs.CAP1读到数据,且读取到的数据是每个PWM波一个周期的时间也就是说,只是获取了上升沿或则下降沿的时间。我的配置如下,需要修改哪里呢?

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; // Operate in one-Shot mode
// ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; // Operate in continuous mode

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

ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING; // Rising edge
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING; // Falling edge
ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING; // Rising edge
ECap1Regs.ECCTL1.bit.CAP4POL = EC_FALLING; // Falling edge
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE; // Difference operation

ECap1Regs.ECCTL2.bit.SYNCI_EN = 1; // Enable sync in
// ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; // Disable sync-in option
// ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0; // Select sync-in event to be the sync-out signal (pass through)
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS; // Disable sync out signal
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units

ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;   // 预分频系数 1 // 20170410
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; // CAP模式

ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN; // Start Counter (TSCTR free-running)
ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE; // 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

Emma Wang:

请检查EC_ABS_MODE的值是0还是1,可以设置为1,在相应的捕获后重置计数器,使其工作于差分模式下。

另外,很想知道你为什么要设置四个中断,按ECAP模块通常的应用来看,设置一个中断就可以读取4个CAP寄存器中锁存的时间标志寄存器TSCTR的值。

赞(0)
未经允许不得转载:TI中文支持网 » eCAP模块配置问题
分享到: 更多 (0)