tao_z
2021-06-27 b34d5dbff89fd992af8196c747e18a8933d0c729
USR/SRC/Motor.c
@@ -1,7 +1,22 @@
#include "gpio.h"
#include "motor.h"
#include "gd32e23x_exti.h"
static motor_rotate_t motor_drive = {0};
#include "gd32e23x_timer.h"
#include "bldc_ctrl.h"
#include "pwm.h"
#include "string.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);
extern void Motor_Init(void)
{
    motor_drive.timeout = 0;
    motor_drive.speed = 0;
    motor_drive.enable_flag = 0;
    memset(motor_drive.speed_group, 0, SPEED_FILTER_NUM);
};
/**
  * @brief  Ê¹ÄÜ»ô¶û´«¸ÐÆ÷
  * @param  ÎÞ
@@ -13,12 +28,8 @@
    exti_interrupt_enable(HALL_A_EXTI);
    exti_interrupt_enable(HALL_B_EXTI);
    exti_interrupt_enable(HALL_C_EXTI);
    // HAL_TIMEx_HallSensor_Start(&htimx_hall);
    // LED1_OFF;
    // HAL_TIM_TriggerCallback(&htimx_hall); // Ö´ÐÐÒ»´Î»»Ïà
    StartSpeedTime();    //start speed timer
    motor_phasechange(); // Ö´ÐÐÒ»´Î»»Ïà
    motor_drive.enable_flag = 1;
}
@@ -35,6 +46,7 @@
    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;
}
@@ -42,8 +54,6 @@
uint8_t get_hall_state(void)
{
    uint8_t state = 0;
#if 1
    /* ¶ÁÈ¡»ô¶û´«¸ÐÆ÷ U µÄ״̬ */
    if (Get_HallSensorA_State())
    {
@@ -61,9 +71,6 @@
    {
        state |= 0x01U << 2;
    }
#else
    state = (GPIOH->IDR >> 10) & 7; // ¶Á 3 ¸ö»ô¶û´«¸ÐÆ÷µÄ״̬
#endif
    return state; // ·µ»Ø´«¸ÐÆ÷״̬
}
@@ -75,14 +82,14 @@
    float f = 0;
    /* ¼ÆËãËÙ¶È£º
     µç»úÿתһȦ¹²ÓÃ12¸öÂö³å£¬(1.0/(48000000.0/128.0)Ϊ¼ÆÊýÆ÷µÄÖÜÆÚ£¬(1.0/(48000000.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 / (48000000.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;
    }
@@ -194,159 +201,188 @@
void HAL_HallExti_TriggerCallback(void)
{
    /* »ñÈ¡»ô¶û´«¸ÐÆ÷Òý½Å״̬,×÷Ϊ»»ÏàµÄÒÀ¾Ý */
    uint8_t step = 0;
    step = get_hall_state();
    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 (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); // Èí¼þ²úÉú»»Ïàʼþ£¬´Ëʱ²Å½«ÅäÖÃдÈë
}