From bc6c916bff0b8d342c1cd62da73a2a09f18d22a8 Mon Sep 17 00:00:00 2001 From: tao_z <tzj0429@163.com> Date: Thu, 24 Jun 2021 22:22:49 +0800 Subject: [PATCH] 基本模块编译通过 --- USR/SRC/Motor.c | 338 +++++++++++++++++++++++++++++++------------------------- 1 files changed, 186 insertions(+), 152 deletions(-) diff --git a/USR/SRC/Motor.c b/USR/SRC/Motor.c index 841048d..416681b 100644 --- a/USR/SRC/Motor.c +++ b/USR/SRC/Motor.c @@ -1,3 +1,13 @@ +#include "gpio.h" +#include "motor.h" +#include "gd32e23x_exti.h" +#include "gd32e23x_timer.h" +#include "bldc_ctrl.h" +#include "pwm.h" +static volatile motor_rotate_t motor_drive = {0}; +static uint32_t motor_pluse = 0; +static void motor_phasechange(void); +static void update_speed_dir(uint8_t dir_in); /** * @brief ʹ�ܻ��������� * @param �� @@ -6,14 +16,11 @@ void hall_enable(void) { /* ʹ�ܻ����������ӿ� */ - __HAL_TIM_ENABLE_IT(&htimx_hall, TIM_IT_TRIGGER); - __HAL_TIM_ENABLE_IT(&htimx_hall, TIM_IT_UPDATE); - - HAL_TIMEx_HallSensor_Start(&htimx_hall); - - LED1_OFF; - - HAL_TIM_TriggerCallback(&htimx_hall); // ִ��һ�λ��� + exti_interrupt_enable(HALL_A_EXTI); + exti_interrupt_enable(HALL_B_EXTI); + exti_interrupt_enable(HALL_C_EXTI); + StartSpeedTime(); //start speed timer + motor_phasechange(); // ִ��һ�λ��� motor_drive.enable_flag = 1; } @@ -26,9 +33,11 @@ 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); + StopSpeedTime(); //stop speed timer motor_drive.enable_flag = 0; motor_drive.speed = 0; } @@ -36,32 +45,27 @@ uint8_t get_hall_state(void) { uint8_t state = 0; - -#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; } -#else - state = (GPIOH->IDR >> 10) & 7; // �� 3 ��������������״̬ -#endif 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 +73,14 @@ float f = 0; /* �����ٶȣ� - ���ÿתһȦ����12�����壬(1.0/(72000000.0/128.0)Ϊ�����������ڣ�(1.0/(72000000.0/128.0) * time)Ϊʱ�䳤�� + ���ÿתһȦ����12�����壬(1.0/(64000000.0/6400)Ϊ�����������ڣ�(1.0/(48000000.0/6400) * time)Ϊʱ�䳤�� */ if (time == 0) motor_drive.speed_group[count++] = 0; else { - f = (1.0f / (72000000.0f / HALL_PRESCALER_COUNT) * time); + f = (1.0f / (64000000.0f / SPEED_PRESCALER_COUNT) * time); f = (1.0f / 12.0f) / (f / 60.0f); motor_drive.speed_group[count++] = f; } @@ -182,164 +186,194 @@ /** * @brief ���������������ص����� - * @param htim:��ʱ����� + * @param void * @retval �� */ -void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) +void HAL_HallExti_TriggerCallback(void) { /* ��ȡ��������������״̬,��Ϊ��������� */ + 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));//TODO ����ʱ������ü���ʱ�� + motor_drive.timeout = 0; + exti_interrupt_flag_clear(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI); + } + motor_phasechange(); + // HAL_TIM_GenerateEvent(&htimx_bldcm, TIM_EVENTSOURCE_COM); // ������������¼�����ʱ�Ž�����д�� +} + +static void motor_phasechange(void) +{ uint8_t step = 0; step = get_hall_state(); - - if (htim == &htimx_hall) // �ж��Ƿ��ɴ����жϲ��� - { - update_motor_speed(step, __HAL_TIM_GET_COMPARE(htim, TIM_CHANNEL_1)); - motor_drive.timeout = 0; - } - if (get_bldcm_direction() == MOTOR_FWD) { - switch (step) - { - case 1: /* U+ W- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� + step = 7u - step; + } + switch (step) + { + /* next step: step 2 configuration .A-C` breakover---------------------------- */ + case 1: + /* channel U configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_ENABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� + /* channel V configuration */ + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, bldcm_pulse); // ͨ�� 1 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_SET); // �������ű� - break; + /* channel W configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_ENABLE); - case 2: /* V+ U- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� + step++; + break; - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� + /* next step: step 3 configuration .B-C` breakover---------------------------- */ + case 2: + /* channel U configuration */ + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, bldcm_pulse); // ͨ�� 2 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_SET); // �������ű� + /* channel V configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_ENABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); - break; + /* channel W configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_ENABLE); - case 3: /* V+ W- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� + step++; + break; - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� + /* next step: step 4 configuration .B-A` breakover---------------------------- */ + case 3: + /* channel U configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_ENABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, bldcm_pulse); // ͨ�� 2 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_SET); // �������ű� - break; + /* channel V configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_ENABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); - case 4: /* W+ V- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� + /* channel W configuration */ + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� + step++; + break; - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, bldcm_pulse); // ͨ�� 3 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_SET); // �������ű� - break; + /* next step: step 5 configuration .C-A` breakover---------------------------- */ + case 4: + /* channel U configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_ENABLE); - case 5: /* U+ V -*/ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� + /* channel V configuration */ + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� + /* channel W configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_ENABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, bldcm_pulse); // ͨ�� 1 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_SET); // �������ű� - break; + step++; + break; - case 6: /* W+ U- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� + /* next step: step 6 configuration .C-B` breakover---------------------------- */ + case 5: + /* channel U configuration */ + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_DISABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� + /* channel V configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_ENABLE); - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, bldcm_pulse); // ͨ�� 3 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_SET); // �������ű� - break; - } + /* channel W configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_ENABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_DISABLE); + + step++; + break; + + /* next step: step 1 configuration .A-B` breakover---------------------------- */ + case 6: + /* channel U configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_ENABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_DISABLE); + + /* channel V configuration */ + timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_ENABLE); + + /* channel W configuration */ + timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_DISABLE); + + step = 1; + break; + } +} + +/** + * @brief ֹͣpwm��� + * @param �� + * @retval �� + */ +extern void stop_pwm_output(void) +{ + timer_channel_output_state_config(TIMER0, TIMER_CH_0, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_0, TIMER_CCXN_DISABLE); + timer_channel_output_state_config(TIMER0, TIMER_CH_1, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_1, TIMER_CCXN_DISABLE); + timer_channel_output_state_config(TIMER0, TIMER_CH_2, TIMER_CCX_DISABLE); + timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_2, TIMER_CCXN_DISABLE); +} + +/** + * @brief ����pwm�����ռ�ձ� + * @param pulse:Ҫ���õ�ռ�ձ� + * @retval �� + */ +void set_pwm_pulse(uint16_t pulse) +{ + /* ���ö�ʱ��ͨ����� PWM ��ռ�ձ� */ + motor_pluse = pulse; + //SetPwmDuty(); + if (motor_drive.enable_flag) + { + motor_phasechange(); + } +} + +extern void BLDC_SpeedAndPID(void) +{ + if (motor_drive.timeout++ > 100) // ��һ���ڲ��������ж�ǰ����������û�в���ֵ + { + // printf("��ת��ʱ\r\n"); + motor_drive.timeout = 0; + + /* ��ת��ʱֹͣ PWM ��� */ + hall_disable(); // ���û����������ӿ� + stop_pwm_output(); // ֹͣ PWM ��� + set_bldcm_disable(); + motor_drive.speed = 0; } else { - switch (step) - { - case 1: /* W+ U- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, bldcm_pulse); // ͨ�� 3 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_SET); // �������ű� - break; - - case 2: /* U+ V -*/ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, bldcm_pulse); // ͨ�� 1 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_SET); // �������ű� - break; - - case 3: /* W+ V- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, bldcm_pulse); // ͨ�� 3 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_SET); // �������ű� - - break; - - case 4: /* V+ W- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, bldcm_pulse); // ͨ�� 2 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_SET); // �������ű� - break; - - case 5: /* V+ U- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, 0); // ͨ�� 1 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, bldcm_pulse); // ͨ�� 2 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_SET); // �������ű� - break; - - case 6: /* U+ W- */ - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_2, 0); // ͨ�� 2 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM2_GPIO_PORT, MOTOR_OCNPWM2_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_3, 0); // ͨ�� 3 ����Ϊ 0 - HAL_GPIO_WritePin(MOTOR_OCNPWM1_GPIO_PORT, MOTOR_OCNPWM1_PIN, GPIO_PIN_RESET); // �ر����ű� - - __HAL_TIM_SET_COMPARE(&htimx_bldcm, TIM_CHANNEL_1, bldcm_pulse); // ͨ�� 1 ���õ�ռ�ձ� - HAL_GPIO_WritePin(MOTOR_OCNPWM3_GPIO_PORT, MOTOR_OCNPWM3_PIN, GPIO_PIN_SET); // �������ű� - break; - } + bldcm_pid_control(); } - HAL_TIM_GenerateEvent(&htimx_bldcm, TIM_EVENTSOURCE_COM); // ������������¼�����ʱ�Ž�����д�� } \ No newline at end of file -- Gitblit v1.8.0