This commit is contained in:
MQjehovah 2023-08-23 23:32:48 +08:00
parent 333c040db5
commit fa67d84a46
6 changed files with 55 additions and 43 deletions

View File

@ -11,6 +11,9 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
hall_handle_t hall_handle;
/* Function ------------------------------------------------------------------*/
/**

View File

@ -23,6 +23,8 @@ extern "C"
#include "usart.h"
#include "gpio.h"
#include "hall.h"
/* Functions ----------------------------------------------------------------*/
extern void board_init(void);

View File

@ -12,13 +12,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
case HALL_STATE_5:
if (handle->state == HALL_STATE_4)
{
handle->Direction = POSITIVE;
handle->MeasuredElAngle = handle->PhaseShift;
handle->direction = POSITIVE;
handle->measure_elec_angle = handle->phase_shift;
}
else if (handle->state == HALL_STATE_1)
{
handle->Direction = NEGATIVE;
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_60_PHASE_SHIFT);
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_60_PHASE_SHIFT);
}
else
{
@ -28,13 +28,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
case HALL_STATE_1:
if (handle->state == HALL_STATE_5)
{
handle->Direction = POSITIVE;
handle->MeasuredElAngle = handle->PhaseShift + S16_60_PHASE_SHIFT;
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->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT);
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
}
else
{
@ -44,14 +44,14 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
case HALL_STATE_3:
if (handle->state == HALL_STATE_1)
{
handle->Direction = POSITIVE;
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT);
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->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT +
S16_60_PHASE_SHIFT);
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT +
S16_60_PHASE_SHIFT);
}
else
{
@ -62,13 +62,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
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);
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->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_120_PHASE_SHIFT);
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
}
else
{
@ -78,13 +78,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
case HALL_STATE_6:
if (handle->state == HALL_STATE_2)
{
handle->Direction = POSITIVE;
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_120_PHASE_SHIFT);
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->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_60_PHASE_SHIFT);
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
}
else
{
@ -94,13 +94,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
case HALL_STATE_4:
if (handle->state == HALL_STATE_6)
{
handle->Direction = POSITIVE;
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_60_PHASE_SHIFT);
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->MeasuredElAngle = (int16_t)(handle->PhaseShift);
handle->direction = NEGATIVE;
handle->measure_elec_angle = (int16_t)(handle->phase_shift);
}
else
{
@ -109,7 +109,7 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
default:
/* Bad hall sensor configutarion so update the speed reliability */
handle->SensorIsReliable = 0;
// handle->SensorIsReliable = 0;
break;
}

View File

@ -30,9 +30,6 @@ enum
typedef struct
{
// |||
// |||
// |||
uint8_t state; // 霍尔状态真值表
int16_t phase_shift; // 同步电角度

View File

@ -1,10 +1,11 @@
#include "svpwm.h"
void svpwm(int16_t alpha, int16_t beta)
void svpwm(foc_handle_t *handle, int16_t alpha, int16_t beta)
{
int32_t wX, wY, wZ, wUAlpha, wUBeta, wTimePhA, wTimePhB, wTimePhC;
wUAlpha = alpha * (int32_t)pHandle->hT_Sqrt3;
wUBeta = -(beta * (int32_t)(pHandle->PWMperiod)) * 2;
wUAlpha = alpha * (int32_t)handle->hT_Sqrt3;
wUBeta = -(beta * (int32_t)(handle->PWMperiod)) * 2;
wX = wUBeta;
wY = (wUBeta + wUAlpha) / 2;
@ -15,7 +16,7 @@ void svpwm(int16_t alpha, int16_t beta)
{
if (wZ < 0)
{
pHandle->Sector = SECTOR_5;
handle->sector = SECTOR_5;
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + wZ / 131072;
wTimePhC = wTimePhA - wY / 131072;
@ -26,7 +27,7 @@ void svpwm(int16_t alpha, int16_t beta)
else /* wZ >= 0 */
if (wX <= 0)
{
pHandle->Sector = SECTOR_4;
handle->sector = SECTOR_4;
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wX - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + wZ / 131072;
wTimePhC = wTimePhB - wX / 131072;
@ -36,7 +37,7 @@ void svpwm(int16_t alpha, int16_t beta)
}
else /* wX > 0 */
{
pHandle->Sector = SECTOR_3;
handle->sector = SECTOR_3;
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wX) / (int32_t)262144);
wTimePhC = wTimePhA - wY / 131072;
wTimePhB = wTimePhC + wX / 131072;
@ -49,7 +50,7 @@ void svpwm(int16_t alpha, int16_t beta)
{
if (wZ >= 0)
{
pHandle->Sector = SECTOR_2;
handle->sector = SECTOR_2;
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + wZ / 131072;
wTimePhC = wTimePhA - wY / 131072;
@ -60,7 +61,7 @@ void svpwm(int16_t alpha, int16_t beta)
else /* wZ < 0 */
if (wX <= 0)
{
pHandle->Sector = SECTOR_6;
handle->sector = SECTOR_6;
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wX) / (int32_t)262144);
wTimePhC = wTimePhA - wY / 131072;
wTimePhB = wTimePhC + wX / 131072;
@ -70,7 +71,7 @@ void svpwm(int16_t alpha, int16_t beta)
}
else /* wX > 0 */
{
pHandle->Sector = SECTOR_1;
handle->sector = SECTOR_1;
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wX - wZ) / (int32_t)262144);
wTimePhB = wTimePhA + wZ / 131072;
wTimePhC = wTimePhB - wX / 131072;
@ -80,8 +81,7 @@ void svpwm(int16_t alpha, int16_t beta)
}
}
pHandle->CntPhA = (uint16_t)wTimePhA;
pHandle->CntPhB = (uint16_t)wTimePhB;
pHandle->CntPhC = (uint16_t)wTimePhC;
handle->pwmA = (uint16_t)wTimePhA;
handle->pwmA = (uint16_t)wTimePhB;
handle->pwmA = (uint16_t)wTimePhC;
}

View File

@ -16,3 +16,13 @@
#define SECTOR_4 3u
#define SECTOR_5 4u
#define SECTOR_6 5u
typedef struct
{
uint8_t sector; // 扇区
uint16_t pwmA;
uint16_t pwmB;
uint16_t pwmC;
} foc_handle_t;