例程如下:
void F281X_EV1_HALL3_Read(HALL3 *p)
{
{
p->CapFlag = EvaRegs.EVAIFRC.all; // Save capture flag register, convenient for Watch Window ##########EVAIFRC的2~0位控制cap1,2,3复位与否#########
if (p->CapFlag==0) // NO_EDGE_DETECTED: No hall signal edges detected on CAP1-3 (bits 0-2) #################CAP1-3 (bits 0-2),其他位保留,要是读取则为0######################
{
p->CmtnTrigHall = 0; // Reset trigger, it only handshakes with calling program.
if (p->EdgeDebounced==0) // If motor has not moved then debounce current position. { F281X_EV1_HALL3_Debounce(p);
p->CmtnTrigHall = p->EdgeDebounced; // Set Commutation trigger here
}
else // If current position is debounced, find match in table F281X_EV1_HALL3_Next_State_Ptr(p); // and return pointer to current state. Ptr to be incremented
// by MOD6CNT after RET.
p->EdgeDebounced = 0; // Reset trigger
}
else // EDGE_DETECTED: Any hall signal edges detected on CAP1-3
{
p->StallCount = 0xFFFF; // On new edge, reset stall counter
EvaRegs.EVAIFRC.all = 0x0007; // Clear all CAP1-3 Int-flags #############################复位cap1~3########################
F281X_EV1_HALL3_Determine_State(p); // Since motor has moved, determine state (read HallGpio)
p->CapCounter += 1; // Increment running edge detection counter
}
if (p->CapFlag==0) // NO_EDGE_DETECTED: No hall signal edges detected on CAP1-3 (bits 0-2) #################CAP1-3 (bits 0-2),其他位保留,要是读取则为0######################
{
p->CmtnTrigHall = 0; // Reset trigger, it only handshakes with calling program.
if (p->EdgeDebounced==0) // If motor has not moved then debounce current position. { F281X_EV1_HALL3_Debounce(p);
p->CmtnTrigHall = p->EdgeDebounced; // Set Commutation trigger here
}
else // If current position is debounced, find match in table F281X_EV1_HALL3_Next_State_Ptr(p); // and return pointer to current state. Ptr to be incremented
// by MOD6CNT after RET.
p->EdgeDebounced = 0; // Reset trigger
}
else // EDGE_DETECTED: Any hall signal edges detected on CAP1-3
{
p->StallCount = 0xFFFF; // On new edge, reset stall counter
EvaRegs.EVAIFRC.all = 0x0007; // Clear all CAP1-3 Int-flags #############################复位cap1~3########################
F281X_EV1_HALL3_Determine_State(p); // Since motor has moved, determine state (read HallGpio)
p->CapCounter += 1; // Increment running edge detection counter
}
各位大佬们好,我的问题是:不是检测是否边沿时,NO则调用debounce函数,那么不是if (p->CapFlag==0) 这句判断边沿与否吗?if (p->CapFlag==0) 这句 if (p->EdgeDebounced==0)又有什么作用呢,不是很理解EdgeDebounced==0是什么意思?
求大佬们救救孩纸吧!!!
Susan Yang:debounce是为了去除霍尔信号的抖动问题,相当于按键检测去抖动同样的原理。
一但边缘检测到,即霍尔信号有变化,那么先将霍尔信号状态保存下来。
下次进中断时,如果霍尔信号没有变化,那么就没有检测到边沿,开始进入到debounce程序去做去抖动,如果满足了去抖动检测,那么上次边缘的变化就被接收,因此进行换向处理。