volt_recons.h
Go to the documentation of this file.
1 //#############################################################################
2 // $TI Release: MotorControl SDK v1.00.00.00 $
3 // $Release Date: Mon Mar 11 18:37:40 CDT 2019 $
4 // $Copyright:
5 // Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the
17 // distribution.
18 //
19 // Neither the name of Texas Instruments Incorporated nor the names of
20 // its contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // $
35 //#############################################################################
36 
37 
38 #ifndef VOLT_RECONS_H
39 #define VOLT_RECONS_H
40 
41 
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 
68 #define MOTOR_MIN_ELEC_FREQ_Hz 5.0f
69 #define MOTOR_MAX_ELEC_FREQ_Hz 800.0f
70 #define MOTOR_THRESHOLD_VOLTAGE_V 0.20f
71 
72 //*****************************************************************************
73 //
75 //
76 //*****************************************************************************
77 typedef struct _VOLREC_Obj_
78 {
86 
90 
94 
97 
98  int32_t numSamples;
99  int32_t minSamples;
100  int32_t maxSamples;
101 
102  int16_t signPrev;
103  int16_t signCurr;
104  int16_t jitterCount;
105 
106  bool flagCalSf;
107 } VOLREC_Obj;
108 
109 //*****************************************************************************
110 //
112 //
113 //*****************************************************************************
114 typedef struct _VOLREC_Obj_ *VOLREC_Handle;
115 
116 
117 //*****************************************************************************
118 //
126 //
127 //*****************************************************************************
128 extern VOLREC_Handle VOLREC_init(void *pMemory, const size_t numBytes);
129 
130 //*****************************************************************************
131 //
143 //
144 //*****************************************************************************
145 static inline void VOLREC_calcVolSF(VOLREC_Handle handle, float32_t VaSen)
146 {
147  VOLREC_Obj *obj = (VOLREC_Obj *)handle;
148 
149  float32_t VaNorm = fabsf(obj->Vin_V.value[0]);
150  obj->VaSen = VaSen;
151 
152  obj->signCurr = (VaNorm > obj->threshold) ? 1 : 0;
153  obj->numSamples++;
154 
155  obj->VaSenSum = obj->VaSenSum + (obj->VaSen * obj->VaSen);
156  obj->VaSum = obj->VaSum + (obj->Vin_V.value[0] * obj->Vin_V.value[0]);
157 
158  if((obj->signPrev != obj->signCurr) && (obj->signCurr == 1))
159  {
160  if(obj->numSamples > obj->minSamples)
161  {
162  float32_t invSamplesSqrt = sqrtf(1.0f / obj->numSamples);
163 
164  obj->VaSenRms = sqrtf(obj->VaSenSum) * invSamplesSqrt;
165  obj->VaRms = sqrtf(obj->VaSum) * invSamplesSqrt;
166 
167  obj->sfCalc = obj->sf * 0.8f + (obj->VaSenRms / obj->VaRms) * 0.2f;
168 
169  obj->sf = __fsat(obj->sfCalc, 0.95f, 0.85f);
170 
171  obj->VaSenSum = 0.0f;
172  obj->VaSum = 0.0f;
173 
174  obj->numSamples = 0;
175  obj->jitterCount = 0;
176  }
177  else
178  {
179  obj->numSamples = 0;
180 
181  if(obj->jitterCount < 25)
182  {
183  obj->jitterCount++;
184  }
185  }
186  }
187 
188  if((obj->numSamples > obj->maxSamples) || (obj->jitterCount >= 20))
189  {
190  obj->VaSenSum = 0.0f;
191  obj->VaSum = 0.0f;
192 
193  obj->jitterCount = 0;
194  obj->numSamples = 0;
195  }
196 
197  obj->signPrev = obj->signCurr;
198 
199  return;
200 }
201 
202 //*****************************************************************************
203 //
215 //
216 //*****************************************************************************
217 static inline void VOLREC_run(VOLREC_Handle handle,
218  float32_t Vdcbus, MATH_Vec3 *pVin, MATH_Vec2 *pVab)
219 {
220  VOLREC_Obj *obj = (VOLREC_Obj *)handle;
221  float32_t Vtemp;
222  MATH_Vec3 Vin;
223  uint16_t cn;
224 
225  // Scale the input Modulation functions with the DC bus voltage value
226  // and calculate the 3 Phase voltages
227  Vtemp = Vdcbus * MATH_ONE_OVER_THREE;
228 
229  Vin.value[0] = Vtemp * (pVin->value[0] * 2.0f - pVin->value[1] - pVin->value[2]);
230  Vin.value[1] = Vtemp * (pVin->value[1] * 2.0f - pVin->value[0] - pVin->value[2]);
231  Vin.value[2] = Vtemp * (pVin->value[2] * 2.0f - pVin->value[1] - pVin->value[0]);
232 
233  for(cn = 0; cn < 3; cn++)
234  {
235  // Compute the output
236  // y0 = (b0 * inputValue) + (a1 * y1);
237  obj->Vin_V.value[cn] = (obj->b0 * Vin.value[cn]) +
238  (obj->b1 * obj->x1.value[cn]) - (obj->a1 * obj->y1.value[cn]);
239 
240  obj->x1.value[cn] = Vin.value[cn];
241 
242  obj->y1.value[cn] = obj->Vin_V.value[cn];
243 
244  obj->Vs_V.value[cn] = obj->Vin_V.value[cn] * obj->sf;
245  }
246 
247  // Voltage transformation (a,b,c) -> (Alpha,Beta)
248  pVab->value[0] = (obj->Vs_V.value[0] * 2.0f -
249  (obj->Vs_V.value[1] + obj->Vs_V.value[2])) * MATH_ONE_OVER_THREE;
250 
251  pVab->value[1] = (obj->Vs_V.value[1] - obj->Vs_V.value[2]) *
253 
254  return;
255 }
256 
257 //*****************************************************************************
258 //
264 //
265 //*****************************************************************************
266 static inline bool VOLREC_getFlagCalSf(VOLREC_Handle handle)
267 {
268  VOLREC_Obj *obj = (VOLREC_Obj *)handle;
269 
270  return(obj->flagCalSf);
271 }
272 
273 //*****************************************************************************
274 //
280 //
281 //*****************************************************************************
282 static inline void VOLREC_setFlagCalSf(VOLREC_Handle handle, const bool flagCalSf)
283 {
284  VOLREC_Obj *obj = (VOLREC_Obj *)handle;
285 
286  obj->flagCalSf = flagCalSf;
287 
288  return;
289 }
290 
291 //*****************************************************************************
292 //
298 //
299 //*****************************************************************************
300 static inline void VOLREC_enableFlagCalSf(VOLREC_Handle handle)
301 {
302  VOLREC_Obj *obj = (VOLREC_Obj *)handle;
303 
304  obj->flagCalSf = true;
305 
306  return;
307 }
308 
309 //*****************************************************************************
310 //
316 //
317 //*****************************************************************************
318 static inline void VOLREC_disableFlagEnableSf(VOLREC_Handle handle)
319 {
320  VOLREC_Obj *obj = (VOLREC_Obj *)handle;
321 
322  obj->flagCalSf = false;
323 
324  return;
325 }
326 
327 
328 //*****************************************************************************
329 //
335 //
336 //*****************************************************************************
337 extern void VOLREC_reset(VOLREC_Handle handle);
338 
339 
340 //*****************************************************************************
341 //
351 //
352 //*****************************************************************************
353 extern void VOLREC_setParams(VOLREC_Handle handle,
354  const float32_t filterPole_rps, const float32_t ctrlFreq_Hz);
355 
356 //*****************************************************************************
357 //
358 // Close the Doxygen group.
360 //
361 //*****************************************************************************
362 
363 //*****************************************************************************
364 //
365 // Mark the end of the C bindings section for C++ compilers.
366 //
367 //*****************************************************************************
368 #ifdef __cplusplus
369 }
370 #endif // extern "C"
371 
372 #endif // end of VOLT_RECONS_H defines
373 
374 
375 
376 
377 
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388 
389 
390 
_MATH_Vec2_
Defines a two element vector.
Definition: math.h:218
VOLREC_disableFlagEnableSf
static void VOLREC_disableFlagEnableSf(VOLREC_Handle handle)
Disables the SF enable flag.
Definition: volt_recons.h:318
_VOLREC_Obj_::jitterCount
int16_t jitterCount
the jitter count due to noise on input
Definition: volt_recons.h:104
_VOLREC_Obj_::signCurr
int16_t signCurr
the flag to detect ZCD
Definition: volt_recons.h:103
_VOLREC_Obj_::minSamples
int32_t minSamples
the sampling points
Definition: volt_recons.h:99
float32_t
float float32_t
Definition: sfra_f32.h:42
types.h
VOLREC_init
VOLREC_Handle VOLREC_init(void *pMemory, const size_t numBytes)
Initializes the Voltage reconstruct module.
_VOLREC_Obj_::x1
MATH_Vec3 x1
the input value at time sample n=-1
Definition: volt_recons.h:82
_VOLREC_Obj_::VaSenSum
float32_t VaSenSum
the square calculation over one sine cycle
Definition: volt_recons.h:92
VOLREC_run
static void VOLREC_run(VOLREC_Handle handle, float32_t Vdcbus, MATH_Vec3 *pVin, MATH_Vec2 *pVab)
Runs the Phase Voltage reconstruction.
Definition: volt_recons.h:217
_VOLREC_Obj_
Defines the VOLREC controller object.
Definition: volt_recons.h:77
_VOLREC_Obj_::sfCalc
float32_t sfCalc
the scale factor of phase voltage
Definition: volt_recons.h:88
VOLREC_setParams
void VOLREC_setParams(VOLREC_Handle handle, const float32_t filterPole_rps, const float32_t ctrlFreq_Hz)
set the Phase Voltage reconstruction parameters
_VOLREC_Obj_::VaRms
float32_t VaRms
the RMS Value
Definition: volt_recons.h:96
math.h
VOLREC_getFlagCalSf
static bool VOLREC_getFlagCalSf(VOLREC_Handle handle)
Gets the SF enable flag.
Definition: volt_recons.h:266
_VOLREC_Obj_::VaSenRms
float32_t VaSenRms
the RMS Value
Definition: volt_recons.h:95
MATH_ONE_OVER_THREE
#define MATH_ONE_OVER_THREE
Defines 1/3.
Definition: math.h:89
_VOLREC_Obj_::flagCalSf
bool flagCalSf
Definition: volt_recons.h:106
_MATH_Vec3_::value
float32_t value[3]
Definition: math.h:232
_VOLREC_Obj_::VaSen
float32_t VaSen
the input Phase voltage phase (V)
Definition: volt_recons.h:91
_VOLREC_Obj_::sf
float32_t sf
the scale factor of phase voltage
Definition: volt_recons.h:87
_VOLREC_Obj_::Vin_V
MATH_Vec3 Vin_V
the input Phase voltage phase (V)
Definition: volt_recons.h:84
_VOLREC_Obj_::y1
MATH_Vec3 y1
the output value at time sample n=-1
Definition: volt_recons.h:83
_VOLREC_Obj_::maxSamples
int32_t maxSamples
the sampling points
Definition: volt_recons.h:100
VOLREC_Handle
struct _VOLREC_Obj_ * VOLREC_Handle
Defines the VOLREC_Handle.
Definition: volt_recons.h:114
VOLREC_enableFlagCalSf
static void VOLREC_enableFlagCalSf(VOLREC_Handle handle)
Enables the SF enable flag.
Definition: volt_recons.h:300
VOLREC_Obj
struct _VOLREC_Obj_ VOLREC_Obj
Defines the VOLREC controller object.
_VOLREC_Obj_::Vs_V
MATH_Vec3 Vs_V
the input Phase voltage phase (V)
Definition: volt_recons.h:85
_VOLREC_Obj_::threshold
float32_t threshold
the voltage level corresponding to zero i/p
Definition: volt_recons.h:89
VOLREC_calcVolSF
static void VOLREC_calcVolSF(VOLREC_Handle handle, float32_t VaSen)
Runs the Phase Voltage reconstruction.
Definition: volt_recons.h:145
_VOLREC_Obj_::b1
float32_t b1
the numerator filter coefficient value for z^(-1)
Definition: volt_recons.h:81
_VOLREC_Obj_::b0
float32_t b0
the numerator filter coefficient value for z^0
Definition: volt_recons.h:80
_VOLREC_Obj_::signPrev
int16_t signPrev
the flag to detect ZCD
Definition: volt_recons.h:102
VOLREC_setFlagCalSf
static void VOLREC_setFlagCalSf(VOLREC_Handle handle, const bool flagCalSf)
Sets up the SF enable flag.
Definition: volt_recons.h:282
VOLREC_reset
void VOLREC_reset(VOLREC_Handle handle)
reset the Phase Voltage reconstruction variables
MATH_ONE_OVER_SQRT_THREE
#define MATH_ONE_OVER_SQRT_THREE
Defines 1/sqrt(3)
Definition: math.h:119
_VOLREC_Obj_::numSamples
int32_t numSamples
the sampling points
Definition: volt_recons.h:98
_VOLREC_Obj_::VaSum
float32_t VaSum
the square calculation over one sine cycle
Definition: volt_recons.h:93
_VOLREC_Obj_::a1
float32_t a1
the denominator filter coefficient value for z^(-1)
Definition: volt_recons.h:79
_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