116 lines
3.1 KiB
C
116 lines
3.1 KiB
C
|
#include "hall.h"
|
||
|
|
||
|
/**
|
||
|
* @brief 更新HALL状态
|
||
|
* @param handle
|
||
|
* @param new_state
|
||
|
*/
|
||
|
void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
||
|
{
|
||
|
switch (new_state)
|
||
|
{
|
||
|
case HALL_STATE_5:
|
||
|
if (handle->state == HALL_STATE_4)
|
||
|
{
|
||
|
handle->Direction = POSITIVE;
|
||
|
handle->MeasuredElAngle = handle->PhaseShift;
|
||
|
}
|
||
|
else if (handle->state == HALL_STATE_1)
|
||
|
{
|
||
|
handle->Direction = NEGATIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_60_PHASE_SHIFT);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case HALL_STATE_1:
|
||
|
if (handle->state == HALL_STATE_5)
|
||
|
{
|
||
|
handle->Direction = POSITIVE;
|
||
|
handle->MeasuredElAngle = handle->PhaseShift + S16_60_PHASE_SHIFT;
|
||
|
}
|
||
|
else if (handle->state == HALL_STATE_3)
|
||
|
{
|
||
|
handle->Direction = NEGATIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case HALL_STATE_3:
|
||
|
if (handle->state == HALL_STATE_1)
|
||
|
{
|
||
|
handle->Direction = POSITIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT);
|
||
|
}
|
||
|
else if (handle->state == HALL_STATE_2)
|
||
|
{
|
||
|
handle->Direction = NEGATIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT +
|
||
|
S16_60_PHASE_SHIFT);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
|
||
|
case HALL_STATE_2:
|
||
|
if (handle->state == HALL_STATE_3)
|
||
|
{
|
||
|
handle->Direction = POSITIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT + S16_60_PHASE_SHIFT);
|
||
|
}
|
||
|
else if (handle->state == HALL_STATE_6)
|
||
|
{
|
||
|
handle->Direction = NEGATIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_120_PHASE_SHIFT);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case HALL_STATE_6:
|
||
|
if (handle->state == HALL_STATE_2)
|
||
|
{
|
||
|
handle->Direction = POSITIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_120_PHASE_SHIFT);
|
||
|
}
|
||
|
else if (handle->state == HALL_STATE_4)
|
||
|
{
|
||
|
handle->Direction = NEGATIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_60_PHASE_SHIFT);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case HALL_STATE_4:
|
||
|
if (handle->state == HALL_STATE_6)
|
||
|
{
|
||
|
handle->Direction = POSITIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_60_PHASE_SHIFT);
|
||
|
}
|
||
|
else if (handle->state == HALL_STATE_5)
|
||
|
{
|
||
|
handle->Direction = NEGATIVE;
|
||
|
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
/* Bad hall sensor configutarion so update the speed reliability */
|
||
|
handle->SensorIsReliable = false;
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|