instaspin_foc
main.h
Go to the documentation of this file.
1 #ifndef _MAIN_H_
2 #define _MAIN_H_
3 /* --COPYRIGHT--,BSD
4  * Copyright (c) 2012, Texas Instruments Incorporated
5  * All rights reserved.
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 distribution.
17  *
18  * * Neither the name of Texas Instruments Incorporated nor the names of
19  * its contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  * --/COPYRIGHT--*/
34 
39 
40 // **************************************************************************
41 // the includes
42 
43 // modules
44 #include "sw/modules/math/src/32b/math.h"
46 #include "sw/modules/est/src/32b/est.h"
51 
52 
53 // drivers
54 
55 
56 // platforms
57 #include "sw/modules/ctrl/src/32b/ctrl.h"
58 #include "hal.h"
59 #include "user.h"
60 
61 
62 // **************************************************************************
63 // the defines
64 
65 
68 #define NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE 1
69 
72 #define MAX_ACCEL_KRPMPS_SF _IQ(USER_MOTOR_NUM_POLE_PAIRS*1000.0/USER_TRAJ_FREQ_Hz/USER_IQ_FULL_SCALE_FREQ_Hz/60.0)
73 
76 #define MOTOR_Vars_INIT {false, \
77  false, \
78  false, \
79  true, \
80  false, \
81  false, \
82  true, \
83  true, \
84  false, \
85  false, \
86  CTRL_State_Idle, \
87  EST_State_Idle, \
88  USER_ErrorCode_NoError, \
89  {0,CTRL_TargetProc_Unknown,0,0}, \
90  _IQ(0.0), \
91  _IQ(0.0), \
92  _IQ(0.0), \
93  _IQ(0.1), \
94  _IQ(0.0), \
95  _IQ(0.2), \
96  _IQ(0.0), \
97  _IQ(USER_MAX_VS_MAG_PU), \
98  _IQ(0.1 * USER_MOTOR_MAX_CURRENT), \
99  400, \
100  _IQ(0.0), \
101  _IQ(0.0), \
102  0.0, \
103  0.0, \
104  0.0, \
105  0.0, \
106  0.0, \
107  0.0, \
108  0.0, \
109  0.0, \
110  _IQ(0.0), \
111  _IQ(0.0), \
112  _IQ(0.0), \
113  0.0, \
114  0.0, \
115  _IQ(0.0), \
116  _IQ(0.0), \
117  _IQ(0.0), \
118  _IQ(0.0), \
119  _IQ(0.0), \
120  _IQ(0.0), \
121  _IQ(0.0), \
122  _IQ(0.8 * USER_MAX_VS_MAG_PU), \
123  _IQ(0.0), \
124  _IQ(0.0), \
125  _IQ(0.0), \
126  _IQ(0.0), \
127  {0,0,0}, \
128  {0,0,0}}
129 
130 
131 // **************************************************************************
132 // the typedefs
133 
134 typedef struct _MOTOR_Vars_t_
135 {
146 
149 
151 
153 
166 
174 
181 
184 
187 
193 
197 
200 
201 }MOTOR_Vars_t;
202 
203 
204 
205 // **************************************************************************
206 // the globals
207 
208 
209 // **************************************************************************
210 // the function prototypes
211 
214 interrupt void mainISR(void);
215 
216 
217 void runCurrentIgnore(void);
218 
219 
220 void runCurrentReconstruction(void);
221 
222 
223 void runFieldWeakening(void);
224 
225 
226 void runOffsetsCalculation(void);
227 
228 
229 void runSetTrigger(void);
230 
231 
235 
236 
239 void updateGlobalVariables(EST_Handle handle);
240 
241 
244 void softwareUpdate1p6(EST_Handle handle);
245 
246 
249 void CTRL_resetLs_qFmt(CTRL_Handle handle, const uint_least8_t qFmt);
250 
251 
255 void recalcKpKiPmsm(CTRL_Handle handle);
256 
257 
260 void recalcKpKi(CTRL_Handle handle);
261 
262 
265 void CTRL_calcMax_Ls_qFmt(CTRL_Handle handle, uint_least8_t *p_qFmt);
266 
267 
270 void updateIqRef(CTRL_Handle handle);
271 
272 
275 void updateKpKiGains(CTRL_Handle handle);
276 
277 
280 void runRsOnLine(CTRL_Handle handle);
281 
282 
285 void updateCPUusage(void);
286 
287 
290 void setFeLimitZero(CTRL_Handle handle);
291 
292 
295 void acim_Dir_qFmtCalc(CTRL_Handle handle);
296 
297 
300 void setupClarke_I(CLARKE_Handle,const uint_least8_t);
301 
302 
305 void setupClarke_V(CLARKE_Handle,const uint_least8_t);
306 
307 
308 _iq angleDelayComp(const _iq fm_pu, const _iq angleUncomp_pu);
309 
310 CTRL_Handle CTRL_init(void *pMemory,const size_t numBytes);
311 
312 void EST_getIdq_pu(EST_Handle handle,MATH_vec2 *pIdq_pu);
313 
314 #if !defined(FAST_ROM_V1p6)
315 void EST_setEstParams(EST_Handle handle,USER_Params *pUserParams);
316 void EST_setupEstIdleState(EST_Handle handle);
317 #endif
318 
319 EST_Handle EST_init(void *pMemory,const size_t numBytes);
320 
326 _iq EST_runPowerWarp(EST_Handle handle,const _iq Id_int_pu,const _iq Iq_pu);
327 
328 _iq getAbsElecAngle(const _iq angle_pu);
329 
330 _iq getAbsMechAngle(_iq *pAngle_mech_poles, _iq *pAngle_z1_pu, const _iq angle_pu);
331 
333 #endif // end of _MAIN_H_ definition
334 
335 
336 
float ipd_waitTime_fine_sec
Definition: main.h:180
void updateGlobalVariables(EST_Handle handle)
Updates the global variables.
Definition: proj_lab11.c:820
void updateIqRef(CTRL_Handle handle)
Updates Iq reference and also sets the right sign to the speed reference for correct force angle...
Definition: proj_lab04.c:522
USER_ErrorCode_e UserErrorCode
Definition: main.h:150
bool Flag_MotorIdentified
Definition: main.h:138
_iq RsOnLineCurrent_A
Definition: main.h:162
float_t RsOnLine_Ohm
Definition: main.h:170
float_t Lsq_H
Definition: main.h:172
_iq Iq_A
Definition: main.h:195
bool Flag_Run_Identify
Definition: main.h:137
_iq ipd_excMag_coarse_pu
Definition: main.h:177
void EST_setupEstIdleState(EST_Handle handle)
CTRL_State_e CtrlState
Definition: main.h:147
void acim_Dir_qFmtCalc(CTRL_Handle handle)
Calculates Dir_qFmt for ACIM.
Definition: proj_lab02a.c:519
bool Flag_enablePowerWarp
Definition: main.h:144
struct _EST_Obj_ * EST_Handle
_iq SvgenMaxModulation_ticks
Definition: main.h:163
void softwareUpdate1p6(EST_Handle handle)
Updates version 1p6 of library.
Definition: proj_lab11.c:736
float_t ipd_excFreq_Hz
Definition: main.h:175
bool Flag_enableForceAngle
Definition: main.h:139
_iq ipd_Kspd
Definition: main.h:176
long _iq
_iq OverModulation
Definition: main.h:161
EST_State_e EstState
Definition: main.h:148
void setupClarke_V(CLARKE_Handle, const uint_least8_t)
Sets up the Clarke transform for voltage.
Definition: fast_obs_im.c:421
float_t Rs_Ohm
Definition: main.h:169
void setFeLimitZero(CTRL_Handle handle)
Set electrical frequency limit to zero while identifying an induction motor.
Definition: proj_lab02a.c:490
void runCurrentReconstruction(void)
Definition: proj_lab11a.c:835
void recalcKpKi(CTRL_Handle handle)
Recalculate Kp and Ki gains to fix the R/L limitation of 2000.0 and Kp limitation of 0...
Definition: proj_lab02a.c:457
void recalcKpKiPmsm(CTRL_Handle handle)
Recalculate Kp and Ki gains to fix the R/L limitation of 2000.0 and Kp limitation of 0...
Definition: proj_lab02c.c:539
struct _MOTOR_Vars_t_ MOTOR_Vars_t
CTRL_Handle CTRL_init(void *pMemory, const size_t numBytes)
EST_Handle EST_init(void *pMemory, const size_t numBytes)
_iq Kp_Idq
Definition: main.h:185
void CTRL_resetLs_qFmt(CTRL_Handle handle, const uint_least8_t qFmt)
Reset Ls Q format to a higher value when Ls identification starts.
Definition: proj_lab02c.c:516
EST_State_e
_iq IqRef_A
Definition: main.h:155
_iq VdcBus_kV
Definition: main.h:192
_iq Torque_Nm
Definition: main.h:165
_iq SpeedRef_krpm
Definition: main.h:157
_iq angleDelayComp(const _iq fm_pu, const _iq angleUncomp_pu)
The angleDelayComp function compensates for the delay introduced.
Definition: proj_lab11.c:704
_iq IdRef_A
Definition: main.h:154
_iq VsRef
Definition: main.h:191
_iq Ki_spd
Definition: main.h:183
float_t Flux_VpHz
Definition: main.h:173
bool Flag_enableUserParams
Definition: main.h:142
bool Flag_enableOffsetcalc
Definition: main.h:143
void setupClarke_I(CLARKE_Handle, const uint_least8_t)
Sets up the Clarke transform for current.
Definition: fast_obs_im.c:392
MATH_vec3 V_bias
Definition: main.h:199
void runSetTrigger(void)
Definition: proj_lab11a.c:957
CTRL_State_e
_iq ipd_excMag_fine_pu
Definition: main.h:178
_iq SpeedRef_pu
Definition: main.h:156
void CTRL_calcMax_Ls_qFmt(CTRL_Handle handle, uint_least8_t *p_qFmt)
Calculates the maximum qFmt value for Ls identification, to get a more accurate Ls per unit...
Definition: proj_lab02c.c:594
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: proj_lab20.c:512
_iq Speed_krpm
Definition: main.h:160
_iq Is_A
Definition: main.h:196
_iq Ki_Idq
Definition: main.h:186
float_t Rr_Ohm
Definition: main.h:168
bool Flag_enableSpeedCtrl
Definition: main.h:145
float_t Lsd_H
Definition: main.h:171
void runCurrentIgnore(void)
Definition: proj_lab11a.c:819
void updateCPUusage(void)
Updates CPU usage.
Definition: fast_obs_im.c:524
float ipd_waitTime_coarse_sec
Definition: main.h:179
_iq SpeedTraj_krpm
Definition: main.h:158
float_t MagnCurr_A
Definition: main.h:167
_iq getAbsMechAngle(_iq *pAngle_mech_poles, _iq *pAngle_z1_pu, const _iq angle_pu)
Calculates mechanical angle from electrical angle.
Definition: proj_lab11b.c:1239
void updateKpKiGains(CTRL_Handle handle)
Updates Kp and Ki gains in the controller object.
Definition: proj_lab20.c:749
void updateGlobalVariables_motor(CTRL_Handle handle)
Updates the global motor variables.
Definition: proj_lab20.c:702
bool Flag_enableSys
Definition: main.h:136
_iq Id_A
Definition: main.h:194
_iq MaxAccel_krpmps
Definition: main.h:159
MATH_vec3 I_bias
Definition: main.h:198
bool Flag_enableRsRecalc
Definition: main.h:141
_iq Kp_spd
Definition: main.h:182
_iq getAbsElecAngle(const _iq angle_pu)
Calculates the absolute electrical angle.
Definition: proj_lab11b.c:1217
USER_ErrorCode_e
CTRL_Version CtrlVersion
Definition: main.h:152
void runRsOnLine(CTRL_Handle handle)
Runs Rs online.
Definition: proj_lab07.c:630
bool Flag_enableFieldWeakening
Definition: main.h:140
void EST_getIdq_pu(EST_Handle handle, MATH_vec2 *pIdq_pu)
void runFieldWeakening(void)
Definition: proj_lab11a.c:864
_iq EST_runPowerWarp(EST_Handle handle, const _iq Id_int_pu, const _iq Iq_pu)
Runs PowerWarp.
void EST_setEstParams(EST_Handle handle, USER_Params *pUserParams)
_iq Flux_Wb
Definition: main.h:164
void runOffsetsCalculation(void)
Definition: proj_lab11a.c:895
float float_t