hpm_block.h 2.2 KB

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