From b150690b6ebe42a4ffd50278d761b8994121eb94 Mon Sep 17 00:00:00 2001 From: tao_z <tzj0429@163.com> Date: Mon, 14 Jun 2021 22:18:45 +0800 Subject: [PATCH] 添加霍尔外部中断 motot模块初次提交尚未调试 --- USR/SRC/Motor.c | 43 +++++++++++++++++++++++++------------------ 1 files changed, 25 insertions(+), 18 deletions(-) diff --git a/USR/SRC/Motor.c b/USR/SRC/Motor.c index 841048d..64b2163 100644 --- a/USR/SRC/Motor.c +++ b/USR/SRC/Motor.c @@ -1,3 +1,7 @@ +#include "gpio.h" +#include "motor.h" +#include "gd32e23x_exti.h" +static motor_rotate_t motor_drive = {0}; /** * @brief ʹ�ܻ��������� * @param �� @@ -6,14 +10,15 @@ void hall_enable(void) { /* ʹ�ܻ����������ӿ� */ - __HAL_TIM_ENABLE_IT(&htimx_hall, TIM_IT_TRIGGER); - __HAL_TIM_ENABLE_IT(&htimx_hall, TIM_IT_UPDATE); + exti_interrupt_enable(HALL_A_EXTI); + exti_interrupt_enable(HALL_B_EXTI); + exti_interrupt_enable(HALL_C_EXTI); - HAL_TIMEx_HallSensor_Start(&htimx_hall); + // HAL_TIMEx_HallSensor_Start(&htimx_hall); - LED1_OFF; + // LED1_OFF; - HAL_TIM_TriggerCallback(&htimx_hall); // ִ��һ�λ��� + // HAL_TIM_TriggerCallback(&htimx_hall); // ִ��һ�λ��� motor_drive.enable_flag = 1; } @@ -26,9 +31,10 @@ void hall_disable(void) { /* ���û����������ӿ� */ - __HAL_TIM_DISABLE_IT(&htimx_hall, TIM_IT_TRIGGER); - __HAL_TIM_DISABLE_IT(&htimx_hall, TIM_IT_UPDATE); - HAL_TIMEx_HallSensor_Stop(&htimx_hall); + exti_interrupt_disable(HALL_A_EXTI); + exti_interrupt_disable(HALL_B_EXTI); + exti_interrupt_disable(HALL_C_EXTI); + // HAL_TIMEx_HallSensor_Stop(&htimx_hall); motor_drive.enable_flag = 0; motor_drive.speed = 0; } @@ -39,19 +45,19 @@ #if 1 /* ��ȡ���������� U ��״̬ */ - if (HAL_GPIO_ReadPin(HALL_INPUTU_GPIO_PORT, HALL_INPUTU_PIN) != GPIO_PIN_RESET) + if (Get_HallSensorA_State()) { state |= 0x01U << 0; } /* ��ȡ���������� V ��״̬ */ - if (HAL_GPIO_ReadPin(HALL_INPUTV_GPIO_PORT, HALL_INPUTV_PIN) != GPIO_PIN_RESET) + if (Get_HallSensorB_State()) { state |= 0x01U << 1; } /* ��ȡ���������� W ��״̬ */ - if (HAL_GPIO_ReadPin(HALL_INPUTW_GPIO_PORT, HALL_INPUTW_PIN) != GPIO_PIN_RESET) + if (Get_HallSensorC_State()) { state |= 0x01U << 2; } @@ -61,7 +67,7 @@ return state; // ���ش�����״̬ } - +static uint8_t count = 0; static void update_motor_speed(uint8_t dir_in, uint32_t time) { int speed_temp = 0; @@ -69,14 +75,14 @@ float f = 0; /* �����ٶȣ� - ���ÿתһȦ����12�����壬(1.0/(72000000.0/128.0)Ϊ�����������ڣ�(1.0/(72000000.0/128.0) * time)Ϊʱ�䳤�� + ���ÿתһȦ����12�����壬(1.0/(48000000.0/128.0)Ϊ�����������ڣ�(1.0/(48000000.0/128.0) * time)Ϊʱ�䳤�� */ if (time == 0) motor_drive.speed_group[count++] = 0; else { - f = (1.0f / (72000000.0f / HALL_PRESCALER_COUNT) * time); + f = (1.0f / (48000000.0f / HALL_PRESCALER_COUNT) * time); f = (1.0f / 12.0f) / (f / 60.0f); motor_drive.speed_group[count++] = f; } @@ -182,19 +188,20 @@ /** * @brief ���������������ص����� - * @param htim:��ʱ����� + * @param void * @retval �� */ -void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) +void HAL_HallExti_TriggerCallback(void) { /* ��ȡ��������������״̬,��Ϊ��������� */ uint8_t step = 0; step = get_hall_state(); - if (htim == &htimx_hall) // �ж��Ƿ��ɴ����жϲ��� + if (exti_interrupt_flag_get(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI)) // �ж��Ƿ��ɴ����жϲ��� { - update_motor_speed(step, __HAL_TIM_GET_COMPARE(htim, TIM_CHANNEL_1)); + // update_motor_speed(step, __HAL_TIM_GET_COMPARE(htim, TIM_CHANNEL_1));//TODO ����ʱ������ü���ʱ�� motor_drive.timeout = 0; + exti_interrupt_flag_clear(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI); } if (get_bldcm_direction() == MOTOR_FWD) -- Gitblit v1.8.0