foc/src/Foc/hall.c
2023-08-23 23:32:48 +08:00

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->measure_elec_angle = handle->phase_shift;
}
else if (handle->state == HALL_STATE_1)
{
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_60_PHASE_SHIFT);
}
else
{
}
break;
case HALL_STATE_1:
if (handle->state == HALL_STATE_5)
{
handle->direction = POSITIVE;
handle->measure_elec_angle = handle->phase_shift + S16_60_PHASE_SHIFT;
}
else if (handle->state == HALL_STATE_3)
{
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
}
else
{
}
break;
case HALL_STATE_3:
if (handle->state == HALL_STATE_1)
{
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
}
else if (handle->state == HALL_STATE_2)
{
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT +
S16_60_PHASE_SHIFT);
}
else
{
}
break;
case HALL_STATE_2:
if (handle->state == HALL_STATE_3)
{
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT + S16_60_PHASE_SHIFT);
}
else if (handle->state == HALL_STATE_6)
{
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
}
else
{
}
break;
case HALL_STATE_6:
if (handle->state == HALL_STATE_2)
{
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
}
else if (handle->state == HALL_STATE_4)
{
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
}
else
{
}
break;
case HALL_STATE_4:
if (handle->state == HALL_STATE_6)
{
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
}
else if (handle->state == HALL_STATE_5)
{
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift);
}
else
{
}
break;
default:
/* Bad hall sensor configutarion so update the speed reliability */
// handle->SensorIsReliable = 0;
break;
}
}