1 /* 2 * Copyright (c) 2021-2023 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #ifndef HPM_SMC_H 8 #define HPM_SMC_H 9 10 #if defined(__cplusplus) 11 extern "C" { 12 #endif /* __cplusplus */ 13 14 /** 15 * @addtogroup mcl_smc_interface HPMicro MCL SMC APIs 16 * @ingroup middleware_mcl_interfaces 17 * @{ 18 * 19 */ 20 21 /** 22 * @brief smc phase locked loop parameters 23 * 24 */ 25 typedef struct hpm_smc_pll_para { 26 float theta_last; /**< the last angle of the filter */ 27 float err; /**< angle errors */ 28 float speedout; /**< speed resulting from phase locked loop processing */ 29 float theta; /**< electrical angle */ 30 float kp; /**< pid kp */ 31 float ki; /**< pid ki */ 32 float max_i; /**< max integral */ 33 float min_i; /**< min integral */ 34 float max_o; /**< max output */ 35 float min_o; /**< min output */ 36 float mem; /**< integral storage */ 37 float theta0; /**< initial angle */ 38 float loop_in_sec; /**< cycle time in s */ 39 void (*func_getspd)(void *str); 40 } hpm_smc_pll_para_t; 41 42 #define BLDC_CONTROL_SMC_PLL_PARA_DEFAULTS {0, 0, 0, 0,\ 43 0, 0, 0, 0,\ 44 0, 0, 0, 0, 0,\ 45 NULL} 46 47 /** 48 * @brief sliding mode control(SMC) 49 * 50 */ 51 typedef struct hpm_mcl_para { 52 float zero; /**< slip mode convergence */ 53 float ksmc; /**< Slide coefficient */ 54 float filter_coeff; /**< low-pass filter coefficients */ 55 float *ualpha; /**< alpha voltage */ 56 float *ubeta; /**< beta voltage */ 57 float *ialpha; /**< alpha current */ 58 float *ibeta; /**< beta current */ 59 float ialpha_mem; /**< Internal Data */ 60 float ibeta_mem; /**< Internal Data */ 61 float alpha_cal; /**< Internal Data */ 62 float zalpha_cal; /**< Internal Data */ 63 float beta_cal; /**< Internal Data */ 64 float zbeta_cal; /**< Internal Data */ 65 hpm_motor_para_t *i_motorpar; /**< Motor parameters @ref hpm_motor_para_t */ 66 void (*func_smc)(void *str); /**< Slide-mode controller */ 67 } hpm_mcl_para_t; 68 69 #define BLDC_CONTROL_SMC_PARA_DEFAULTS {0, 0, 0, NULL, NULL,\ 70 NULL, NULL, 0, 0, 0,\ 71 0, 0, 0,\ 72 NULL,\ 73 NULL} 74 75 /** 76 * @brief Sliding mode control function 77 * 78 * @param[inout] par @ref hpm_mcl_para_t 79 */ 80 void hpm_mcl_smc_pos_cal(hpm_mcl_para_t *par); 81 82 /** 83 * @brief Calculation of sliding mode control static parameters 84 * 85 * @param[inout] par @ref hpm_motor_para_t 86 */ 87 void hpm_mcl_smc_const_cal(hpm_motor_para_t *par); 88 89 /** 90 * @brief Phase-locked loop filtering of angles after smc processing 91 * 92 * @param[in] par @refhpm_mcl_para_t 93 * @param[inout] pll @ref hpm_smc_pll_para_t 94 * @return angle 95 */ 96 float hpm_mcl_smc_pll(hpm_mcl_para_t *par, hpm_smc_pll_para_t *pll); 97 98 /** 99 * @brief smc current loop 100 * 101 * @param[inout] par @ref BLDC_CONTROL_FOC_PARA 102 * @param[inout] smc @ref hpm_mcl_para_t 103 * @param[inout] pll @ref hpm_smc_pll_para_t 104 * @param[in] is_smc_enable true: smc enable, false: smc disable 105 */ 106 void hpm_mcl_smc_loop(BLDC_CONTROL_FOC_PARA *par, hpm_mcl_para_t *smc, hpm_smc_pll_para_t *pll, uint8_t *is_smc_enable); 107 108 #if defined(__cplusplus) 109 } 110 #endif /* __cplusplus */ 111 112 /** 113 * @} 114 * 115 */ 116 117 #endif 118 119