我最近在用TI的DSP芯片,型号是TMS320F2808,打算用里面的eCAP模块测直流无刷电机的霍尔信号频率,以此来测速。
我先用一块我做的板子发送PWM波,然后用eCAP测频率,测出来的没有问题,用信号发生器发的PWM波测起来也很准。。。但是当我接上电机后,问题就来了,无论电机的转速是多少ecap测出来的频率都是25K。。。用示波器看霍尔信号才50Hz....我有用自己做的板子发50Hz的PWM,测的也没问题。。。总之就是一测霍尔的信号就固定的是25K了。。。霍尔信号和自己发的信号都是5V的方波。
我测试的思路是用CAP2和CAP4都是下降沿触发,CAP1,CAP3是上升沿触发 。然后在CEVT4的中断里用CAP4减去CAP2就能得到一个波的时间了,然后算频率
eCAP设置如下:
ECap2Regs.ECEINT.all = 0x0000;
ECap2Regs.ECCLR.all = 0xFFFF; ECap2Regs.ECCTL1.bit.CAPLDEN = 0; ECap2Regs.ECCTL2.bit.TSCTRSTOP = 0;
ECap2Regs.ECCTL2.bit.CONT_ONESHT = 0; ECap2Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap2Regs.ECCTL1.bit.CAP1POL = 1; ECap2Regs.ECCTL1.bit.CAP2POL = 0; ECap2Regs.ECCTL1.bit.CAP3POL = 1; ECap2Regs.ECCTL1.bit.CAP4POL = 0; ECap2Regs.ECCTL1.bit.CTRRST1 = 0; // Difference operation
ECap2Regs.ECCTL1.bit.CTRRST2 = 0; // Difference operation
ECap2Regs.ECCTL1.bit.CTRRST3 = 0; // Difference operation
ECap2Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
ECap2Regs.ECCTL2.bit.SYNCI_EN = 0; // Enable sync in
ECap2Regs.ECCTL2.bit.SYNCO_SEL = 2; // Pass through
ECap2Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units
ECap2Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
ECap2Regs.ECCTL1.bit.CAPLDEN = 1; ECap2Regs.ECEINT.bit.CEVT4 = 1; // 4 events = interrupt
CAP4的中断函数如下:
interrupt void ecap_test_isr(void)
{
Uint32 aa1=0,aa2=0,aa3=0;
if(ECap2Regs.CAP4 > ECap2Regs.CAP2)
{
aa1= ECap2Regs.CAP4;
aa2= ECap2Regs.CAP2;
aa3=aa1-aa2;
speed[ECap1PassCount]=aa3;
aa3=0;
ECap1PassCount++;
}
if(ECap1PassCount==100)
{
ECap1PassCount=0;
}
ECap2Regs.ECCLR.bit.CEVT4 = 1;
ECap2Regs.ECCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
} |