1 /* 2 * Copyright (c) 2021-2022 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #ifndef HPM_BLOCK_H 8 #define HPM_BLOCK_H 9 10 #if defined(__cplusplus) 11 extern "C" { 12 #endif /* __cplusplus */ 13 14 /** 15 * @addtogroup mcl_block_interface HPMicro MCL BLOCK APIs 16 * @ingroup middleware_mcl_interfaces 17 * @{ 18 * 19 */ 20 21 /** 22 * @brief Output pwm according to the number of motor steps 23 * 24 * @param[in] motorindex number of motor @ref BLDC_MOTOR0_INDEX ... BLDC_MOTOR3_INDEX 25 * @param[in] dir Motor operation direction @ref BLDC_MOTOR_DIR_FORWARD or @ref BLDC_MOTOR_DIR_REVERSE 26 * @param[in] step Motor steps, 60 degrees per step 27 */ 28 void hpm_mcl_bldc_block_ctrl(uint8_t motorindex, uint8_t dir, uint8_t step); 29 30 /** 31 * @brief Get step count based on Hall sensor status 32 * 33 * @param[in] phase Hall Displacement @ref bldc_hall_phase_t 34 * @param[in] hall_u u-phase Hall level state, 0-low 1-high 35 * @param[in] hall_v v-phase Hall level state, 0-low 1-high 36 * @param[in] hall_w w-phase Hall level state, 0-low 1-high 37 * @return uint8_t step 38 */ 39 uint8_t hpm_mcl_bldc_block_step_get(bldc_hall_phase_t phase, uint8_t hall_u, uint8_t hall_v, uint8_t hall_w); 40 41 /** 42 * @brief pi loop function 43 * 44 * @param[in] memory Store points data 45 * @param[in] targetspeed Target speed 46 * @param[in] speed Real speed 47 * @param[in] kp Scale factor 48 * @param[in] ki Integral factor 49 * @param[in] max Output maximum and integration maximum 50 * @return float Data after pi adjustment 51 */ 52 float hpm_mcl_al_pi_ctrl_func(float *memory, float targetspeed, float speed, float kp, float ki, float max); 53 54 /** 55 * @brief Enables the pwm output of the given pin 56 * 57 * @param[in] motor_index number of motor @ref BLDC_MOTOR0_INDEX ... BLDC_MOTOR3_INDEX 58 * @param[in] pin_name pin names @ref BLDC_PWM_PIN_UH ... BLDC_PWM_PIN_WL 59 */ 60 void hpm_mcl_bldc_pwm_enable(uint8_t motor_index, uint8_t pin_name); 61 62 /** 63 * @brief Disable the pwm output of the given pin 64 * 65 * @param[in] motor_index number of motor @ref BLDC_MOTOR0_INDEX ... BLDC_MOTOR3_INDEX 66 * @param[in] pin_name pin names @ref BLDC_PWM_PIN_UH ... BLDC_PWM_PIN_WL 67 */ 68 void hpm_mcl_bldc_pwm_disable(uint8_t motor_index, uint8_t pin_name); 69 70 /** 71 * @} 72 * 73 */ 74 75 #if defined(__cplusplus) 76 } 77 #endif /* __cplusplus */ 78 79 #endif 80