void HALL_Init_Electrical_Angle(void)
{
#if (HALL_SENSORS_PLACEMENT == DEGREES_120)
switch(ReadHallState())
{
case STATE_5:
hElectrical_Angle = (s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT/2);
break;
case STATE_1:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT+
S16_60_PHASE_SHIFT/2);
break;
case STATE_3:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT+S16_120_PHASE_SHIFT+
S16_60_PHASE_SHIFT/2);
break;
case STATE_2:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT-S16_120_PHASE_SHIFT-
S16_60_PHASE_SHIFT/2);
break;
case STATE_6:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT-S16_60_PHASE_SHIFT-
S16_60_PHASE_SHIFT/2);
break;
case STATE_4:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT-S16_60_PHASE_SHIFT/2);
break;
default:
break;
}
#elif (HALL_SENSORS_PLACEMENT == DEGREES_60)
switch(ReadHallState())
{
case STATE_1:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT/2);
break;
case STATE_3:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT+
S16_60_PHASE_SHIFT/2);
break;
case STATE_7:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT+S16_120_PHASE_SHIFT+
S16_60_PHASE_SHIFT/2);
break;
case STATE_6:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT-S16_120_PHASE_SHIFT-
S16_60_PHASE_SHIFT/2);
break;
case STATE_4:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT-S16_60_PHASE_SHIFT-
S16_60_PHASE_SHIFT/2);
break;
case STATE_0:
hElectrical_Angle =(s16)(S16_PHASE_SHIFT-S16_60_PHASE_SHIFT/2);
break;
default:
break;
}
#endif
}
霍尔电角度上电初始化时,各个状态的电角度已经规定好了的,怎么在霍尔中断处理程序里的值表现不一样呢?
#if (HALL_SENSORS_PLACEMENT == DEGREES_120)
switch(bHallState)
{
case STATE_5:
if (bPrevHallState == STATE_5)
{
//a speed reversal occured
if(bSpeed<0)
{
bSpeed = POSITIVE_SWAP;
}
else
{
bSpeed = NEGATIVE_SWAP;
}
}
else
if (bPrevHallState == STATE_6)
{
bSpeed = POSITIVE;
}
else
if (bPrevHallState == STATE_3)
{
bSpeed = NEGATIVE;
}
// Update angle
if(bSpeed<0)
{
hElectrical_Angle = (s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT);
}
else if(bSpeed!= ERROR)
{
hElectrical_Angle = S16_PHASE_SHIFT;
}
break;
如上图,上一个状态bPrevHallState是5,这次 bHallState还是5,应该霍尔出错啊,
电角度初始化时case STATE_5:
hElectrical_Angle = (s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT/2);
break;
到中断时// Update angle
if(bSpeed<0)
{
hElectrical_Angle = (s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT);
}
怎么不一样了呢?各位大侠不吝赐教
|