fwc.h
Go to the documentation of this file.
1 //#############################################################################
2 //
3 // FILE: fwc.h
4 //
5 // TITLE: C28x Field Weakening Control (FWC) library (floating point)
6 //
7 //#############################################################################
8 // $TI Release: MotorControl SDK v3.03.00.00 $
9 // $Release Date: Tue Sep 21 16:33:26 CDT 2021 $
10 // $Copyright:
11 // Copyright (C) 2017-2019 Texas Instruments Incorporated - http://www.ti.com/
12 //
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted provided that the following conditions
15 // are met:
16 //
17 // Redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // Redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the
23 // distribution.
24 //
25 // Neither the name of Texas Instruments Incorporated nor the names of
26 // its contributors may be used to endorse or promote products derived
27 // from this software without specific prior written permission.
28 //
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 // $
41 //#############################################################################
42 
43 #ifndef FWC_H
44 #define FWC_H
45 
46 //*****************************************************************************
47 //
48 // If building with a C++ compiler, make all of the definitions in this header
49 // have a C binding.
50 //
51 //*****************************************************************************
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
57 //*****************************************************************************
58 //
61 //
62 //*****************************************************************************
63 
65 
66 #ifdef __TMS320C28XX_CLA__
67 #include "libraries/math/include/CLAmath.h"
68 #else
69 #include <math.h>
70 #endif
71 
72 #include "pi.h"
73 
74 //*****************************************************************************
75 //
77 //
78 //*****************************************************************************
79 typedef struct _FWC_Obj_
80 {
83 
85  bool flagEnable;
86 } FWC_Obj;
87 
88 //*****************************************************************************
89 //
91 //
92 //*****************************************************************************
93 typedef struct _FWC_Obj_ *FWC_Handle;
94 
95 //*****************************************************************************
96 //
97 // Prototypes for the APIs
98 //
99 //*****************************************************************************
102 static inline void FWC_disable(FWC_Handle handle)
103 {
104  FWC_Obj *obj = (FWC_Obj *)handle;
105 
106  obj->flagEnable = false;
107 
108  return;
109 } // end of FWC_disable() function
110 
111 
114 static inline void FWC_enable(FWC_Handle handle)
115 {
116  FWC_Obj *obj = (FWC_Obj *)handle;
117 
118  obj->flagEnable = true;
119 
120  return;
121 } // end of FWC_enable() function
122 
123 
128 {
129  FWC_Obj *obj = (FWC_Obj *)handle;
130 
131  return(&(obj->angleCurrent_rad));
132 } // end of FWC_getCurrentAngle_rad_addr() function
133 
134 
139 {
140  FWC_Obj *obj = (FWC_Obj *)handle;
141 
142  return(obj->angleCurrent_rad);
143 } // end of FWC_getAnglePhase_rad() function
144 
145 
149 static inline bool FWC_getFlagEnable(FWC_Handle handle)
150 {
151  FWC_Obj *obj = (FWC_Obj *)handle;
152 
153  return(obj->flagEnable);
154 } // end of FWC_getFlagEnable() function
155 
159 static inline void FWC_setCurrentAngle_rad(FWC_Handle handle,
161 {
162  FWC_Obj *obj = (FWC_Obj *)handle;
163 
165 
166  return;
167 } // end of FWC_setCurrentAngle_rad() function
168 
172 static inline void FWC_setFlagEnable(FWC_Handle handle, const bool flagEnable)
173 {
174  FWC_Obj *obj = (FWC_Obj *)handle;
175 
176  obj->flagEnable = flagEnable;
177 
178  return;
179 } // end of FWC_setFlagEnable() function
180 
181 
185 static inline void FWC_setKi(FWC_Handle handle, const float32_t Ki)
186 {
187  FWC_Obj *obj = (FWC_Obj *)handle;
188 
189  PI_setKi(obj->piHandle, Ki);
190 
191  return;
192 } // end of FWC_setKi() function
193 
194 
198 static inline void FWC_setKp(FWC_Handle handle, const float32_t Kp)
199 {
200  FWC_Obj *obj = (FWC_Obj *)handle;
201 
202  PI_setKp(obj->piHandle, Kp);
203 
204  return;
205 } // end of FWC_setKp() function
206 
211 static inline void FWC_setGains(FWC_Handle handle,
212  const float32_t Kp, const float32_t Ki)
213 {
214  FWC_Obj *obj = (FWC_Obj *)handle;
215 
216  PI_setKp(obj->piHandle, Kp);
217  PI_setKi(obj->piHandle, Ki);
218 
219  return;
220 } // end of FWC_setGains() function
221 
222 
227 static inline void FWC_setAngleMinMax(FWC_Handle handle,
228  const float32_t angleMin_rad,
229  const float32_t angleMax_rad)
230 {
231  FWC_Obj *obj = (FWC_Obj *)handle;
232 
233  // set the minimum and maximum values of PI controller
234  PI_setMinMax(obj->piHandle, angleMax_rad, angleMin_rad);
235 
236  return;
237 } // end of FWC_setAngleMinMax() function
238 
239 
243 static inline void FWC_setAngleMax(FWC_Handle handle,
244  const float32_t angleMax_rad)
245 {
246  FWC_Obj *obj = (FWC_Obj *)handle;
247 
248  // set the minimum values of PI controller
249  // convert the maximum angle to negative value in PI controller
250  // the maximum angle = MATH_PI_OVER_TWO - minimum value of PI output
251  PI_setOutMin(obj->piHandle, angleMax_rad);
252 
253  return;
254 } // end of FWC_setAngleMax() function
255 
258 static inline void FWC_resetUi(FWC_Handle handle)
259 {
260  FWC_Obj *obj = (FWC_Obj *)handle;
261 
262  // Sets the integrator start value in the PI controller
263  // reset the new integrator value to Zero
264  PI_setUi(obj->piHandle, 0.0);
265 
266  return;
267 } // end of FWC_setKi() function
268 
272 static inline void FWC_setUi(FWC_Handle handle, const float32_t Ui)
273 {
274  FWC_Obj *obj = (FWC_Obj *)handle;
275 
276  // set the new integrator value
277  PI_setUi(obj->piHandle, Ui);
278 
279  return;
280 } // end of FWC_setKi() function
281 
282 
287 extern FWC_Handle FWC_init(void *pMemory, const size_t numBytes);
288 extern FWC_Handle cla_FWC_init(void *pMemory, const size_t numBytes);
289 
290 
297 extern void FWC_setParams(FWC_Handle handle,
298  const float32_t Kp, const float32_t Ki,
299  const float32_t angleMin_rad,
300  const float32_t angleMax_rad);
301 
302 
308 static inline void FWC_computeCurrentAngle(FWC_Handle handle,
309  const float32_t Vs_V, const float32_t VsRef_V)
310 {
311  FWC_Obj *obj = (FWC_Obj *)handle;
312  float32_t angle_rad = 0.0;
313 
314  float32_t Vs_in_V = Vs_V;
315  float32_t VsRef_in_V = VsRef_V;
316 
317  if(FWC_getFlagEnable(handle) == true)
318  {
319  // Perform the Field Weakening Control (FWC)
320 
321  PI_run_series(obj->piHandle,
322  VsRef_in_V,
323  Vs_in_V,
324  0.0,
325  &angle_rad);
326 
327  obj->angleCurrent_rad = MATH_PI_OVER_TWO - angle_rad;
328  }
329  else
330  {
332  }
333 
334  return;
335 } // end of FWC_computeCurrentAngle() function
336 
337 //*****************************************************************************
338 //
339 // Close the Doxygen group.
341 //
342 //*****************************************************************************
343 
344 //*****************************************************************************
345 //
346 // Mark the end of the C bindings section for C++ compilers.
347 //
348 //*****************************************************************************
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 #endif // FWC_H
FWC_disable
static void FWC_disable(FWC_Handle handle)
Disables the FWC function.
Definition: fwc.h:102
FWC_getCurrentAngle_rad_addr
static float32_t * FWC_getCurrentAngle_rad_addr(FWC_Handle handle)
Gets the stator current phase angle memory address.
Definition: fwc.h:127
FWC_enable
static void FWC_enable(FWC_Handle handle)
Enables the FWC function.
Definition: fwc.h:114
FWC_getFlagEnable
static bool FWC_getFlagEnable(FWC_Handle handle)
Gets the enable controller flag value from the FWC.
Definition: fwc.h:149
pi.h
FWC_Handle
struct _FWC_Obj_ * FWC_Handle
Defines the FWC handle.
Definition: fwc.h:93
_FWC_Obj_::angleCurrent_rad
float32_t angleCurrent_rad
the stator current phase angle
Definition: fwc.h:84
float32_t
float float32_t
Definition: sfra_f32.h:42
PI_setUi
static void PI_setUi(PI_Handle handle, const float32_t Ui)
Sets the integrator start value in the PI controller.
Definition: pi.h:506
PI_setKi
static void PI_setKi(PI_Handle handle, const float32_t Ki)
Sets the integral gain in the PI controller.
Definition: pi.h:376
FWC_setKp
static void FWC_setKp(FWC_Handle handle, const float32_t Kp)
Sets the proportional gain (Kp) value.
Definition: fwc.h:198
MATH_PI_OVER_TWO
#define MATH_PI_OVER_TWO
Defines pi/2.
Definition: math.h:182
FWC_setAngleMinMax
static void FWC_setAngleMinMax(FWC_Handle handle, const float32_t angleMin_rad, const float32_t angleMax_rad)
Sets the minimum and maximum output values of FWC.
Definition: fwc.h:227
FWC_setUi
static void FWC_setUi(FWC_Handle handle, const float32_t Ui)
Sets the integrator start value (Ui)
Definition: fwc.h:272
math.h
FWC_setParams
void FWC_setParams(FWC_Handle handle, const float32_t Kp, const float32_t Ki, const float32_t angleMin_rad, const float32_t angleMax_rad)
Sets the Field Weakening Control (FWC) module parmaeters.
PI_setOutMin
static void PI_setOutMin(PI_Handle handle, const float32_t outMin)
Sets the minimum output value allowed in the PI controller.
Definition: pi.h:464
FWC_setFlagEnable
static void FWC_setFlagEnable(FWC_Handle handle, const bool flagEnable)
Sets the enable flag.
Definition: fwc.h:172
FWC_Obj
struct _FWC_Obj_ FWC_Obj
Defines the Field Weakening Control (FWC) object.
_FWC_Obj_::piHandle
PI_Handle piHandle
the handle for the fwc angle PI controller
Definition: fwc.h:81
FWC_setGains
static void FWC_setGains(FWC_Handle handle, const float32_t Kp, const float32_t Ki)
Sets the gain values.
Definition: fwc.h:211
FWC_setAngleMax
static void FWC_setAngleMax(FWC_Handle handle, const float32_t angleMax_rad)
Sets the maximum output values of FWC.
Definition: fwc.h:243
_FWC_Obj_::flagEnable
bool flagEnable
a flag to enable the controller
Definition: fwc.h:85
PI_setKp
static void PI_setKp(PI_Handle handle, const float32_t Kp)
Sets the proportional gain in the PI controller.
Definition: pi.h:397
cla_FWC_init
FWC_Handle cla_FWC_init(void *pMemory, const size_t numBytes)
_PI_Obj_
Defines the PI controller object.
Definition: pi.h:73
FWC_setCurrentAngle_rad
static void FWC_setCurrentAngle_rad(FWC_Handle handle, const float32_t angleCurrent_rad)
Sets the stator current phase angle value.
Definition: fwc.h:159
FWC_init
FWC_Handle FWC_init(void *pMemory, const size_t numBytes)
Initializes the Field Weakening Control (FWC) module.
_FWC_Obj_
Defines the Field Weakening Control (FWC) object.
Definition: fwc.h:79
FWC_resetUi
static void FWC_resetUi(FWC_Handle handle)
Resets the integrator start value (Ui)
Definition: fwc.h:258
FWC_computeCurrentAngle
static void FWC_computeCurrentAngle(FWC_Handle handle, const float32_t Vs_V, const float32_t VsRef_V)
Runs the Field Weakening Control (FWC)
Definition: fwc.h:308
_FWC_Obj_::pi
PI_Obj pi
the fwc angle PI controller object
Definition: fwc.h:82
PI_setMinMax
static void PI_setMinMax(PI_Handle handle, const float32_t outMin, const float32_t outMax)
Sets the minimum and maximum output value allowed in the PI controller.
Definition: pi.h:421
FWC_getCurrentAngle_rad
static float32_t FWC_getCurrentAngle_rad(FWC_Handle handle)
Gets the stator current phase angle value (angleCurrent_rad)
Definition: fwc.h:138
FWC_setKi
static void FWC_setKi(FWC_Handle handle, const float32_t Ki)
Sets the integral gain (Ki) value.
Definition: fwc.h:185
PI_run_series
static void PI_run_series(PI_Handle handle, const float32_t refValue, const float32_t fbackValue, const float32_t ffwdValue, float32_t *pOutValue)
Runs the series form of the PI controller.
Definition: pi.h:588

Copyright 2023, Texas Instruments Incorporated