svgen.h
Go to the documentation of this file.
1 //#############################################################################
2 //
3 // FILE: svgen.h
4 //
5 // TITLE: C28x InstaSPIN Space Vector Generator (SVGEN) library
6 // (floating point)
7 //
8 //#############################################################################
9 // $TI Release: MotorControl SDK v3.00.01.00 $
10 // $Release Date: Tue May 26 19:13:58 CDT 2020 $
11 // $Copyright:
12 // Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
13 //
14 // Redistribution and use in source and binary forms, with or without
15 // modification, are permitted provided that the following conditions
16 // are met:
17 //
18 // Redistributions of source code must retain the above copyright
19 // notice, this list of conditions and the following disclaimer.
20 //
21 // Redistributions in binary form must reproduce the above copyright
22 // notice, this list of conditions and the following disclaimer in the
23 // documentation and/or other materials provided with the
24 // distribution.
25 //
26 // Neither the name of Texas Instruments Incorporated nor the names of
27 // its contributors may be used to endorse or promote products derived
28 // from this software without specific prior written permission.
29 //
30 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 // $
42 //#############################################################################
43 
44 #ifndef SVGEN_H
45 #define SVGEN_H
46 
47 //*****************************************************************************
48 //
49 // If building with a C++ compiler, make all of the definitions in this header
50 // have a C binding.
51 //
52 //*****************************************************************************
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57 
58 //*****************************************************************************
59 //
62 //
63 //*****************************************************************************
64 
65 #include "types.h"
67 
70 typedef enum
71 {
72  SVM_COM_C = 0,
73  SVM_MIN_C = 1,
74  SVM_MAX_C = 2,
75  SVM_DQ_S = 3
76 } SVM_Mode_e;
77 
78 //*****************************************************************************
79 //
81 //
82 //*****************************************************************************
83 typedef struct _SVGEN_Obj_
84 {
86  uint16_t sector;
88 } SVGEN_Obj;
89 
90 //*****************************************************************************
91 //
93 //
94 //*****************************************************************************
95 typedef struct _SVGEN_Obj_ *SVGEN_Handle;
96 
97 //*****************************************************************************
98 //
104 //
105 //*****************************************************************************
106 static inline float32_t
108 {
109  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
110 
111  return(obj->oneOverDcBus_invV);
112 } // end of SVGEN_getOneOverDcBus_invV() function
113 
114 //*****************************************************************************
115 //
121 //
122 //*****************************************************************************
123 static inline SVM_Mode_e SVGEN_getMode(SVGEN_Handle handle)
124 {
125  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
126 
127  return(obj->svmMode);
128 } // end of SVGEN_getMode() function
129 
130 
131 //*****************************************************************************
132 //
138 //
139 //*****************************************************************************
140 static inline uint16_t SVGEN_getSector(SVGEN_Handle handle)
141 {
142  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
143 
144  return(obj->sector);
145 } // end of SVGEN_getSector() function
146 
147 //*****************************************************************************
148 //
156 //
157 //*****************************************************************************
158 static inline void
161 {
162  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
163 
165 
166  return;
167 } // end of SVGEN_setOneOverDcBus_invV() function
168 
169 //*****************************************************************************
170 //
178 //
179 //*****************************************************************************
180 static inline void SVGEN_setMode(SVGEN_Handle handle, SVM_Mode_e svmMode)
181 {
182  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
183 
184  obj->svmMode = svmMode;
185 
186  return;
187 } // end of SVGEN_setMode() function
188 
189 //*****************************************************************************
190 //
198 //
199 //*****************************************************************************
200 static inline void SVGEN_setSector(SVGEN_Handle handle, uint16_t sector)
201 {
202  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
203 
204  obj->sector = sector;
205 
206  return;
207 } // end of SVGEN_setSector() function
208 
209 //*****************************************************************************
210 //
218 //
219 //*****************************************************************************
220 static inline void
222 {
224 
225  return;
226 } // end of SVGEN_setup() function
227 
228 //*****************************************************************************
229 //
238 //
239 //*****************************************************************************
240 extern SVGEN_Handle
241 SVGEN_init(void *pMemory, const size_t numBytes);
242 
243 //*****************************************************************************
244 //
254 //
255 //*****************************************************************************
256 static inline void
257 SVGEN_run(SVGEN_Handle handle, const MATH_Vec2 *pVab_V, MATH_Vec3 *pVabc_pu)
258 {
259  float32_t Vmax_pu = 0,Vmin_pu = 0,Vcom_pu;
261  SVM_Mode_e svmMode = SVGEN_getMode(handle);
262 
263  float32_t Valpha_pu = pVab_V->value[0] * oneOverDcBus_invV;
264  float32_t Vbeta_pu = pVab_V->value[1] * oneOverDcBus_invV;
265 
266  float32_t Va_tmp = (float32_t)(0.5f) * Valpha_pu;
267  float32_t Vb_tmp = MATH_SQRTTHREE_OVER_TWO * Vbeta_pu;
268 
269  float32_t Va_pu = Valpha_pu;
270 
271  //
272  // -0.5*Valpha + sqrt(3)/2 * Vbeta
273  //
274  float32_t Vb_pu = -Va_tmp + Vb_tmp;
275 
276  //
277  // -0.5*Valpha - sqrt(3)/2 * Vbeta
278  float32_t Vc_pu = -Va_tmp - Vb_tmp;
279 
280  //
281  // Find Vmax and Vmin
282  //
283  if(Va_pu > Vb_pu)
284  {
285  Vmax_pu = Va_pu;
286  Vmin_pu = Vb_pu;
287  }
288  else
289  {
290  Vmax_pu = Vb_pu;
291  Vmin_pu = Va_pu;
292  }
293 
294  if(Vc_pu > Vmax_pu)
295  {
296  Vmax_pu = Vc_pu;
297  }
298  else if(Vc_pu < Vmin_pu)
299  {
300  Vmin_pu = Vc_pu;
301  }
302 
303  // Compute Vcom = 0.5*(Vmax+Vmin)
304  Vcom_pu = 0.5f * (Vmax_pu + Vmin_pu);
305 
306  if(svmMode == SVM_COM_C)
307  {
308  // Subtract common-mode term to achieve SV modulation
309  pVabc_pu->value[0] = (Va_pu - Vcom_pu);
310  pVabc_pu->value[1] = (Vb_pu - Vcom_pu);
311  pVabc_pu->value[2] = (Vc_pu - Vcom_pu);
312  }
313  else if(svmMode == SVM_MIN_C)
314  {
315  pVabc_pu->value[0] = (Va_pu - Vmin_pu) - 0.5f;
316  pVabc_pu->value[1] = (Vb_pu - Vmin_pu) - 0.5f;
317  pVabc_pu->value[2] = (Vc_pu - Vmin_pu) - 0.5f;
318  }
319  else if(svmMode == SVM_MAX_C)
320  {
321  pVabc_pu->value[0] = (Va_pu - Vmax_pu) + 0.5f;
322  pVabc_pu->value[1] = (Vb_pu - Vmax_pu) + 0.5f;
323  pVabc_pu->value[2] = (Vc_pu - Vmax_pu) + 0.5f;
324  }
325 
326  return;
327 } // end of SVGEN_run() function
328 
329 //*****************************************************************************
330 //
331 // Close the Doxygen group.
333 //
334 //*****************************************************************************
335 
336 //*****************************************************************************
337 //
338 // Mark the end of the C bindings section for C++ compilers.
339 //
340 //*****************************************************************************
341 #ifdef __cplusplus
342 }
343 #endif
344 
345 #endif // end of SVGEN_H definition
_MATH_Vec2_
Defines a two element vector.
Definition: math.h:218
SVM_DQ_S
SVPWM standard DQ mode.
Definition: svgen.h:75
SVGEN_run
static void SVGEN_run(SVGEN_Handle handle, const MATH_Vec2 *pVab_V, MATH_Vec3 *pVabc_pu)
Implements a SVM that saturates at the level of MaxModulation.
Definition: svgen.h:257
SVGEN_setSector
static void SVGEN_setSector(SVGEN_Handle handle, uint16_t sector)
Sets the spave vector sector value.
Definition: svgen.h:200
SVGEN_getOneOverDcBus_invV
static float32_t SVGEN_getOneOverDcBus_invV(SVGEN_Handle handle)
Gets the one over DC bus voltage value.
Definition: svgen.h:107
float32_t
float float32_t
Definition: sfra_f32.h:42
types.h
SVM_MIN_C
DPWM minimum SVM mode.
Definition: svgen.h:73
SVM_Mode_e
SVM_Mode_e
Enumeration for svpwm mode.
Definition: svgen.h:70
_SVGEN_Obj_::sector
uint16_t sector
the sector value of space vector
Definition: svgen.h:86
_SVGEN_Obj_
Defines the Space Vector Generator (SVGEN) object.
Definition: svgen.h:83
SVGEN_setOneOverDcBus_invV
static void SVGEN_setOneOverDcBus_invV(SVGEN_Handle handle, const float32_t oneOverDcBus_invV)
Sets the one over DC bus voltage value.
Definition: svgen.h:159
_SVGEN_Obj_::oneOverDcBus_invV
float32_t oneOverDcBus_invV
The inverse DC bus voltage value, 1/V.
Definition: svgen.h:85
math.h
SVGEN_Handle
struct _SVGEN_Obj_ * SVGEN_Handle
Defines the SVGEN handle.
Definition: svgen.h:95
_SVGEN_Obj_::svmMode
SVM_Mode_e svmMode
Definition: svgen.h:87
SVGEN_setup
static void SVGEN_setup(SVGEN_Handle handle, const float32_t oneOverDcBus_invV)
Sets up the space vector generator (SVGEN) module.
Definition: svgen.h:221
_MATH_Vec3_::value
float32_t value[3]
Definition: math.h:232
MATH_SQRTTHREE_OVER_TWO
#define MATH_SQRTTHREE_OVER_TWO
Defines sqrt(3)/2.
Definition: math.h:422
SVGEN_Obj
struct _SVGEN_Obj_ SVGEN_Obj
Defines the Space Vector Generator (SVGEN) object.
SVGEN_getSector
static uint16_t SVGEN_getSector(SVGEN_Handle handle)
Gets the spave vector sector value.
Definition: svgen.h:140
SVM_MAX_C
DPWM maximum SVM.
Definition: svgen.h:74
SVGEN_setMode
static void SVGEN_setMode(SVGEN_Handle handle, SVM_Mode_e svmMode)
Sets the spave vector mode.
Definition: svgen.h:180
SVGEN_init
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
Initializes the space vector generator module.
SVM_COM_C
SVPWM common SVM mode.
Definition: svgen.h:72
SVGEN_getMode
static SVM_Mode_e SVGEN_getMode(SVGEN_Handle handle)
Gets the spave vector mode.
Definition: svgen.h:123
_MATH_Vec2_::value
float32_t value[2]
Definition: math.h:220
_MATH_Vec3_
Defines a three element vector.
Definition: math.h:230

Copyright 2023, Texas Instruments Incorporated