MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

fw.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 _FW_H_
33 #define _FW_H_
34
40
41
42 // **************************************************************************
43 // the includes
44
45 #include "sw/modules/iqmath/src/32b/IQmathLib.h"
46 #include "sw/modules/types/src/types.h"
47
52
53
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59
60 // **************************************************************************
61 // the defines
62
63
66 #define FW_INC_DELTA (1000)
67
68
71 #define FW_DEC_DELTA (1000)
72
73
76 #define FW_NUM_ISR_TICKS_PER_CTRL_TICK (10)
77
78
79 // **************************************************************************
80 // the typedefs
81
82
85 typedef struct _FW_Obj_
86 {
87 uint32_t numIsrTicksPerFwTick;
88
89 uint32_t counter_fw;
90
91 _iq delta_inc;
92 _iq delta_dec;
93
94 _iq refValue;
95 _iq fbackValue;
96
97 _iq output;
98
99 _iq outMin;
100 _iq outMax;
101
102 bool flag_enableFw;
103 } FW_Obj;
104
105
108 typedef struct _FW_Obj_ *FW_Handle;
109
110
111 // **************************************************************************
112 // the globals
113
114
115 // **************************************************************************
116 // the function prototypes
117
118
123 extern FW_Handle FW_init(void *pMemory, const size_t numBytes);
124
125
130 static inline void FW_getMinMax(FW_Handle fwHandle,_iq *pOutMin,_iq *pOutMax)
131 {
132 FW_Obj *fw = (FW_Obj *)fwHandle;
133
134 *pOutMin = fw->outMin;
135 *pOutMax = fw->outMax;
136
137 return;
138 } // end of FW_getMinMax() function
139
140
145 static inline void FW_setMinMax(FW_Handle fwHandle,const _iq outMin,const _iq outMax)
146 {
147 FW_Obj *fw = (FW_Obj *)fwHandle;
148
149 fw->outMin = outMin;
150 fw->outMax = outMax;
151
152 return;
153 } // end of FW_setMinMax() function
154
155
160 static inline void FW_setDeltas(FW_Handle fwHandle, const _iq delta_inc, const _iq delta_dec)
161 {
162 FW_Obj *fw = (FW_Obj *)fwHandle;
163
164 fw->delta_inc = delta_inc;
165
166 fw->delta_dec = delta_dec;
167
168 return;
169 } // end of FW_setDeltas() function
170
171
175 static inline void FW_setNumIsrTicksPerFwTick(FW_Handle fwHandle, const uint32_t numIsrTicksPerFwTick)
176 {
177 FW_Obj *fw = (FW_Obj *)fwHandle;
178
179 fw->numIsrTicksPerFwTick = numIsrTicksPerFwTick;
180
181 return;
182 } // end of FW_setNumIsrTicksPerFwTick() function
183
184
188 static inline uint32_t FW_getNumIsrTicksPerFwTick(FW_Handle fwHandle)
189 {
190 FW_Obj *fw = (FW_Obj *)fwHandle;
191
192 return(fw->numIsrTicksPerFwTick);
193 } // end of FW_getNumIsrTicksPerFwTick() function
194
195
198 static inline void FW_clearCounter(FW_Handle fwHandle)
199 {
200 FW_Obj *fw = (FW_Obj *)fwHandle;
201
202 fw->counter_fw = 0;
203
204 return;
205 } // end of FW_clearCounter() function
206
207
210 static inline void FW_incCounter(FW_Handle fwHandle)
211 {
212 FW_Obj *fw = (FW_Obj *)fwHandle;
213
214 fw->counter_fw++;
215
216 return;
217 } // end of FW_incCounter() function
218
219
222 static inline uint32_t FW_getCounter(FW_Handle fwHandle)
223 {
224 FW_Obj *fw = (FW_Obj *)fwHandle;
225
226 return(fw->counter_fw);
227 } // end of FW_getCounter() function
228
229
233 static inline void FW_setFlag_enableFw(FW_Handle fwHandle, const bool state)
234 {
235 FW_Obj *fw = (FW_Obj *)fwHandle;
236
237 fw->flag_enableFw = state;
238
239 return;
240 } // end of FW_setFlag_enableFw() function
241
242
246 static inline bool FW_getFlag_enableFw(FW_Handle fwHandle)
247 {
248 FW_Obj *fw = (FW_Obj *)fwHandle;
249
250 return(fw->flag_enableFw);
251 } // end of FW_getFlag_enableFw() function
252
253
257 static inline void FW_setOutput(FW_Handle fwHandle,const _iq output)
258 {
259 FW_Obj *fw = (FW_Obj *)fwHandle;
260
261 fw->output = output;
262
263 return;
264 } // end of FW_setOutput() function
265
266
270 static inline _iq FW_getOutput(FW_Handle fwHandle)
271 {
272 FW_Obj *fw = (FW_Obj *)fwHandle;
273
274 return(fw->output);
275 } // end of FW_getOutput() function
276
277
283 static inline void FW_run(FW_Handle fwHandle,const _iq refValue,const _iq fbackValue,_iq *pOutValue)
284 {
285 FW_Obj *fw = (FW_Obj *)fwHandle;
286
287 _iq Error;
288 _iq output = fw->output;
289 _iq delta_inc = fw->delta_inc;
290 _iq delta_dec = fw->delta_inc;
291
292
293 Error = refValue - fbackValue;
294
295 if(Error < 0)
296 {
297 output = output - delta_dec; // Calculate the output for negative error
298 }
299 else if(Error > 0)
300 {
301 output = output + delta_inc; // Calculate the output for positive error
302 }
303
304 output = _IQsat(output,fw->outMax,fw->outMin); // Saturate the output
305
306 fw->output = output; // store the output
307 fw->refValue = refValue;
308 fw->fbackValue = fbackValue;
309
310 *pOutValue = output;
311
312 return;
313 } // end of FW_run() function
314
315
316 #ifdef __cplusplus
317 }
318 #endif // extern "C"
319
321 #endif // end of _FW_H_ definition
322
_FW_Obj_::refValue
_iq refValue
the reference input value
Definition: fw.h:94
types.h
Contains the public interface to the types definitions.
_FW_Obj_::outMax
_iq outMax
the maximum output value allowed for the FW controller
Definition: fw.h:100
_FW_Obj_::counter_fw
uint32_t counter_fw
the field weakening counter
Definition: fw.h:89
_FW_Obj_::fbackValue
_iq fbackValue
the feedback input value
Definition: fw.h:95
FW_init
FW_Handle FW_init(void *pMemory, const size_t numBytes)
Initializes the field weakening (FW) object.
Definition: fw.c:55
FW_getFlag_enableFw
static bool FW_getFlag_enableFw(FW_Handle fwHandle)
Gets the enable flag of the field weakening (FW) object.
Definition: fw.h:246
FW_getNumIsrTicksPerFwTick
static uint32_t FW_getNumIsrTicksPerFwTick(FW_Handle fwHandle)
Gets the number of ISR ticks per field weakening tick of the field weakening (FW) object...
Definition: fw.h:188
_FW_Obj_::output
_iq output
the output of field weakening
Definition: fw.h:97
FW_setOutput
static void FW_setOutput(FW_Handle fwHandle, const _iq output)
Sets the start value in the FW controller.
Definition: fw.h:257
FW_run
static void FW_run(FW_Handle fwHandle, const _iq refValue, const _iq fbackValue, _iq *pOutValue)
Runs the FW controller.
Definition: fw.h:283
FW_Handle
struct _FW_Obj_ * FW_Handle
Defines the FW handle.
Definition: fw.h:108
FW_getOutput
static _iq FW_getOutput(FW_Handle fwHandle)
Gets the output value in the FW controller.
Definition: fw.h:270
_iq
long _iq
Definition: 32b/IQmathLib.h:223
FW_Obj
struct _FW_Obj_ FW_Obj
Defines the field weakening (FW) data.
FW_incCounter
static void FW_incCounter(FW_Handle fwHandle)
Increments the counter of the field weakening (FW) object.
Definition: fw.h:210
FW_getMinMax
static void FW_getMinMax(FW_Handle fwHandle, _iq *pOutMin, _iq *pOutMax)
Gets the minimum and maximum output value allowed in the FW controller.
Definition: fw.h:130
_FW_Obj_
Defines the field weakening (FW) data.
Definition: fw.h:85
FW_setFlag_enableFw
static void FW_setFlag_enableFw(FW_Handle fwHandle, const bool state)
Sets the enable flag of the field weakening (FW) object.
Definition: fw.h:233
FW_clearCounter
static void FW_clearCounter(FW_Handle fwHandle)
Clears the counter of the field weakening (FW) object.
Definition: fw.h:198
FW_setDeltas
static void FW_setDeltas(FW_Handle fwHandle, const _iq delta_inc, const _iq delta_dec)
Configures the deltas of the field weakening (FW) object.
Definition: fw.h:160
_FW_Obj_::numIsrTicksPerFwTick
uint32_t numIsrTicksPerFwTick
Defines the number of isr clock ticks per field weakening clock tick.
Definition: fw.h:87
_FW_Obj_::outMin
_iq outMin
the minimum output value allowed for the FW controller
Definition: fw.h:99
_FW_Obj_::delta_dec
_iq delta_dec
the field weakening delta decrement of Id reference
Definition: fw.h:92
FW_getCounter
static uint32_t FW_getCounter(FW_Handle fwHandle)
Returns the counter of the field weakening (FW) object.
Definition: fw.h:222
_FW_Obj_::delta_inc
_iq delta_inc
the field weakening delta increment of Id reference
Definition: fw.h:91
FW_setNumIsrTicksPerFwTick
static void FW_setNumIsrTicksPerFwTick(FW_Handle fwHandle, const uint32_t numIsrTicksPerFwTick)
Configures the number of ISR ticks per field weakening tick of the field weakening (FW) object...
Definition: fw.h:175
_IQsat
#define _IQsat(A, Pos, Neg)
Definition: 32b/IQmathLib.h:513
IQmathLib.h
_FW_Obj_::flag_enableFw
bool flag_enableFw
a flag to enable field weakening
Definition: fw.h:102
FW_setMinMax
static void FW_setMinMax(FW_Handle fwHandle, const _iq outMin, const _iq outMax)
Sets the minimum and maximum output value allowed in the FW controller.
Definition: fw.h:145