foc/src/Foc/hall.c

117 lines
3.2 KiB
C
Raw Normal View History

2023-08-23 03:05:48 +00:00
#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)
{
2023-08-23 15:32:48 +00:00
handle->direction = POSITIVE;
handle->measure_elec_angle = handle->phase_shift;
2023-08-23 03:05:48 +00:00
}
else if (handle->state == HALL_STATE_1)
{
2023-08-23 15:32:48 +00:00
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_60_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else
{
}
break;
case HALL_STATE_1:
if (handle->state == HALL_STATE_5)
{
2023-08-23 15:32:48 +00:00
handle->direction = POSITIVE;
handle->measure_elec_angle = handle->phase_shift + S16_60_PHASE_SHIFT;
2023-08-23 03:05:48 +00:00
}
else if (handle->state == HALL_STATE_3)
{
2023-08-23 15:32:48 +00:00
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else
{
}
break;
case HALL_STATE_3:
if (handle->state == HALL_STATE_1)
{
2023-08-23 15:32:48 +00:00
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else if (handle->state == HALL_STATE_2)
{
2023-08-23 15:32:48 +00:00
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT +
S16_60_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else
{
}
break;
case HALL_STATE_2:
if (handle->state == HALL_STATE_3)
{
2023-08-23 15:32:48 +00:00
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT + S16_60_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else if (handle->state == HALL_STATE_6)
{
2023-08-23 15:32:48 +00:00
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else
{
}
break;
case HALL_STATE_6:
if (handle->state == HALL_STATE_2)
{
2023-08-23 15:32:48 +00:00
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else if (handle->state == HALL_STATE_4)
{
2023-08-23 15:32:48 +00:00
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else
{
}
break;
case HALL_STATE_4:
if (handle->state == HALL_STATE_6)
{
2023-08-23 15:32:48 +00:00
handle->direction = POSITIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
2023-08-23 03:05:48 +00:00
}
else if (handle->state == HALL_STATE_5)
{
2023-08-23 15:32:48 +00:00
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift);
2023-08-23 03:05:48 +00:00
}
else
{
}
break;
default:
/* Bad hall sensor configutarion so update the speed reliability */
2023-08-23 15:32:48 +00:00
// handle->SensorIsReliable = 0;
2023-08-23 03:05:48 +00:00
break;
}
2023-09-06 02:28:44 +00:00
handle->state = new_state;
2023-08-23 03:05:48 +00:00
}