hpm_hfi.h 3.2 KB

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