MotorWare f2806x Module API Documentation
32b/svgen.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #ifndef _SVGEN_H_
33 #define _SVGEN_H_
34 
40 
41 
42 // **************************************************************************
43 // the includes
44 
48 
53 
54 
55 // Include the algorithm overview defined in modules/<module>/docs/doxygen/doxygen.h
57 
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 
64 // **************************************************************************
65 // the defines
66 
69 #define SVGEN_MAX_VAB_VOLTAGES _IQ(1.1547005384)
70 
73 #define SVGEN_100_PERCENT_MODULATION _IQ(1.0 - 1.0/32768)
74 
77 #define SVGEN_SQRT3_OVER_2 _IQ(0.8660254038)
78 
81 #define SVGEN_4_OVER_3 _IQ(4.0/3.0)
82 
83 // **************************************************************************
84 // the typedefs
85 
88 typedef struct _SVGEN_Obj_
89 {
91 } SVGEN_Obj;
92 
93 
96 typedef struct _SVGEN_Obj_ *SVGEN_Handle;
97 
98 
99 // **************************************************************************
100 // the function prototypes
101 
105 static inline _iq SVGEN_getMaxModulation(SVGEN_Handle handle)
106 {
107  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
108 
109  return(obj->maxModulation);
110 } // end of SVGEN_getMaxModulation() function
111 
112 
117 extern SVGEN_Handle SVGEN_init(void *pMemory,const size_t numBytes);
118 
119 
124 static inline void SVGEN_run(SVGEN_Handle handle,const MATH_vec2 *pVab,MATH_vec3 *pT)
125 {
126 
127  _iq Vmax,Vmin,Vcom;
128  _iq Va,Vb,Vc;
129  _iq Va_tmp = -(pVab->value[0]>>1);
130  _iq Vb_tmp = _IQmpy(SVGEN_SQRT3_OVER_2,pVab->value[1]);
131 
132  Va = pVab->value[0]; //alpha
133  Vb = Va_tmp + Vb_tmp; //-0.5*alpha + sqrt(3)/2 * beta;
134  Vc = Va_tmp - Vb_tmp; //-0.5*alpha - sqrt(3)/2 * beta;
135 
136  Vmax=0;
137  Vmin=0;
138 
139  // find order Vmin,Vmid,Vmax
140  if (Va > Vb)
141  {
142  Vmax = Va;
143  Vmin = Vb;
144  }
145  else
146  {
147  Vmax = Vb;
148  Vmin = Va;
149  }
150 
151  if (Vc > Vmax)
152  {
153  Vmax = Vc;
154  }
155  else if (Vc < Vmin)
156  {
157  Vmin = Vc;
158  }
159 
160  Vcom = _IQmpy(Vmax+Vmin, _IQ(0.5));
161 
162  // Subtract common-mode term to achieve SV modulation
163  pT->value[0] = (Va - Vcom);
164  pT->value[1] = (Vb - Vcom);
165  pT->value[2] = (Vc - Vcom);
166 
167  return;
168 } // end of SVGEN_run() function
169 
170 
174 static inline void SVGEN_setMaxModulation(SVGEN_Handle handle,const _iq maxModulation)
175 {
176  SVGEN_Obj *obj = (SVGEN_Obj *)handle;
177  _iq maxMod = maxModulation;
178 
179  if(maxMod > SVGEN_4_OVER_3)
180  maxMod = SVGEN_4_OVER_3;
181  else if(maxMod < _IQ(0.0))
182  maxMod = _IQ(0.0);
183 
184  obj->maxModulation = maxMod;
185 
186  return;
187 } // end of SVGEN_setMaxModulation() function
188 
189 
190 #ifdef __cplusplus
191 }
192 #endif // extern "C"
193 
195 #endif // end of _SVGEN_H_ definition
196 
Contains the public interface to the types definitions.
#define _IQ(A)
Defines a two element vector.
Definition: 32b/math.h:248
_iq value[3]
Definition: 32b/math.h:261
Defines the Space Vector Generator object.
Definition: 32b/svgen.h:88
struct _SVGEN_Obj_ SVGEN_Obj
Defines the Space Vector Generator object.
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
Implements a SVM that saturates at the level of MaxModulation.
Definition: 32b/svgen.h:124
long _iq
_iq maxModulation
The maximum modulation magnitude used in the SVM.
Definition: 32b/svgen.h:90
#define SVGEN_SQRT3_OVER_2
Defines sqrt(3)/2.
Definition: 32b/svgen.h:77
#define _IQmpy(A, B)
_iq value[2]
Definition: 32b/math.h:251
Defines a three element vector.
Definition: 32b/math.h:258
Contains the public interface to the math (MATH) module routines.
static void SVGEN_setMaxModulation(SVGEN_Handle handle, const _iq maxModulation)
Sets the maximum modulation in the space vector generator module.
Definition: 32b/svgen.h:174
struct _SVGEN_Obj_ * SVGEN_Handle
Defines the SVGEN handle.
Definition: 32b/svgen.h:96
#define SVGEN_4_OVER_3
Defines 4/3.
Definition: 32b/svgen.h:81
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
Initializes the space vector generator module.
Definition: 32b/svgen.c:55
static _iq SVGEN_getMaxModulation(SVGEN_Handle handle)
Gets the maximum modulation used in the space vector generator module.
Definition: 32b/svgen.h:105