1 /* 2 * Copyright (c) 2023 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef HPM_SQUARE_WAVE_INJECT_H 9 #define HPM_SQUARE_WAVE_INJECT_H 10 11 #include "hpm_common.h" 12 #include "hpm_bldc_define.h" 13 #include "hpm_foc.h" 14 #include "hpm_smc.h" 15 16 /** 17 * @addtogroup mcl_smc_interface HPMicro MCL HFI APIs 18 * @ingroup middleware_hfi_interfaces 19 * @{ 20 * 21 */ 22 23 #if defined(__cplusplus) 24 extern "C" { 25 #endif /* __cplusplus */ 26 27 #ifndef PI 28 #define PI (3.1415926) 29 #endif 30 31 /** 32 * @brief HFI parameters and calculation data 33 * 34 */ 35 typedef struct hpm_hfi_para { 36 float vh; /**< Injection Voltage */ 37 float last_alpha; 38 float last_beta; 39 float e_alpha; 40 float e_beta; 41 float e_theta; 42 float alpha; 43 float beta; 44 bool period; /**< loop tick */ 45 void (*func)(void *str); 46 } hpm_hfi_para_t; 47 48 #define BLDC_CONTROL_INJECT_PARA_DEFAULTS {\ 49 0, 0, 0,\ 50 0, 0, 0, 0, 0, 0,\ 51 NULL\ 52 } 53 54 /** 55 * @brief HFI of magnetic pole identification parameters 56 * 57 */ 58 typedef struct hpm_hfi_pole_detect_para { 59 int16_t currentd_force; 60 uint8_t status; 61 uint16_t times; 62 uint16_t current_d_init_val; /**< Voltage injected during identification */ 63 int32_t theta_pi; /**< Voltage at 180 degrees */ 64 int32_t theta_zero; /**< Voltage at 0 degrees */ 65 bool (*func)(void *foc, void *inject, 66 void *pll, void *pole); 67 } hpm_hfi_pole_detect_para_t; 68 69 #define BLDC_CONTROL_INJECT_POLE_DETECT_PARA_DEFAULTS {\ 70 0, 0, 0, 0, 0, 0,\ 71 NULL\ 72 } 73 74 /** 75 * @brief HFI pll Filter Parameters 76 * 77 */ 78 typedef struct hpm_hfi_pll_para { 79 float theta_last; 80 float err_last; 81 float low_pass; 82 float filter; 83 float deta; 84 float theta; 85 float kp; 86 float ki; 87 float mem_max; 88 float mem_min; 89 float mem; 90 float loop_s; 91 float err; 92 void (*func)(void *str); 93 } hpm_hfi_pll_para_t; 94 95 #define BLDC_CONTROL_INJECT_PLL_PARA_DEFAULTS {\ 96 0, 0, 0, 0, 0,\ 97 0, 0, 0, 0, 0, 0, 0, 0,\ 98 NULL\ 99 } 100 101 /** 102 * @brief HFI current loop 103 * 104 * @param par @ref BLDC_CONTROL_FOC_PARA 105 * @param inject @ref hpm_hfi_para_t 106 * @param pll @ref hpm_hfi_pll_para_t 107 * @param pole @ref hpm_hfi_pole_detect_para_t 108 */ 109 void hpm_mcl_hfi_loop(BLDC_CONTROL_FOC_PARA *par, hpm_hfi_para_t *inject, 110 hpm_hfi_pll_para_t *pll, hpm_hfi_pole_detect_para_t *pole); 111 112 /** 113 * @brief HFI Magnetic Pole Detection 114 * 115 * @param foc @ref BLDC_CONTROL_FOC_PARA 116 * @param inject @ref hpm_hfi_para_t 117 * @param pll @ref hpm_hfi_pll_para_t 118 * @param pole @ref hpm_hfi_pole_detect_para_t 119 * @retval true Complete pole identification 120 * false pole detection failure 121 */ 122 bool hpm_mcl_hfi_pole_detect(BLDC_CONTROL_FOC_PARA *foc, hpm_hfi_para_t *inject, 123 hpm_hfi_pll_para_t *pll, hpm_hfi_pole_detect_para_t *pole); 124 #if defined(__cplusplus) 125 } 126 #endif /* __cplusplus */ 127 128 /** 129 * @} 130 * 131 */ 132 133 #endif 134