MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

svgen_current.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 // Texas Instruments (TI) is supplying this software for use solely and
33 // exclusively on TI's microcontroller products. The software is owned by
34 // TI and/or its suppliers, and is protected under applicable copyright
35 // laws. You may not combine this software with "viral" open-source
36 // software in order to form a larger program.
37 //
38 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
39 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
40 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
42 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
43 // DAMAGES, FOR ANY REASON WHATSOEVER.
44 #ifndef SVGENCURRENT_H_
45 #define SVGENCURRENT_H_
46
52
53 // **************************************************************************
54 // the includes
55
56 #include "sw/modules/math/src/32b/math.h"
57 #include "sw/modules/types/src/types.h"
58
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64
65 // **************************************************************************
66 // the typedefs
67
68 typedef enum
69 {
70 use_all=0,
71 ignore_a,
72 ignore_b,
73 ignore_c,
74 ignore_ab,
75 ignore_ac,
76 ignore_bc
77 } SVGENCURRENT_IgnoreShunt_e;
78
79
82 typedef struct _SVGENCURRENT_Obj_
83 {
84 int16_t MinWidth;
85 SVGENCURRENT_IgnoreShunt_e IgnoreShunt;
86
87 } SVGENCURRENT_Obj;
88
89
92 typedef struct _SVGENCURRENT_Obj_ *SVGENCURRENT_Handle;
93
94
95 // **************************************************************************
96 // the function prototypes
97
98
102 extern SVGENCURRENT_Handle SVGENCURRENT_init(void *pMemory,const size_t numBytes);
103
104
109 static inline void SVGENCURRENT_setMinWidth(SVGENCURRENT_Handle svgencurrentHandle,const int16_t minwidth)
110 {
111 SVGENCURRENT_Obj *svgencurrent = (SVGENCURRENT_Obj *)svgencurrentHandle;
112
113 svgencurrent->MinWidth = minwidth;
114
115 return;
116 } // end of SVGENCURRENT_setMinWidth() function
117
118
122 static inline void SVGENCURRENT_setIgnoreShunt(SVGENCURRENT_Handle svgencurrentHandle,const SVGENCURRENT_IgnoreShunt_e ignoreShunt)
123 {
124 SVGENCURRENT_Obj *svgencurrent = (SVGENCURRENT_Obj *)svgencurrentHandle;
125
126 svgencurrent->IgnoreShunt = ignoreShunt;
127
128 return;
129 } // end of SVGENCURRENT_setIgnoreShunt() function
130
131
135 static inline SVGENCURRENT_IgnoreShunt_e SVGENCURRENT_getIgnoreShunt(SVGENCURRENT_Handle svgencurrentHandle)
136 {
137 SVGENCURRENT_Obj *svgencurrent = (SVGENCURRENT_Obj *)svgencurrentHandle;
138
139 return(svgencurrent->IgnoreShunt);
140 } // end of SVGENCURRENT_getIgnoreShunt() function
141
142
147 static inline int16_t SVGENCURRENT_getMinWidth(SVGENCURRENT_Handle svgencurrentHandle)
148 {
149 SVGENCURRENT_Obj *svgencurrent = (SVGENCURRENT_Obj *)svgencurrentHandle;
150
151 return(svgencurrent->MinWidth);
152 } // end of SVGENCURRENT_getMinWidth() function
153
154
165 static inline void SVGENCURRENT_RunIgnoreShunt(SVGENCURRENT_Handle svgencurrentHandle, uint16_t cmp1, uint16_t cmp2, uint16_t cmp3, uint16_t cmpM1, uint16_t cmpM2, uint16_t cmpM3)
166 {
167 SVGENCURRENT_Obj *svgencurrent = (SVGENCURRENT_Obj *)svgencurrentHandle;
168 uint16_t minWidth;
169
170 minWidth = svgencurrent->MinWidth;
171
172 uint16_t nextPulse1 = (cmp1 + cmpM1)>>1;
173 uint16_t nextPulse2 = (cmp2 + cmpM2)>>1;
174 uint16_t nextPulse3 = (cmp3 + cmpM3)>>1;
175
176 if(nextPulse1 < minWidth)
177 {
178 if((nextPulse2 < minWidth) || ((cmp2 - cmp1) < minWidth))
179 {
180 svgencurrent->IgnoreShunt = ignore_ab;
181 }
182 else if((nextPulse3 < minWidth) || ((cmp3 - cmp1) < minWidth))
183 {
184 svgencurrent->IgnoreShunt = ignore_ac;
185 }
186 else
187 {
188 svgencurrent->IgnoreShunt = ignore_a;
189 }
190 }
191 else if(nextPulse2 < minWidth)
192 {
193 if((nextPulse1 < minWidth) || ((cmp1 - cmp2) < minWidth))
194 {
195 svgencurrent->IgnoreShunt = ignore_ab;
196 }
197 else if((nextPulse3 < minWidth) || ((cmp3 - cmp2) < minWidth))
198 {
199 svgencurrent->IgnoreShunt = ignore_bc;
200 }
201 else
202 {
203 svgencurrent->IgnoreShunt = ignore_b;
204 }
205 }
206 else if(nextPulse3 < minWidth)
207 {
208 if((nextPulse1 < minWidth) || ((cmp1 - cmp3) < minWidth))
209 {
210 svgencurrent->IgnoreShunt = ignore_ac;
211 }
212 else if((nextPulse2 < minWidth) || ((cmp2 - cmp3) < minWidth))
213 {
214 svgencurrent->IgnoreShunt = ignore_bc;
215 }
216 else
217 {
218 svgencurrent->IgnoreShunt = ignore_c;
219 }
220 }
221 else
222 {
223 svgencurrent->IgnoreShunt = use_all;
224 }
225
226 return;
227 } // end of SVGENCURRENT_RunIgnoreShunt() function
228
229
233 static inline void SVGENCURRENT_RunRegenCurrent(SVGENCURRENT_Handle svgencurrentHandle, MATH_vec3 *pAdcData)
234 {
235 SVGENCURRENT_Obj *svgencurrent = (SVGENCURRENT_Obj *)svgencurrentHandle;
236
237 _iq Ia = pAdcData->value[0];
238 _iq Ib = pAdcData->value[1];
239 _iq Ic = pAdcData->value[2];
240
241
242 // select valid shunts and ignore one when needed
243 if (svgencurrent->IgnoreShunt==ignore_a)
244 { // repair a based on b and c
245 Ia = -Ib - Ic; //Ia = -Ib - Ic;
246 }
247 else if (svgencurrent->IgnoreShunt==ignore_b)
248 { // repair b based on a and c
249 Ib = -Ia - Ic; //Ib = -Ia - Ic;
250 }
251 else if (svgencurrent->IgnoreShunt==ignore_c)
252 { // repair c based on a and b
253 Ic = -Ia - Ib; //Ic = -Ia - Ib;
254 }
255 else if (svgencurrent->IgnoreShunt==ignore_ab)
256 { // repair a and b based on c
257 Ia = (-Ic)>>1; //Ia = (-Ic)/2;
258 Ib = Ia; //Ib = Ia;
259 }
260 else if (svgencurrent->IgnoreShunt==ignore_ac)
261 { // repair a and c based on b
262 Ia = (-Ib)>>1; //Ia = (-Ib)/2;
263 Ic = Ia; //Ic = Ia;
264 }
265 else if (svgencurrent->IgnoreShunt==ignore_bc)
266 { // repair b and c based on a
267 Ib = (-Ia)>>1; //Ib = (-Ia)/2;
268 Ic = Ib; //Ic = Ib;
269 }
270
271 pAdcData->value[0] = Ia;
272 pAdcData->value[1] = Ib;
273 pAdcData->value[2] = Ic;
274
275 return;
276 } // end of SVGENCURRENT_RunRegenCurrent() function
277
278 #ifdef __cplusplus
279 }
280 #endif // extern "C"
281
282 #endif /*SVGENCURRENT_H_*/
SVGENCURRENT_Obj
struct _SVGENCURRENT_Obj_ SVGENCURRENT_Obj
Defines the Svgen Current object.
types.h
Contains the public interface to the types definitions.
SVGENCURRENT_init
SVGENCURRENT_Handle SVGENCURRENT_init(void *pMemory, const size_t numBytes)
Initializes the svgen current object.
Definition: svgen_current.c:57
SVGENCURRENT_getIgnoreShunt
static SVGENCURRENT_IgnoreShunt_e SVGENCURRENT_getIgnoreShunt(SVGENCURRENT_Handle svgencurrentHandle)
Gets the ignore shunt value.
Definition: svgen_current.h:135
ignore_b
Ignore the B phase shunt measurement.
Definition: svgen_current.h:72
_MATH_vec3_::value
_iq value[3]
Definition: 32b/math.h:261
ignore_ac
Ignore the AC phase shunt measurement.
Definition: svgen_current.h:75
ignore_a
Ignore the A phase shunt measurement.
Definition: svgen_current.h:71
_iq
long _iq
Definition: 32b/IQmathLib.h:223
ignore_bc
Ignore the BC phase shunt measurement.
Definition: svgen_current.h:76
ignore_ab
Ignore the AB phase shunt measurement.
Definition: svgen_current.h:74
_SVGENCURRENT_Obj_::MinWidth
int16_t MinWidth
The maximum width where a valid measurement cannot be taken.
Definition: svgen_current.h:84
_SVGENCURRENT_Obj_::IgnoreShunt
SVGENCURRENT_IgnoreShunt_e IgnoreShunt
Output of what shunt or shunts to ignore.
Definition: svgen_current.h:85
_MATH_vec3_
Defines a three element vector.
Definition: 32b/math.h:258
SVGENCURRENT_getMinWidth
static int16_t SVGENCURRENT_getMinWidth(SVGENCURRENT_Handle svgencurrentHandle)
Gets the minimum Duty Cycle width that the lower switch can be on before.
Definition: svgen_current.h:147
SVGENCURRENT_setIgnoreShunt
static void SVGENCURRENT_setIgnoreShunt(SVGENCURRENT_Handle svgencurrentHandle, const SVGENCURRENT_IgnoreShunt_e ignoreShunt)
Sets the ignore shunt value.
Definition: svgen_current.h:122
math.h
Contains the public interface to the math (MATH) module routines.
SVGENCURRENT_IgnoreShunt_e
SVGENCURRENT_IgnoreShunt_e
Definition: svgen_current.h:68
SVGENCURRENT_setMinWidth
static void SVGENCURRENT_setMinWidth(SVGENCURRENT_Handle svgencurrentHandle, const int16_t minwidth)
Sets the minimum Duty Cycle width that the lower switch can be on before.
Definition: svgen_current.h:109
use_all
Use all shunt measurements.
Definition: svgen_current.h:70
SVGENCURRENT_Handle
struct _SVGENCURRENT_Obj_ * SVGENCURRENT_Handle
Defines the Svgen Current handle.
Definition: svgen_current.h:92
SVGENCURRENT_RunIgnoreShunt
static void SVGENCURRENT_RunIgnoreShunt(SVGENCURRENT_Handle svgencurrentHandle, uint16_t cmp1, uint16_t cmp2, uint16_t cmp3, uint16_t cmpM1, uint16_t cmpM2, uint16_t cmpM3)
Gets the svgen current module ignore shunt.
Definition: svgen_current.h:165
SVGENCURRENT_RunRegenCurrent
static void SVGENCURRENT_RunRegenCurrent(SVGENCURRENT_Handle svgencurrentHandle, MATH_vec3 *pAdcData)
Reconstructs the missed measured currents due to a small sampling window.
Definition: svgen_current.h:233
ignore_c
Ignore the C phase shunt measurement.
Definition: svgen_current.h:73
_SVGENCURRENT_Obj_
Defines the Svgen Current object.
Definition: svgen_current.h:82