fix
This commit is contained in:
parent
333c040db5
commit
fa67d84a46
@ -11,6 +11,9 @@
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
hall_handle_t hall_handle;
|
||||||
|
|
||||||
|
|
||||||
/* Function ------------------------------------------------------------------*/
|
/* Function ------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,8 @@ extern "C"
|
|||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
|
||||||
|
#include "hall.h"
|
||||||
|
|
||||||
/* Functions ----------------------------------------------------------------*/
|
/* Functions ----------------------------------------------------------------*/
|
||||||
|
|
||||||
extern void board_init(void);
|
extern void board_init(void);
|
||||||
|
@ -12,13 +12,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
case HALL_STATE_5:
|
case HALL_STATE_5:
|
||||||
if (handle->state == HALL_STATE_4)
|
if (handle->state == HALL_STATE_4)
|
||||||
{
|
{
|
||||||
handle->Direction = POSITIVE;
|
handle->direction = POSITIVE;
|
||||||
handle->MeasuredElAngle = handle->PhaseShift;
|
handle->measure_elec_angle = handle->phase_shift;
|
||||||
}
|
}
|
||||||
else if (handle->state == HALL_STATE_1)
|
else if (handle->state == HALL_STATE_1)
|
||||||
{
|
{
|
||||||
handle->Direction = NEGATIVE;
|
handle->direction = NEGATIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_60_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_60_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -28,13 +28,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
case HALL_STATE_1:
|
case HALL_STATE_1:
|
||||||
if (handle->state == HALL_STATE_5)
|
if (handle->state == HALL_STATE_5)
|
||||||
{
|
{
|
||||||
handle->Direction = POSITIVE;
|
handle->direction = POSITIVE;
|
||||||
handle->MeasuredElAngle = handle->PhaseShift + S16_60_PHASE_SHIFT;
|
handle->measure_elec_angle = handle->phase_shift + S16_60_PHASE_SHIFT;
|
||||||
}
|
}
|
||||||
else if (handle->state == HALL_STATE_3)
|
else if (handle->state == HALL_STATE_3)
|
||||||
{
|
{
|
||||||
handle->Direction = NEGATIVE;
|
handle->direction = NEGATIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -44,14 +44,14 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
case HALL_STATE_3:
|
case HALL_STATE_3:
|
||||||
if (handle->state == HALL_STATE_1)
|
if (handle->state == HALL_STATE_1)
|
||||||
{
|
{
|
||||||
handle->Direction = POSITIVE;
|
handle->direction = POSITIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else if (handle->state == HALL_STATE_2)
|
else if (handle->state == HALL_STATE_2)
|
||||||
{
|
{
|
||||||
handle->Direction = NEGATIVE;
|
handle->direction = NEGATIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT +
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT +
|
||||||
S16_60_PHASE_SHIFT);
|
S16_60_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -62,13 +62,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
case HALL_STATE_2:
|
case HALL_STATE_2:
|
||||||
if (handle->state == HALL_STATE_3)
|
if (handle->state == HALL_STATE_3)
|
||||||
{
|
{
|
||||||
handle->Direction = POSITIVE;
|
handle->direction = POSITIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift + S16_120_PHASE_SHIFT + S16_60_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift + S16_120_PHASE_SHIFT + S16_60_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else if (handle->state == HALL_STATE_6)
|
else if (handle->state == HALL_STATE_6)
|
||||||
{
|
{
|
||||||
handle->Direction = NEGATIVE;
|
handle->direction = NEGATIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_120_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -78,13 +78,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
case HALL_STATE_6:
|
case HALL_STATE_6:
|
||||||
if (handle->state == HALL_STATE_2)
|
if (handle->state == HALL_STATE_2)
|
||||||
{
|
{
|
||||||
handle->Direction = POSITIVE;
|
handle->direction = POSITIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_120_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_120_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else if (handle->state == HALL_STATE_4)
|
else if (handle->state == HALL_STATE_4)
|
||||||
{
|
{
|
||||||
handle->Direction = NEGATIVE;
|
handle->direction = NEGATIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_60_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -94,13 +94,13 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
case HALL_STATE_4:
|
case HALL_STATE_4:
|
||||||
if (handle->state == HALL_STATE_6)
|
if (handle->state == HALL_STATE_6)
|
||||||
{
|
{
|
||||||
handle->Direction = POSITIVE;
|
handle->direction = POSITIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift - S16_60_PHASE_SHIFT);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift - S16_60_PHASE_SHIFT);
|
||||||
}
|
}
|
||||||
else if (handle->state == HALL_STATE_5)
|
else if (handle->state == HALL_STATE_5)
|
||||||
{
|
{
|
||||||
handle->Direction = NEGATIVE;
|
handle->direction = NEGATIVE;
|
||||||
handle->MeasuredElAngle = (int16_t)(handle->PhaseShift);
|
handle->measure_elec_angle = (int16_t)(handle->phase_shift);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -109,7 +109,7 @@ void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
/* Bad hall sensor configutarion so update the speed reliability */
|
/* Bad hall sensor configutarion so update the speed reliability */
|
||||||
handle->SensorIsReliable = 0;
|
// handle->SensorIsReliable = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,6 @@ enum
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
// |||
|
|
||||||
// |||
|
|
||||||
// |||
|
|
||||||
uint8_t state; // 霍尔状态真值表
|
uint8_t state; // 霍尔状态真值表
|
||||||
|
|
||||||
int16_t phase_shift; // 同步电角度
|
int16_t phase_shift; // 同步电角度
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include "svpwm.h"
|
#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;
|
int32_t wX, wY, wZ, wUAlpha, wUBeta, wTimePhA, wTimePhB, wTimePhC;
|
||||||
|
|
||||||
wUAlpha = alpha * (int32_t)pHandle->hT_Sqrt3;
|
wUAlpha = alpha * (int32_t)handle->hT_Sqrt3;
|
||||||
wUBeta = -(beta * (int32_t)(pHandle->PWMperiod)) * 2;
|
wUBeta = -(beta * (int32_t)(handle->PWMperiod)) * 2;
|
||||||
|
|
||||||
wX = wUBeta;
|
wX = wUBeta;
|
||||||
wY = (wUBeta + wUAlpha) / 2;
|
wY = (wUBeta + wUAlpha) / 2;
|
||||||
@ -15,7 +16,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
{
|
{
|
||||||
if (wZ < 0)
|
if (wZ < 0)
|
||||||
{
|
{
|
||||||
pHandle->Sector = SECTOR_5;
|
handle->sector = SECTOR_5;
|
||||||
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wZ) / (int32_t)262144);
|
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wZ) / (int32_t)262144);
|
||||||
wTimePhB = wTimePhA + wZ / 131072;
|
wTimePhB = wTimePhA + wZ / 131072;
|
||||||
wTimePhC = wTimePhA - wY / 131072;
|
wTimePhC = wTimePhA - wY / 131072;
|
||||||
@ -26,7 +27,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
else /* wZ >= 0 */
|
else /* wZ >= 0 */
|
||||||
if (wX <= 0)
|
if (wX <= 0)
|
||||||
{
|
{
|
||||||
pHandle->Sector = SECTOR_4;
|
handle->sector = SECTOR_4;
|
||||||
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wX - wZ) / (int32_t)262144);
|
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wX - wZ) / (int32_t)262144);
|
||||||
wTimePhB = wTimePhA + wZ / 131072;
|
wTimePhB = wTimePhA + wZ / 131072;
|
||||||
wTimePhC = wTimePhB - wX / 131072;
|
wTimePhC = wTimePhB - wX / 131072;
|
||||||
@ -36,7 +37,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
}
|
}
|
||||||
else /* wX > 0 */
|
else /* wX > 0 */
|
||||||
{
|
{
|
||||||
pHandle->Sector = SECTOR_3;
|
handle->sector = SECTOR_3;
|
||||||
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wX) / (int32_t)262144);
|
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wX) / (int32_t)262144);
|
||||||
wTimePhC = wTimePhA - wY / 131072;
|
wTimePhC = wTimePhA - wY / 131072;
|
||||||
wTimePhB = wTimePhC + wX / 131072;
|
wTimePhB = wTimePhC + wX / 131072;
|
||||||
@ -49,7 +50,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
{
|
{
|
||||||
if (wZ >= 0)
|
if (wZ >= 0)
|
||||||
{
|
{
|
||||||
pHandle->Sector = SECTOR_2;
|
handle->sector = SECTOR_2;
|
||||||
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wZ) / (int32_t)262144);
|
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wZ) / (int32_t)262144);
|
||||||
wTimePhB = wTimePhA + wZ / 131072;
|
wTimePhB = wTimePhA + wZ / 131072;
|
||||||
wTimePhC = wTimePhA - wY / 131072;
|
wTimePhC = wTimePhA - wY / 131072;
|
||||||
@ -60,7 +61,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
else /* wZ < 0 */
|
else /* wZ < 0 */
|
||||||
if (wX <= 0)
|
if (wX <= 0)
|
||||||
{
|
{
|
||||||
pHandle->Sector = SECTOR_6;
|
handle->sector = SECTOR_6;
|
||||||
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wX) / (int32_t)262144);
|
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wY - wX) / (int32_t)262144);
|
||||||
wTimePhC = wTimePhA - wY / 131072;
|
wTimePhC = wTimePhA - wY / 131072;
|
||||||
wTimePhB = wTimePhC + wX / 131072;
|
wTimePhB = wTimePhC + wX / 131072;
|
||||||
@ -70,7 +71,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
}
|
}
|
||||||
else /* wX > 0 */
|
else /* wX > 0 */
|
||||||
{
|
{
|
||||||
pHandle->Sector = SECTOR_1;
|
handle->sector = SECTOR_1;
|
||||||
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wX - wZ) / (int32_t)262144);
|
wTimePhA = (int32_t)(pHandle->PWMperiod) / 4 + ((wX - wZ) / (int32_t)262144);
|
||||||
wTimePhB = wTimePhA + wZ / 131072;
|
wTimePhB = wTimePhA + wZ / 131072;
|
||||||
wTimePhC = wTimePhB - wX / 131072;
|
wTimePhC = wTimePhB - wX / 131072;
|
||||||
@ -80,8 +81,7 @@ void svpwm(int16_t alpha, int16_t beta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pHandle->CntPhA = (uint16_t)wTimePhA;
|
handle->pwmA = (uint16_t)wTimePhA;
|
||||||
pHandle->CntPhB = (uint16_t)wTimePhB;
|
handle->pwmA = (uint16_t)wTimePhB;
|
||||||
pHandle->CntPhC = (uint16_t)wTimePhC;
|
handle->pwmA = (uint16_t)wTimePhC;
|
||||||
|
|
||||||
}
|
}
|
@ -16,3 +16,13 @@
|
|||||||
#define SECTOR_4 3u
|
#define SECTOR_4 3u
|
||||||
#define SECTOR_5 4u
|
#define SECTOR_5 4u
|
||||||
#define SECTOR_6 5u
|
#define SECTOR_6 5u
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t sector; // 扇区
|
||||||
|
|
||||||
|
uint16_t pwmA;
|
||||||
|
uint16_t pwmB;
|
||||||
|
uint16_t pwmC;
|
||||||
|
|
||||||
|
} foc_handle_t;
|
Loading…
Reference in New Issue
Block a user