hpm_foc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2021-2022 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_FOC_H
  8. #define HPM_FOC_H
  9. #if defined(__cplusplus)
  10. extern "C" {
  11. #endif /* __cplusplus */
  12. #include "hpm_motor_math.h"
  13. /**
  14. * @addtogroup mcl_foc_interface HPMicro MCL FOC APIs
  15. * @ingroup middleware_mcl_interfaces
  16. * @{
  17. *
  18. */
  19. /**
  20. * @brief Calculation of speed by angular difference of sampling.
  21. *
  22. * @param[inout] par Speed parameters @ref BLDC_CONTRL_SPD_PARA
  23. */
  24. void hpm_mcl_bldc_foc_al_speed(BLDC_CONTRL_SPD_PARA *par);
  25. /**
  26. * @brief Update output pwm according to duty cycle, provided by the user
  27. *
  28. * @param[inout] par @ref BLDC_CONTROL_PWMOUT_PARA
  29. */
  30. void hpm_mcl_bldc_foc_pwmset(BLDC_CONTROL_PWMOUT_PARA *par);
  31. /**
  32. * @brief Reconfiguring three-phase currents
  33. *
  34. * @param[inout] par @ref BLDC_CONTROL_CURRENT_PARA
  35. */
  36. void hpm_mcl_bldc_foc_current_cal(BLDC_CONTROL_CURRENT_PARA *par);
  37. /**
  38. * @brief pi control function
  39. *
  40. * @param[inout] par @ref BLDC_CONTRL_PID_PARA
  41. */
  42. void hpm_mcl_bldc_foc_pi_contrl(BLDC_CONTRL_PID_PARA *par);
  43. /**
  44. * @brief Clark Transformation
  45. *
  46. * @param[in] currentu U-phase current
  47. * @param[in] currentv V-phase current
  48. * @param[in] currentw W-phase current
  49. * @param[out] currentalpha alpha-axis current
  50. * @param[out] currentbeta beta-axis current
  51. */
  52. void hpm_mcl_bldc_foc_clarke(HPM_MOTOR_MATH_TYPE currentu, HPM_MOTOR_MATH_TYPE currentv, HPM_MOTOR_MATH_TYPE currentw,
  53. HPM_MOTOR_MATH_TYPE *currentalpha, HPM_MOTOR_MATH_TYPE *currentbeta);
  54. /**
  55. * @brief transform
  56. *
  57. * @brief Park transform
  58. *
  59. * @param[in] currentalpha alpha-axis current
  60. * @param[in] currentbeta beta-axis current
  61. * @param[out] currentd d-axis current
  62. * @param[out] currentq q-axis current
  63. * @param[in] sin_angle sin(theta)
  64. * @param[in] cos_angle cos(theta)
  65. */
  66. void hpm_mcl_bldc_foc_park(HPM_MOTOR_MATH_TYPE currentalpha, HPM_MOTOR_MATH_TYPE currentbeta,
  67. HPM_MOTOR_MATH_TYPE *currentd, HPM_MOTOR_MATH_TYPE *currentq,
  68. HPM_MOTOR_MATH_TYPE sin_angle, HPM_MOTOR_MATH_TYPE cos_angle);
  69. /**
  70. * @brief Motor rotor angle, electrical angle
  71. *
  72. * @param[in] ud d-axis voltage
  73. * @param[in] uq q-axis voltage
  74. * @param[out] ualpha u-alpha-axis voltage
  75. * @param[out] ubeta u-beta-axis voltage
  76. * @param[in] sin_angle sin(theta)
  77. * @param[in] cos_angle cos(theta)
  78. */
  79. void hpm_mcl_bldc_foc_inv_park(HPM_MOTOR_MATH_TYPE ud, HPM_MOTOR_MATH_TYPE uq,
  80. HPM_MOTOR_MATH_TYPE *ualpha, HPM_MOTOR_MATH_TYPE *ubeta,
  81. HPM_MOTOR_MATH_TYPE sin_angle, HPM_MOTOR_MATH_TYPE cos_angle);
  82. /**
  83. * @brief svpwm function
  84. *
  85. * @param par @ref BLDC_CONTROL_PWM_PARA
  86. */
  87. void hpm_mcl_bldc_foc_svpwm(BLDC_CONTROL_PWM_PARA *par);
  88. /**
  89. * @brief Speed Control PI Loop
  90. *
  91. * @param[in] memory Internal Data
  92. * @param[in] targetspeed target speed
  93. * @param[in] curspeed Current speed
  94. * @param[in] kp Scale factor
  95. * @param[in] ki Integral factor
  96. * @param[in] max Output maximum and integration maximum
  97. * @param[out] output Output after pi control
  98. */
  99. void hpm_mcl_bldc_foc_speed_ctrl(float *memory, float targetspeed, float curspeed,
  100. float kp, float ki, int16_t max, int16_t *output);
  101. /**
  102. * @brief Position Control P Loop
  103. *
  104. * @param targetpos Target position
  105. * @param curpos current position
  106. * @param kp Scale factor
  107. * @param max Output maximum
  108. * @param output Output after p control
  109. */
  110. void hpm_mcl_bldc_foc_position_ctrl(float targetpos, float curpos,
  111. float kp, float max, float *output);
  112. /**
  113. * @brief dq-axis voltage conversion to pwm output
  114. *
  115. * @param par @ref BLDC_CONTROL_FOC_PARA
  116. */
  117. void hpm_mcl_bldc_foc_ctrl_dq_to_pwm(BLDC_CONTROL_FOC_PARA *par);
  118. /**
  119. * @}
  120. *
  121. */
  122. #if defined(__cplusplus)
  123. }
  124. #endif /* __cplusplus */
  125. #endif