| | |
| | | |
| | | #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; |
| | |
| | | */ |
| | | void bldcm_init(void) |
| | | { |
| | | PWM_TIMx_Configuration(); // µç»ú¿ØÖƶ¨Ê±Æ÷£¬Òý½Å³õʼ»¯ |
| | | hall_tim_config(); // »ô¶û´«¸ÐÆ÷³õʼ»¯ |
| | | // PWM_TIMx_Configuration(); // µç»ú¿ØÖƶ¨Ê±Æ÷£¬Òý½Å³õʼ»¯ |
| | | // hall_tim_config(); // »ô¶û´«¸ÐÆ÷³õʼ»¯ |
| | | sd_gpio_config(); // sd Òý½Å³õʼ»¯ |
| | | } |
| | | |
| | |
| | | */ |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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 |
| | | } |
| | | } |