fix
This commit is contained in:
parent
2676f1efe1
commit
254fc8bc5a
@ -14,6 +14,7 @@
|
|||||||
hall_handle_t hall_handle;
|
hall_handle_t hall_handle;
|
||||||
foc_handle_t foc_handle;
|
foc_handle_t foc_handle;
|
||||||
|
|
||||||
|
const char *data = "hello world";
|
||||||
/* Function ------------------------------------------------------------------*/
|
/* Function ------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +26,7 @@ int main(void)
|
|||||||
board_init();
|
board_init();
|
||||||
|
|
||||||
foc_handle.pwm_period = 168 * 1000000 / 16000;
|
foc_handle.pwm_period = 168 * 1000000 / 16000;
|
||||||
|
|
||||||
// while (1)
|
// while (1)
|
||||||
// {
|
// {
|
||||||
// int segment = 60;
|
// int segment = 60;
|
||||||
@ -55,6 +57,7 @@ int main(void)
|
|||||||
// // svmpw()
|
// // svmpw()
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
HAL_UART_Transmit(&huart1, data, 1, 0xFFFF);
|
||||||
// hall_handle.control_elec_angle++;
|
// hall_handle.control_elec_angle++;
|
||||||
// foc_handle.Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle);
|
// foc_handle.Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle);
|
||||||
// svmpw(foc_handle);
|
// svmpw(foc_handle);
|
||||||
|
@ -22,6 +22,9 @@ extern "C"
|
|||||||
|
|
||||||
/* Functions ----------------------------------------------------------------*/
|
/* Functions ----------------------------------------------------------------*/
|
||||||
|
|
||||||
|
extern hall_handle_t hall_handle;
|
||||||
|
extern foc_handle_t foc_handle;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -138,12 +138,12 @@ void board_init(void)
|
|||||||
|
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
SystemCoreClockUpdate();
|
// SystemCoreClockUpdate();
|
||||||
|
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_USART1_UART_Init();
|
MX_USART1_UART_Init();
|
||||||
MX_TIM1_Init();
|
MX_TIM1_Init();
|
||||||
// MX_TIM3_Init();
|
MX_TIM3_Init();
|
||||||
MX_NVIC_Init();
|
MX_NVIC_Init();
|
||||||
|
|
||||||
FOC_Init();
|
FOC_Init();
|
||||||
|
@ -17,13 +17,14 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "stm32f407xx.h"
|
||||||
|
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_ll_gpio.h"
|
||||||
#include "stm32f4xx_ll_tim.h"
|
#include "stm32f4xx_ll_tim.h"
|
||||||
|
#include "stm32f4xx_hal.h"
|
||||||
|
|
||||||
|
|
||||||
#include "usart.h"
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
#include "usart.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
#include "foc.h"
|
#include "foc.h"
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "stm32f4xx_ll_tim.h"
|
#include "main.h"
|
||||||
|
|
||||||
TIM_HandleTypeDef htim1;
|
TIM_HandleTypeDef htim1;
|
||||||
TIM_HandleTypeDef htim3;
|
TIM_HandleTypeDef htim3;
|
||||||
@ -20,7 +20,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
|||||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base);
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base);
|
||||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim_base);
|
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim_base);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TIM1 Initialization Function
|
* @brief TIM1 Initialization Function
|
||||||
* @param None
|
* @param None
|
||||||
@ -118,6 +117,10 @@ void MX_TIM3_Init(void)
|
|||||||
TIM_HallSensor_InitTypeDef sConfig = {0};
|
TIM_HallSensor_InitTypeDef sConfig = {0};
|
||||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时器主频48M
|
||||||
|
*
|
||||||
|
*/
|
||||||
htim3.Instance = TIM3;
|
htim3.Instance = TIM3;
|
||||||
htim3.Init.Prescaler = 0;
|
htim3.Init.Prescaler = 0;
|
||||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
@ -342,6 +345,16 @@ void TIM3_IRQHandler(void)
|
|||||||
if (LL_TIM_IsActiveFlag_CC1(TIM3))
|
if (LL_TIM_IsActiveFlag_CC1(TIM3))
|
||||||
{
|
{
|
||||||
LL_TIM_ClearFlag_CC1(TIM3);
|
LL_TIM_ClearFlag_CC1(TIM3);
|
||||||
// HALL_TIMx_CC_IRQHandler(&HALL_M1);
|
uint8_t new_state = 0;
|
||||||
|
if (hall_handle.placement_type == HALL_TYPE_DEGREES_120)
|
||||||
|
{
|
||||||
|
new_state = (uint8_t)((LL_GPIO_IsInputPinSet(GPIOC, GPIO_PIN_6) << 2) | (LL_GPIO_IsInputPinSet(GPIOC, GPIO_PIN_7) << 1) | LL_GPIO_IsInputPinSet(GPIOC, GPIO_PIN_8));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new_state = (uint8_t)(((LL_GPIO_IsInputPinSet(GPIOC, GPIO_PIN_7) ^ 1) << 2) | (LL_GPIO_IsInputPinSet(GPIOC, GPIO_PIN_8) << 1) | LL_GPIO_IsInputPinSet(GPIOC, GPIO_PIN_6));
|
||||||
|
}
|
||||||
|
|
||||||
|
calc_hall_angle(&hall_handle, new_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ void MX_USART1_UART_Init(void)
|
|||||||
|
|
||||||
void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
|
void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
|
||||||
if (uartHandle->Instance == USART1)
|
if (uartHandle->Instance == USART1)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN USART1_MspInit 0 */
|
/* USER CODE BEGIN USART1_MspInit 0 */
|
||||||
@ -62,17 +62,17 @@ void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
|
|||||||
/* USART1 clock enable */
|
/* USART1 clock enable */
|
||||||
__HAL_RCC_USART1_CLK_ENABLE();
|
__HAL_RCC_USART1_CLK_ENABLE();
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
/**USART1 GPIO Configuration
|
/**USART1 GPIO Configuration
|
||||||
PA9 ------> USART1_TX
|
PA9 ------> USART1_TX
|
||||||
PA10 ------> USART1_RX
|
PA10 ------> USART1_RX
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
|
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USART1 interrupt Init */
|
/* USART1 interrupt Init */
|
||||||
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
|
||||||
|
@ -18,7 +18,7 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "stm32f4xx_hal.h"
|
||||||
|
|
||||||
extern UART_HandleTypeDef huart1;
|
extern UART_HandleTypeDef huart1;
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
switch (new_state)
|
switch (new_state)
|
||||||
{
|
{
|
||||||
case HALL_STATE_5:
|
case HALL_STATE_5:
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
#define S16_120_PHASE_SHIFT (int16_t)(65536 / 3)
|
#define S16_120_PHASE_SHIFT (int16_t)(65536 / 3)
|
||||||
#define S16_60_PHASE_SHIFT (int16_t)(65536 / 6)
|
#define S16_60_PHASE_SHIFT (int16_t)(65536 / 6)
|
||||||
|
|
||||||
|
#define HALL_TYPE_DEGREES_120 0u
|
||||||
|
#define HALL_TYPE_DEGREES_60 1u
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
NEGATIVE = -1,
|
NEGATIVE = -1,
|
||||||
@ -36,6 +39,8 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint8_t state; // 霍尔状态真值表
|
uint8_t state; // 霍尔状态真值表
|
||||||
|
|
||||||
|
uint8_t placement_type; // 霍尔排列方式
|
||||||
|
|
||||||
int16_t phase_shift; // 同步电角度
|
int16_t phase_shift; // 同步电角度
|
||||||
|
|
||||||
int8_t direction; // 转子方向
|
int8_t direction; // 转子方向
|
||||||
@ -44,4 +49,6 @@ typedef struct
|
|||||||
|
|
||||||
} hall_handle_t;
|
} hall_handle_t;
|
||||||
|
|
||||||
|
extern void calc_hall_angle(hall_handle_t *handle, uint8_t new_state);
|
||||||
|
|
||||||
#endif /* __FOC_HALL_H__ */
|
#endif /* __FOC_HALL_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user