MotorWare f2806x Module API Documentation
spintac_pos_conv.h
Go to the documentation of this file.
1 #ifndef __SPINTAC_POS_CONV_H__
2 #define __SPINTAC_POS_CONV_H__
3 /* --COPYRIGHT--,BSD
4  * Copyright (c) 2012, LineStream Technologies Incorporated
5  * Copyright (c) 2012, Texas Instruments Incorporated
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * * Neither the names of Texas Instruments Incorporated, LineStream
20  * Technologies Incorporated, nor the names of its contributors may be
21  * used to endorse or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
34  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  * --/COPYRIGHT--*/
36 
43 
45 
46 
47 #include "spintac_version.h"
48 
51 typedef enum
52 {
57 
61 typedef struct {
68  int16_t LpfTime_tick;
69  // These values are only required for ACIM motors
73 
77 typedef struct {
78  /* Configuration variables */
80  /* Input variables */
84  // Control bits
85  bool ENB;
86  /* Output variables */
90  int32_t PosROCounts;
92  // Information variables
94  uint16_t ERR_ID;
95  /* Internal Variables */
96  uint32_t s0[19];
97 } ST_PosConv_t; // Structure for SpinTAC Position Converter
98 
99 typedef struct _ST_POSCONV_Handle_ *ST_POSCONV_Handle; // SpinTAC Position Converter Handle
100 
104 static inline void STPOSCONV_setSampleTime_sec(ST_POSCONV_Handle handle, _iq24 sampleTime) {
105  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
106 
107  if(obj->STATUS == ST_POS_CONV_IDLE) {
108  obj->cfg.T_sec = sampleTime;
109  }
110 
111  return;
112 } // end of STPOSCONV_setSampleTime_sec function
113 
118 static inline void STPOSCONV_setERevMaximums_erev(ST_POSCONV_Handle handle, _iq24 eRevROMax, _iq24 eRevROMin) {
119  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
120 
121  if(obj->STATUS == ST_POS_CONV_IDLE) {
122  obj->cfg.ROMax_erev = eRevROMax;
123  obj->cfg.ROMin_erev = eRevROMin;
124  }
125 
126  return;
127 } // end of STPOSCONV_setERevMaximums_erev function
128 
134 static inline void STPOSCONV_setUnitConversion(ST_POSCONV_Handle handle, float_t baseFreq, float_t sampleTime, uint16_t polePairs) {
135  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
136 
137  if(obj->STATUS == ST_POS_CONV_IDLE) {
138  obj->cfg.erev_TO_pu_ps = _IQ24(1.0 / (baseFreq * sampleTime));
139  obj->cfg.PolePairs = _IQ24(polePairs);
140  }
141 
142  return;
143 } // end of STPOSCONV_setUnitConversion function
144 
148 static inline void STPOSCONV_setMRevMaximum_mrev(ST_POSCONV_Handle handle, _iq24 mRevROMax) {
149  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
150 
151  if(obj->STATUS == ST_POS_CONV_IDLE) {
152  obj->cfg.ROMax_mrev = mRevROMax;
153  }
154 
155  return;
156 } // end of STPOSCONV_setMRevMaximum_mrev function
157 
161 static inline void STPOSCONV_setLowPassFilterTime_tick(ST_POSCONV_Handle handle, int16_t lpfTime) {
162  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
163 
164  if(obj->STATUS == ST_POS_CONV_IDLE) {
165  obj->cfg.LpfTime_tick = lpfTime;
166  }
167 
168  return;
169 } // end of STPOSCONV_setLowPassFilterTime_tick function
170 
177 static inline void STPOSCONV_setupSlipCompensator(ST_POSCONV_Handle handle, float_t sampleTime, float_t baseFreq, float_t rotorResistance, float_t statorInductance) {
178  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
179 
180  if(obj->STATUS == ST_POS_CONV_IDLE) {
181  obj->cfg.SampleTimeOverTimeConst = _IQ24(sampleTime * (rotorResistance/statorInductance));
182  obj->cfg.OneOverFreqTimeConst = _IQ24((1.0 / baseFreq) * (rotorResistance/statorInductance));
183  }
184 
185  return;
186 } // end of STPOSCONV_setupSlipCompensator function
187 
191 static inline void STPOSCONV_setElecAngle_erev(ST_POSCONV_Handle handle, _iq24 posERev) {
192  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
193 
194  obj->Pos_erev = posERev;
195 
196  return;
197 } // end of STPOSCONV_setElecAngle_erev function
198 
202 static inline void STPOSCONV_setCurrentVector(ST_POSCONV_Handle handle, MATH_vec2 *pIdqIn) {
203  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
204 
205  obj->Id = pIdqIn->value[0];
206  obj->Iq = pIdqIn->value[1];
207 
208  return;
209 } // end of STPOSCONV_setCurrentVector function
210 
215  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
216 
217  return(obj->Vel);
218 } // end of STPOSCONV_getVelocity function
219 
224  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
225 
226  return(obj->VelLpf);
227 } // end of STPOSCONV_getVelocityFiltered function
228 
233  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
234 
235  return(obj->Pos_mrev);
236 } // end of STPOSCONV_getPosition_mrev function
237 
241 static inline int32_t STPOSCONV_getPositionRollOver(ST_POSCONV_Handle handle) {
242  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
243 
244  return(obj->PosROCounts);
245 } // end of STPOSCONV_getPositionRollOver function
246 
251  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
252 
253  return(obj->SlipVel);
254 } // end of STPOSCONV_getSlipVelocity function
255 
259 static inline void STPOSCONV_setEnable(ST_POSCONV_Handle handle, bool enb) {
260  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
261 
262  obj->ENB = enb;
263 
264  return;
265 } // end of STPOSCONV_setEnable function
266 
270 static inline bool STPOSCONV_getEnable(ST_POSCONV_Handle handle) {
271  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
272 
273  return (obj->ENB);
274 } // end of STPOSCONV_getEnable function
275 
280  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
281 
282  return (obj->STATUS);
283 } // end of STPOSCONV_getStatus function
284 
288 static inline uint16_t STPOSCONV_getErrorID(ST_POSCONV_Handle handle) {
289  ST_PosConv_t *obj = (ST_PosConv_t *)handle;
290 
291  return (obj->ERR_ID);
292 } // end of STPOSCONV_getErrorID function
293 
298 ST_POSCONV_Handle STPOSCONV_init(void *pMemory, const size_t numBytes);
299 
302 void STPOSCONV_run(ST_POSCONV_Handle handle); // SpinTAC Position Converter function
304 #endif //__SPINTAC_POS_CONV_H__
_iq24 Pos_mrev
Position { unit: [MRev] }.
_iq24 PolePairs
Conversion ratio from mechanical revolution to electrical revolution { Pole Pairs }...
static void STPOSCONV_setSampleTime_sec(ST_POSCONV_Handle handle, _iq24 sampleTime)
Sets the Sample Time (cfg.T) for SpinTAC Position Converter.
static void STPOSCONV_setupSlipCompensator(ST_POSCONV_Handle handle, float_t sampleTime, float_t baseFreq, float_t rotorResistance, float_t statorInductance)
Sets up the Slip Compensator (only for ACIM) for SpinTAC Position Converter.
ST_POSCONV_Handle STPOSCONV_init(void *pMemory, const size_t numBytes)
Initializes the SpinTAC Position Converter object.
ST_PosConvStatus_e
Enumeration for the Position Convert Status states.
static void STPOSCONV_setLowPassFilterTime_tick(ST_POSCONV_Handle handle, int16_t lpfTime)
Sets the Lowpass Time (cfg.LpfTime_tick) for SpinTAC Position Converter.
_iq24 erev_TO_pu_ps
Conversion ratio from electrical revolution to user unit.
static _iq24 STPOSCONV_getPosition_mrev(ST_POSCONV_Handle handle)
Gets the Position (Pos_mrev) for SpinTAC Position Converter.
Defines a two element vector.
Definition: 32b/math.h:248
_iq24 SampleTimeOverTimeConst
Scalar value used in the Slip Compensator (only needed for ACIM) { value range: positive _IQ24 value ...
_iq24 SlipVel
Speed of the magnetic slip (only for ACIM) { unit: [ERev/s] }.
int16_t LpfTime_tick
Low pass filter ISR ticks { unit: [ticks], value range: [1, 100] }.
_iq24 VelLpf
Speed filtered { unit: [pu/s] }.
static void STPOSCONV_setUnitConversion(ST_POSCONV_Handle handle, float_t baseFreq, float_t sampleTime, uint16_t polePairs)
Sets the Unit Conversions for SpinTAC Position Converter.
Position Converter is in busy state, converting position and velocity signals.
bool ENB
Enable bit { false: disable; true: enable }.
static ST_PosConvStatus_e STPOSCONV_getStatus(ST_POSCONV_Handle handle)
Gets the Status value (STATUS) for SpinTAC Position Converter.
void STPOSCONV_run(ST_POSCONV_Handle handle)
Performs Position Roll Over Addition.
static bool STPOSCONV_getEnable(ST_POSCONV_Handle handle)
Gets the Enable signal (ENB) for SpinTAC Position Converter.
#define _IQ24(A)
static void STPOSCONV_setEnable(ST_POSCONV_Handle handle, bool enb)
Sets the Enable signal (ENB) for SpinTAC Position Converter.
ST_PosConvStatus_e STATUS
Status { ST_POS_CONV_IDLE, ST_POS_CONV_INIT,ST_POS_CONV_BUSY }.
Position Converter is in idle state, zero output.
static _iq24 STPOSCONV_getVelocityFiltered(ST_POSCONV_Handle handle)
Gets the Velocity Filtered (VelLpf) for SpinTAC Position Converter.
static void STPOSCONV_setCurrentVector(ST_POSCONV_Handle handle, MATH_vec2 *pIdqIn)
Sets the Current Vector (IdqIn) (only needed for ACIM) for SpinTAC Position Converter.
static _iq24 STPOSCONV_getVelocity(ST_POSCONV_Handle handle)
Gets the Velocity (Vel) for SpinTAC Position Converter.
_iq value[2]
Definition: 32b/math.h:251
_iq24 Pos_erev
Electrical angle { unit: [ERev] }.
_iq24 OneOverFreqTimeConst
Scalar value used in the Slip Compensator (only needed for ACIM) { value range: positive _IQ24 value ...
long _iq24
Defines the ST_PosConv_t data.
_iq24 ROMax_erev
Maximum bound for electrical revolution { unit: [ERev] }.
_iq24 ROMin_erev
Minimum bound for electrical revolution { unit: [ERev] }.
_iq24 Id
the Id current (only needed for ACIM) { unit: [PU] }
static int32_t STPOSCONV_getPositionRollOver(ST_POSCONV_Handle handle)
Gets the Position RollOver Counts (PosROCounts) for SpinTAC Position Converter.
Public interface, object, and function definitions related to the SpinTAC Version object...
ST_PosConvCfg_t cfg
uint16_t ERR_ID
Error ID { 0: no error; others: see error code }.
int32_t PosROCounts
Position rollover counts.
_iq24 Vel
Speed unfiltered { unit: [pu/s] }.
Position Converter is in init state, validating configured parameters.
static uint16_t STPOSCONV_getErrorID(ST_POSCONV_Handle handle)
Gets the Error value (ERR_ID) for SpinTAC Position Converter.
_iq24 ROMax_mrev
Position Rollover bound { unit: [MRev] }.
Defines the ST_PosConvCfg_t data.
_iq24 T_sec
Sample Time { unit: [s], value range: (0, 0.01] }.
static void STPOSCONV_setERevMaximums_erev(ST_POSCONV_Handle handle, _iq24 eRevROMax, _iq24 eRevROMin)
Sets the Electrical Revolution Maximum (cfg.ERevROMax) & Minimum (cfg.ERevROMin) for SpinTAC Position...
static void STPOSCONV_setElecAngle_erev(ST_POSCONV_Handle handle, _iq24 posERev)
Sets the Electrical Angle (Pos_erev) for SpinTAC Position Converter.
static _iq24 STPOSCONV_getSlipVelocity(ST_POSCONV_Handle handle)
Gets the Slip Velocity (SlipVel) (only for ACIM) for SpinTAC Position Converter.
struct _ST_POSCONV_Handle_ * ST_POSCONV_Handle
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
static void STPOSCONV_setMRevMaximum_mrev(ST_POSCONV_Handle handle, _iq24 mRevROMax)
Sets the Mechanical Revolution Maximum (cfg.ROMax_mrev) for SpinTAC Position Converter.
_iq24 Iq
the Iq current (only needed for ACIM) { unit: [PU] }