Thread 中讨论的其他器件:C2000WARE
工具与软件:
我想通过将方波信号应用于 GPIO 并匹配上升沿中断来测量该 GPIO 的频率。
__interrupt void Grid_ZCD(void)
{
// Disable ZCD int
Interrupt_disable(INT_XINT1);
Grid_ZCD_Flag = 2; // Grid ZCD flag set
mytimercount = CPUTimer_getTimerCount(CPUTIMER1_BASE);
CPUTimer_reloadTimerCounter(CPUTIMER1_BASE);
Grid_Period = 10000000 - mytimercount;
myT = 8.3333e-9 * (float) Grid_Period;
freq = 1 / (float) myT;
//
// Acknowledge this interrupt to receive more interrupts from group 1
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
}
这个方波有一个围绕边沿的抖动,所以为了避免错误的中断,我们在大约3/4的方波中禁用这个 Grid ZCD 中断。
这引起了很多问题。 此处、我们得到的测量频率值对应于 STOP_CYCLES。 如果它大约为80Hz、它将提供该值、就像之后立即触发中断一样。
if (Grid_ZCD_Flag == 1)
{
blanking_time++;
if (blanking_time >= stop_cycles)
{
blanking_time =0;
Grid_ZCD_Flag = 0;
// enable ZCD int
Interrupt_enable(INT_XINT1);
}
}
禁用/启用中断时是否出现错误? 您会建议什么替代方案?