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