hpm_mcl_physical.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MCL_PHYSICAL_H
  8. #define HPM_MCL_PHYSICAL_H
  9. #include "hpm_common.h"
  10. #define MCL_ANALOG_CHN_NUM 10 /**< @ref mcl_analog_chn_t */
  11. /**
  12. * @brief The mounting angle of the Hall sensor, 60 degrees or 120 degrees,
  13. * is an inherent property of the motor.
  14. *
  15. */
  16. typedef enum {
  17. phase_60, /*60*/
  18. phase_120 /*120*/
  19. } hall_phase_t;
  20. typedef enum {
  21. motor_dir_forward = 1,
  22. motor_dir_back = 2
  23. } mcl_motor_dir_t;
  24. typedef struct {
  25. float res; /**< Motor resistance in ohms */
  26. int32_t pole_num; /**< Motor pole number */
  27. float vbus; /**< Bus supply voltage */
  28. float ld; /**< d-axis inductors */
  29. float lq; /**< q-axis inductors */
  30. float ls; /**< inductors */
  31. float i_max; /**< Maximum current */
  32. float i_rated; /**< Rated current */
  33. float power; /**< Rated power */
  34. float inertia; /**< kgm^2 */
  35. float rpm_max; /**< Maximum RPM */
  36. float flux;
  37. hall_phase_t hall;
  38. } physical_motor_t;
  39. typedef struct {
  40. int32_t res; /**< Motor resistance in ohms */
  41. int32_t pole_num; /**< Motor pole number */
  42. int32_t vbus;
  43. int32_t ld;
  44. int32_t lq;
  45. int32_t ls;
  46. int32_t i_max;
  47. int32_t i_rated;
  48. int32_t power;
  49. int32_t inertia; /**< kgm^2 */
  50. int32_t rpm_max;
  51. int32_t flux;
  52. hall_phase_t hall;
  53. } physical_motor_q_t;
  54. typedef struct {
  55. float sample_res; /**< Sampling Resistance Value, ohms */
  56. float adc_reference_vol; /**< adc reference voltage */
  57. float opamp_gain; /**< operational amplifier amplification */
  58. int32_t sample_precision; /**< Sampling accuracy, e.g. 12-bit adc should be set to 4095 */
  59. } physical_board_analog_t;
  60. typedef struct {
  61. int32_t sample_res; /**< Sampling Resistance Value, ohms */
  62. int32_t opamp_gain; /**< operational amplifier amplification */
  63. int32_t adc_reference_vol; /**< adc reference voltage */
  64. int32_t sample_precision; /**< Sampling accuracy, e.g. 12-bit adc should be set to 4095 */
  65. } physical_board_analog_q_t;
  66. typedef struct {
  67. physical_board_analog_t analog[MCL_ANALOG_CHN_NUM];
  68. int32_t num_current_sample_res; /**< number of sampling resistors */
  69. int32_t pwm_reload; /**< pwm reload maximum */
  70. float pwm_frequency; /**< pwm frequency hz */
  71. int32_t pwm_dead_time_tick; /**< pwm dead time in ticks, A pwm cycle has two dead zones, and this is the time of one of the dead zones*/
  72. } physical_board_t;
  73. typedef struct {
  74. physical_board_analog_q_t analog[MCL_ANALOG_CHN_NUM];
  75. int32_t num_current_sample_res; /**< number of sampling resistors */
  76. int32_t pwm_reload; /**< pwm reload maximum */
  77. int32_t pwm_frequency; /**< pwm frequency hz */
  78. int32_t pwm_dead_tick; /**< pwm dead time in ticks, A pwm cycle has two dead zones, and this is the time of one of the dead zones*/
  79. } physical_board_q_t;
  80. typedef struct {
  81. int32_t pwm_clock_tick; /**< pwm clock period */
  82. int32_t mcu_clock_tick; /**< mcu clock period */
  83. float speed_loop_ts; /**< velocity loop operating cycle in s */
  84. float current_loop_ts;
  85. float position_loop_ts;
  86. float encoder_process_ts; /**< Encoder Processing Cycle */
  87. float adc_sample_ts; /**< adc sampling period in s */
  88. } physical_time_t;
  89. typedef struct {
  90. int32_t pwm_clock_tick; /**< pwm clock period */
  91. int32_t mcu_clock_tick; /**< mcu clock period */
  92. int32_t speed_loop_ts; /**< velocity loop operating cycle in s */
  93. int32_t current_loop_ts;
  94. int32_t position_loop_ts;
  95. int32_t adc_sample_ts; /**< adc sampling period in s */
  96. } physical_time_q_t;
  97. typedef struct {
  98. physical_motor_t motor;
  99. physical_board_t board;
  100. physical_time_t time;
  101. } mcl_physical_para_t;
  102. typedef struct {
  103. physical_motor_q_t motor;
  104. physical_board_q_t board;
  105. physical_time_q_t time;
  106. } mcl_physical_para_q_t;
  107. #endif