tao_z
2021-06-24 bc6c916bff0b8d342c1cd62da73a2a09f18d22a8
USR/SRC/bldc_ctrl.c
@@ -1,6 +1,11 @@
#include <math.h>
#include <stdlib.h>
#include "bldc_ctrl.h"
#include "motor.h"
#include "gpio.h"
#include "pwm.h"
#include "bsp_pid.h"
/* Ë½ÓбäÁ¿ */
static bldcm_data_t bldcm_data;
@@ -15,8 +20,8 @@
  */
void bldcm_init(void)
{
    PWM_TIMx_Configuration(); // µç»ú¿ØÖƶ¨Ê±Æ÷£¬Òý½Å³õʼ»¯
    hall_tim_config();        // »ô¶û´«¸ÐÆ÷³õʼ»¯
  // PWM_TIMx_Configuration(); // µç»ú¿ØÖƶ¨Ê±Æ÷£¬Òý½Å³õʼ»¯
  // hall_tim_config();        // »ô¶û´«¸ÐÆ÷³õʼ»¯
    sd_gpio_config();         // sd Òý½Å³õʼ»¯
}
@@ -27,24 +32,7 @@
  */
static void sd_gpio_config(void)
{
    GPIO_InitTypeDef GPIO_InitStruct;
    /* ¶¨Ê±Æ÷ͨµÀ¹¦ÄÜÒý½Å¶Ë¿ÚʱÖÓʹÄÜ */
    SHUTDOWN_GPIO_CLK_ENABLE();
    /* Òý½ÅIO³õʼ»¯ */
    /*ÉèÖÃÊä³öÀàÐÍ*/
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    /*ÉèÖÃÒý½ÅËÙÂÊ */
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    /*Ñ¡ÔñÒª¿ØÖƵÄGPIOÒý½Å*/
    GPIO_InitStruct.Pin = SHUTDOWN_PIN;
    /*µ÷Óÿ⺯Êý£¬Ê¹ÓÃÉÏÃæÅäÖõÄGPIO_InitStructure³õʼ»¯GPIO*/
    HAL_GPIO_Init(SHUTDOWN_GPIO_PORT, &GPIO_InitStruct);
    BLDCM_ENABLE_SD(); // Ä¬ÈÏ¿ªÆô
    HAL_Delay(1);
  Set_SDH2136_Disable();
}
/**
@@ -132,14 +120,14 @@
            bldcm_data.direction = MOTOR_FWD;
        }
        cont_val = (cont_val > PWM_PERIOD_COUNT) ? PWM_PERIOD_COUNT : cont_val; // ÉÏÏÞ´¦Àí
    cont_val = (cont_val > PERIOD_CMP) ? PERIOD_CMP : cont_val; // ÉÏÏÞ´¦Àí
        set_bldcm_speed(cont_val);
#ifdef PID_ASSISTANT_EN
        set_computer_value(SEND_FACT_CMD, CURVES_CH1, &speed_actual, 1); // ¸øÍ¨µÀ 1 ·¢ËÍʵ¼ÊÖµ
#else
        printf("ʵ¼ÊÖµ£º%d, Ä¿±êÖµ£º%.0f£¬¿ØÖÆÖµ: %.0f\n", speed_actual, get_pid_target(), cont_val);
#endif
    // #ifdef PID_ASSISTANT_EN
    //     set_computer_value(SEND_FACT_CMD, CURVES_CH1, &speed_actual, 1); // ¸øÍ¨µÀ 1 ·¢ËÍʵ¼ÊÖµ
    // #else
    //     printf("ʵ¼ÊÖµ£º%d, Ä¿±êÖµ£º%.0f£¬¿ØÖÆÖµ: %.0f\n", speed_actual, get_pid_target(), cont_val);
    // #endif
    }
}