This commit is contained in:
MQjehovah 2023-09-01 14:09:24 +08:00
parent 2676f1efe1
commit 254fc8bc5a
9 changed files with 43 additions and 14 deletions

View File

@ -14,6 +14,7 @@
hall_handle_t hall_handle;
foc_handle_t foc_handle;
const char *data = "hello world";
/* Function ------------------------------------------------------------------*/
/**
@ -25,6 +26,7 @@ int main(void)
board_init();
foc_handle.pwm_period = 168 * 1000000 / 16000;
// while (1)
// {
// int segment = 60;
@ -55,6 +57,7 @@ int main(void)
// // svmpw()
while (1)
{
HAL_UART_Transmit(&huart1, data, 1, 0xFFFF);
// hall_handle.control_elec_angle++;
// foc_handle.Valphabeta = math_rev_park(foc_handle.Vqd, hall_handle.control_elec_angle);
// svmpw(foc_handle);

View File

@ -22,6 +22,9 @@ extern "C"
/* Functions ----------------------------------------------------------------*/
extern hall_handle_t hall_handle;
extern foc_handle_t foc_handle;
#ifdef __cplusplus
}
#endif

View File

@ -138,12 +138,12 @@ void board_init(void)
HAL_Init();
SystemClock_Config();
SystemCoreClockUpdate();
// SystemCoreClockUpdate();
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_TIM1_Init();
// MX_TIM3_Init();
MX_TIM3_Init();
MX_NVIC_Init();
FOC_Init();

View File

@ -17,13 +17,14 @@ extern "C"
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f407xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_ll_gpio.h"
#include "stm32f4xx_ll_tim.h"
#include "stm32f4xx_hal.h"
#include "usart.h"
#include "gpio.h"
#include "usart.h"
#include "timer.h"
#include "foc.h"

View File

@ -11,7 +11,7 @@
/* Includes ------------------------------------------------------------------*/
#include "timer.h"
#include "board.h"
#include "stm32f4xx_ll_tim.h"
#include "main.h"
TIM_HandleTypeDef htim1;
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_MspDeInit(TIM_HandleTypeDef *htim_base);
/**
* @brief TIM1 Initialization Function
* @param None
@ -118,6 +117,10 @@ void MX_TIM3_Init(void)
TIM_HallSensor_InitTypeDef sConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/**
* 48M
*
*/
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
@ -342,6 +345,16 @@ void TIM3_IRQHandler(void)
if (LL_TIM_IsActiveFlag_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);
}
}

View File

@ -52,8 +52,8 @@ void MX_USART1_UART_Init(void)
void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if (uartHandle->Instance == USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */
@ -62,17 +62,17 @@ void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
/* USART1 clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
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.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);

View File

@ -18,7 +18,7 @@ extern "C"
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f4xx_hal.h"
extern UART_HandleTypeDef huart1;

View File

@ -7,6 +7,8 @@
*/
void calc_hall_angle(hall_handle_t *handle, uint8_t new_state)
{
switch (new_state)
{
case HALL_STATE_5:

View File

@ -25,6 +25,9 @@
#define S16_120_PHASE_SHIFT (int16_t)(65536 / 3)
#define S16_60_PHASE_SHIFT (int16_t)(65536 / 6)
#define HALL_TYPE_DEGREES_120 0u
#define HALL_TYPE_DEGREES_60 1u
enum
{
NEGATIVE = -1,
@ -36,6 +39,8 @@ typedef struct
{
uint8_t state; // 霍尔状态真值表
uint8_t placement_type; // 霍尔排列方式
int16_t phase_shift; // 同步电角度
int8_t direction; // 转子方向
@ -44,4 +49,6 @@ typedef struct
} hall_handle_t;
extern void calc_hall_angle(hall_handle_t *handle, uint8_t new_state);
#endif /* __FOC_HALL_H__ */