• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #define MCL_ANALOG_CHN_NUM  10 /**< @ref mcl_analog_chn_t */
12 
13 typedef struct {
14     float res;    /**< Motor resistance in ohms */
15     int32_t pole_num;  /**< Motor pole number */
16     float vbus;     /**< Bus supply voltage */
17     float ld;       /**< d-axis inductors */
18     float lq;   /**< q-axis inductors */
19     float ls;       /**< inductors */
20     float i_max;    /**< Maximum current */
21     float power;    /**< Rated power */
22     float inertia; /**< kgm^2 */
23     float rpm_max; /**< Maximum RPM */
24 } physical_motor_t;
25 
26 typedef struct {
27     int32_t res;    /**< Motor resistance in ohms */
28     int32_t pole_num;  /**< Motor pole number */
29     int32_t vbus;
30     int32_t ld;
31     int32_t lq;
32     int32_t ls;
33     int32_t i_max;
34     int32_t power;
35     int32_t inertia; /**< kgm^2 */
36     int32_t rpm_max;
37 } physical_motor_q_t;
38 
39 typedef struct {
40     float sample_res; /**< Sampling Resistance Value, ohms */
41     float adc_reference_vol; /**< adc reference voltage */
42     float opamp_gain;   /**< operational amplifier amplification */
43     int32_t sample_precision; /**< Sampling accuracy, e.g. 12-bit adc should be set to 4095 */
44 } physical_board_analog_t;
45 
46 typedef struct {
47     int32_t sample_res; /**< Sampling Resistance Value, ohms */
48     int32_t opamp_gain;     /**< operational amplifier amplification */
49     int32_t adc_reference_vol; /**< adc reference voltage */
50     int32_t sample_precision;   /**< Sampling accuracy, e.g. 12-bit adc should be set to 4095 */
51 } physical_board_analog_q_t;
52 
53 typedef struct {
54     physical_board_analog_t analog[MCL_ANALOG_CHN_NUM];
55     int32_t num_current_sample_res; /**< number of sampling resistors */
56     int32_t pwm_reload;    /**< pwm reload maximum */
57     float pwm_frequency;    /**< pwm frequency hz */
58     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*/
59 } physical_board_t;
60 
61 typedef struct {
62     physical_board_analog_q_t analog[MCL_ANALOG_CHN_NUM];
63     int32_t num_current_sample_res; /**< number of sampling resistors */
64     int32_t pwm_reload;    /**< pwm reload maximum */
65     int32_t pwm_frequency;    /**< pwm frequency hz */
66     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*/
67 } physical_board_q_t;
68 
69 typedef struct {
70     int32_t pwm_clock_tick;   /**< pwm clock period */
71     int32_t mcu_clock_tick;   /**< mcu clock period */
72     float speed_loop_ts;    /**< velocity loop operating cycle in s */
73     float current_loop_ts;
74     float position_loop_ts;
75     float encoder_process_ts; /**< Encoder Processing Cycle */
76     float adc_sample_ts;    /**< adc sampling period in s */
77 } physical_time_t;
78 
79 typedef struct {
80     int32_t pwm_clock_tick;   /**< pwm clock period */
81     int32_t mcu_clock_tick;   /**< mcu clock period */
82     int32_t speed_loop_ts;    /**< velocity loop operating cycle in s */
83     int32_t current_loop_ts;
84     int32_t position_loop_ts;
85     int32_t adc_sample_ts;    /**< adc sampling period in s */
86 } physical_time_q_t;
87 
88 typedef struct {
89     physical_motor_t motor;
90     physical_board_t board;
91     physical_time_t time;
92 } mcl_physical_para_t;
93 
94 typedef struct {
95     physical_motor_q_t motor;
96     physical_board_q_t board;
97     physical_time_q_t time;
98 } mcl_physical_para_q_t;
99 
100 #endif