park.h
Go to the documentation of this file.
1 //#############################################################################
2 //
3 // FILE: park.h
4 //
5 // TITLE: C28x InstaSPIN park transform library (fixed point)
6 //
7 //#############################################################################
8 // $TI Release: MotorControl SDK v1.00.00.00 $
9 // $Release Date: Mon Mar 11 18:37:40 CDT 2019 $
10 // $Copyright:
11 // Copyright (C) 2017-2018 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 PARK_H
44 #define PARK_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 
64 #ifdef __TMS320C28XX_CLA__
65 #include "libraries/math/include/CLAmath.h"
66 #else
68 #include <math.h>
69 #endif // __TMS320C28XX_CLA__
70 
71 
72 //*****************************************************************************
73 //
75 //
76 //*****************************************************************************
77 typedef struct _PARK_Obj_
78 {
82 } PARK_Obj;
84 
85 //*****************************************************************************
86 //
88 //
89 //*****************************************************************************
90 typedef struct _PARK_Obj_ *PARK_Handle;
91 
92 //*****************************************************************************
93 //
100 //
101 //*****************************************************************************
102 static inline float32_t
104 {
105  PARK_Obj *obj = (PARK_Obj *)handle;
106 
107  return(obj->cosTh);
108 } // end of PARK_getCosTh() function
109 
110 //*****************************************************************************
111 //
119 //
120 //*****************************************************************************
121 static inline void
123 {
124  PARK_Obj *obj = (PARK_Obj *)handle;
125 
126  pPhasor->value[0] = obj->cosTh;
127  pPhasor->value[1] = obj->sinTh;
128 
129  return;
130 } // end of PARK_getPhasor() function
131 
132 //*****************************************************************************
133 //
140 //
141 //*****************************************************************************
142 static inline float32_t
144 {
145  PARK_Obj *obj = (PARK_Obj *)handle;
146 
147  return(obj->sinTh);
148 } // end of PARK_getSinTh() function
149 
150 //*****************************************************************************
151 //
160 //
161 //*****************************************************************************
162 extern PARK_Handle
163 PARK_init(void *pMemory, const size_t numBytes);
164 
165 extern PARK_Handle
166 cla_PARK_init(void *pMemory, const size_t numBytes);
167 
168 //*****************************************************************************
169 //
179 //
180 //*****************************************************************************
181 #ifdef __TMS320C28XX_CLA__
182 #pragma FUNC_ALWAYS_INLINE(PARK_run)
183 #endif
184 
185 static inline void
186 PARK_run(PARK_Handle handle, const MATH_Vec2 *pInVec, MATH_Vec2 *pOutVec)
187 {
188  PARK_Obj *obj = (PARK_Obj *)handle;
189 
190  float32_t sinTh = obj->sinTh;
191  float32_t cosTh = obj->cosTh;
192 
193  float32_t value_0 = pInVec->value[0];
194  float32_t value_1 = pInVec->value[1];
195 
196  pOutVec->value[0] = (value_0 * cosTh) + (value_1 * sinTh);
197  pOutVec->value[1] = (value_1 * cosTh) - (value_0 * sinTh);
198 
199  return;
200 } // end of PARK_run() function
201 
202 //*****************************************************************************
203 //
212 //
213 //*****************************************************************************
214 static inline void
216 {
217  PARK_Obj *obj = (PARK_Obj *)handle;
218 
219  obj->cosTh = cosTh;
220 
221  return;
222 } // end of PARK_setCosTh() function
223 
224 //*****************************************************************************
225 //
233 //
234 //*****************************************************************************
235 static inline void
236 PARK_setPhasor(PARK_Handle handle, const MATH_Vec2 *pPhasor)
237 {
238  PARK_Obj *obj = (PARK_Obj *)handle;
239 
240  obj->cosTh = pPhasor->value[0];
241  obj->sinTh = pPhasor->value[1];
242 
243  return;
244 } // end of PARK_setPhasor() function
245 
246 //*****************************************************************************
247 //
256 //
257 //*****************************************************************************
258 static inline void
260 {
261  PARK_Obj *obj = (PARK_Obj *)handle;
262 
263  obj->sinTh = sinTh;
264 
265  return;
266 } // end of PARK_setSinTh() function
267 
268 //*****************************************************************************
269 //
278 //
279 //*****************************************************************************
280 #ifdef __TMS320C28XX_CLA__
281 #pragma FUNC_ALWAYS_INLINE(PARK_setup)
282 #endif
283 
284 static inline void
286 {
287  PARK_Obj *obj = (PARK_Obj *)handle;
288 
289 #ifdef __TMS320C28XX_CLA__
290  obj->sinTh = CLAsin_inline(Th);
291  obj->cosTh = CLAcos_inline(Th);
292 #else
293  obj->sinTh = __sin(Th);
294  obj->cosTh = __cos(Th);
295 #endif // __TMS320C28XX_CLA__
296 
297  return;
298 } // end of PARK_setup() function
299 
300 //*****************************************************************************
301 //
302 // Close the Doxygen group.
304 //
305 //*****************************************************************************
306 
307 //*****************************************************************************
308 //
309 // Mark the end of the C bindings section for C++ compilers.
310 //
311 //*****************************************************************************
312 #ifdef __cplusplus
313 }
314 #endif
315 
316 #endif // end of PARK_H definition
_MATH_Vec2_
Defines a two element vector.
Definition: math.h:218
_PARK_Obj_
Defines the PARK object.
Definition: park.h:77
float32_t
float float32_t
Definition: sfra_f32.h:42
_PARK_Obj_::cosTh
float32_t cosTh
alpha, beta coordinate systems
Definition: park.h:81
PARK_getCosTh
static float32_t PARK_getCosTh(PARK_Handle handle)
Gets the cosine of the angle between the d,q and the alpha, beta coordinate systems.
Definition: park.h:103
PARK_setPhasor
static void PARK_setPhasor(PARK_Handle handle, const MATH_Vec2 *pPhasor)
Sets the cosine/sine phasor for the inverse Park transform.
Definition: park.h:236
PARK_setSinTh
static void PARK_setSinTh(PARK_Handle handle, const float32_t sinTh)
Sets the sine of the angle between the d,q and the alpha, beta coordinate systems.
Definition: park.h:259
PARK_getPhasor
static void PARK_getPhasor(PARK_Handle handle, MATH_Vec2 *pPhasor)
Gets the cosine/sine phasor for the Park transform.
Definition: park.h:122
PARK_Obj
struct _PARK_Obj_ PARK_Obj
Defines the PARK object.
PARK_setup
static void PARK_setup(PARK_Handle handle, const float32_t Th)
Sets up the Park transform module.
Definition: park.h:285
PARK_setCosTh
static void PARK_setCosTh(PARK_Handle handle, const float32_t cosTh)
Sets the cosine of the angle between the d,q and the alpha, beta coordinate systems.
Definition: park.h:215
_PARK_Obj_::sinTh
float32_t sinTh
alpha, beta coordinate systems
Definition: park.h:79
math.h
PARK_Handle
struct _PARK_Obj_ * PARK_Handle
Defines the PARK handle.
Definition: park.h:90
PARK_getSinTh
static float32_t PARK_getSinTh(PARK_Handle handle)
Gets the sine of the angle between the d,q and the alpha, beta coordinate systems.
Definition: park.h:143
PARK_init
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
Initializes the Park transform module.
cla_PARK_init
PARK_Handle cla_PARK_init(void *pMemory, const size_t numBytes)
PARK_run
static void PARK_run(PARK_Handle handle, const MATH_Vec2 *pInVec, MATH_Vec2 *pOutVec)
Runs the Park transform module.
Definition: park.h:186
_MATH_Vec2_::value
float32_t value[2]
Definition: math.h:220

Copyright 2023, Texas Instruments Incorporated