step_response.h
Go to the documentation of this file.
1 //#############################################################################
2 // $TI Release: MotorControl SDK v3.00.00.00 $
3 // $Release Date: Fri Mar 27 13:04:40 CDT 2020 $
4 // $Copyright:
5 // Copyright (C) 2017-2019 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 #ifndef STEP_RP_H
38 #define STEP_RP_H
39 
44 
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 // the includes
66 
67 // modules
68 
69 // drivers
70 
71 // platforms
72 
73 // **************************************************************************
74 // the defines
75 // MST: Changed to 4 buffer arrays
76 #define GRAPH_BUFFER_NR 2 // Number of data arrays
77 
78 #define GRAPH_BUFFER_SIZE 256 // Size of data arrays
79 #define GRAPH_BUFFER_MASK (256-1)
80 
81 #define GRAPH_BUFFER_SPEED_TICK 100U
82 #define GRAPH_BUFFER_CURRENT_TICK 10U
83 
84 #define GRAPH_SPEEDREF_DEFAULT 40.0f
85 #define GRAPH_SPEEDREF_STEP 60.0f
86 
87 #define GRAPH_CURRENTREF_DEFAULT 0.0f
88 #define GRAPH_CURRENTREF_STEP -0.5f
89 
90 #define GRAPH_TORQUE_DEFAULT 1.0f
91 #define GRAPH_TORQUE_STEP 4.0f
92 
95 
96 
97 // **************************************************************************
98 // the typedefs
99 
102 typedef enum
103 {
107 
108 typedef enum
109 {
115 
116 typedef struct _GRAPH_Buffer_t_
117 {
119  uint16_t write; // points to empty field
121 
122 typedef struct _GRAPH_StepVars_t_
123 {
124  GRAPH_STEP_RPM_Mode_e bufferMode; // used to define different values to
125  // record for each mode during run time
126 
127  uint16_t stepResponse; // value to start the step response generation
128  uint16_t bufferCounter; // used as an index into the buffer
129  uint16_t bufferTickCounter; // used to count the interrupts
130  uint16_t bufferTick; // defines how many interrupts per graph write
131 
132  volatile float32_t *pSpeed_ref; // Pointer to Setting value of spdRef
133  volatile float32_t *pSpeed_in; // Pointer to Real value of Speed
134 
135  volatile float32_t *pId_ref; // Pointer to Setting value of IdRef
136  volatile float32_t *pId_in; // Pointer to Real value of Id
137 
138  volatile float32_t *pIq_ref; // Pointer to Setting value of IqRef
139  volatile float32_t *pIq_in; // Pointer to Real value of Iq
140 
141  float32_t spdRef_Default; // Default starting value of spdRef
142  float32_t spdRef_StepSize; // Step size of spdRef
143 
144  float32_t IdRef_Default; // Default starting value of IdRef
145  float32_t IdRef_StepSize; // Step size of IdRef
146 
147  float32_t IqRef_Default; // Default starting value of IqRef
148  float32_t IqRef_StepSize; // Step size of IqRef
149 
152 
153 
154 #if defined(STEP_RP_EN)
155 // global variables
156 extern GRAPH_StepVars_t stepRPVars;
157 #endif // STEP_RP_EN
158 
159 // **************************************************************************
160 // the function prototypes
161 
165 static inline bool
167 {
168  uint16_t next = ((pBuffer->write + 1) & GRAPH_BUFFER_MASK);
169 
170  pBuffer->data[pBuffer->write & GRAPH_BUFFER_MASK] = data;
171  pBuffer->write = next;
172 
173  return(true);
174 }
175 
181 
189 void GRAPH_init(GRAPH_StepVars_t *pStepVars,
190  volatile float32_t *pSpeed_ref, volatile float32_t *pSpeed_in,
191  volatile float32_t *pId_ref, volatile float32_t *pId_in,
192  volatile float32_t *pIq_ref, volatile float32_t *pIq_in);
193 
199 static inline void GRAPH_collectData (GRAPH_StepVars_t *pStepVars,
200  GRAPH_BufferNR_e bufferNum, float32_t gData)
201 {
202  if( pStepVars->bufferCounter < GRAPH_BUFFER_SIZE)
203  {
204  if(pStepVars->bufferTickCounter >= pStepVars->bufferTick)
205  {
206  GRAPH_writeDataBuffer(&pStepVars->bufferData[bufferNum], gData);
207 
208  if (bufferNum <= GRAPH_BUFFER_NR0)
209  {
210  pStepVars->bufferCounter++;
211  pStepVars->bufferTickCounter = 0;
212  }
213 
214  } // End (gGraphVars->Buffer_delay_counter <= gGraphVars->Buffer_delay)
215 
216  if (bufferNum <= GRAPH_BUFFER_NR0)
217  {
218  pStepVars->bufferTickCounter++;
219  }
220  } // End if(gGraphVars->bufferCounter < GRAPH_BUFFER_SIZE)
221 
222  return;
223 } // End of Graph_Current_step()
224 
225 
226 static inline GRAPH_STEP_RPM_Mode_e
228 {
229  return(pStepVars->bufferMode);
230 }
231 
236 static inline void GRAPH_updateBuffer(GRAPH_StepVars_t *pStepVars)
237 {
238  switch(pStepVars->bufferMode)
239  {
241  // Id current
243  (*pStepVars->pId_in));
244 
246  (*pStepVars->pSpeed_in));
247  break;
248 
249  case GRAPH_STEP_RP_SPEED:
250  // Iq current and speed
252  (*pStepVars->pIq_in));
253 
255  (*pStepVars->pSpeed_in));
256  break;
257 
259  // Iq current & speed
261  (*pStepVars->pIq_in));
262 
264  (*pStepVars->pSpeed_in));
265  break;
266 
267  default:
268  break;
269  }
270 
271  return;
272 }
273 //*****************************************************************************
274 //
275 // Close the Doxygen group.
277 //
278 //*****************************************************************************
279 
280 //*****************************************************************************
281 //
282 // Mark the end of the C bindings section for C++ compilers.
283 //
284 //*****************************************************************************
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif // end of STEP_RP_H definition
290 
GRAPH_BufferNR_e
GRAPH_BufferNR_e
Enumeration for the number of buffers.
Definition: graph.h:116
_GRAPH_StepVars_t_::spdRef_StepSize
float32_t spdRef_StepSize
Definition: graph.h:166
_GRAPH_StepVars_t_::bufferCounter
uint16_t bufferCounter
Definition: step_response.h:128
float32_t
float float32_t
Definition: sfra_f32.h:42
_GRAPH_StepVars_t_::pSpeed_in
volatile float32_t * pSpeed_in
Definition: graph.h:157
_GRAPH_StepVars_t_::pId_ref
volatile float32_t * pId_ref
Definition: step_response.h:135
_GRAPH_StepVars_t_
Definition: graph.h:153
_GRAPH_StepVars_t_::bufferData
GRAPH_Buffer_t bufferData[2]
Definition: step_response.h:150
_GRAPH_StepVars_t_::pSpeed_ref
volatile float32_t * pSpeed_ref
Definition: graph.h:161
GRAPH_generateStepResponse
void GRAPH_generateStepResponse(GRAPH_StepVars_t *pStepVars)
Sets the values to collect in a data array.
_GRAPH_Buffer_t_::data
float32_t data[256]
Definition: graph.h:136
GRAPH_writeDataBuffer
static bool GRAPH_writeDataBuffer(GRAPH_Buffer_t *pBuffer, float32_t data)
Write into the buffer.
Definition: step_response.h:166
GRAPH_updateBuffer
static void GRAPH_updateBuffer(GRAPH_StepVars_t *pStepVars)
Sets the values to collect in a data array.
Definition: step_response.h:236
math.h
_GRAPH_StepVars_t_::pIq_ref
volatile float32_t * pIq_ref
Definition: step_response.h:138
GRAPH_BUFFER_NR
#define GRAPH_BUFFER_NR
Definition: step_response.h:76
_GRAPH_StepVars_t_::pIq_in
float32_t * pIq_in
Definition: graph.h:159
GRAPH_STEP_RP_SPEED
speed step response
Definition: step_response.h:112
_GRAPH_StepVars_t_::IdRef_Default
float32_t IdRef_Default
Definition: graph.h:168
GRAPH_STEP_RP_IDLE
current step response
Definition: step_response.h:110
GRAPH_BufferNR_e
GRAPH_BufferNR_e
Initialization values of global variables.
Definition: step_response.h:102
_GRAPH_StepVars_t_::IdRef_StepSize
float32_t IdRef_StepSize
Definition: graph.h:169
GRAPH_BUFFER_SIZE
#define GRAPH_BUFFER_SIZE
Definition: step_response.h:78
GRAPH_init
void GRAPH_init(GRAPH_StepVars_t *pStepVars, volatile float32_t *pSpeed_ref, volatile float32_t *pSpeed_in, volatile float32_t *pId_ref, volatile float32_t *pId_in, volatile float32_t *pIq_ref, volatile float32_t *pIq_in)
Data gathering function for any iq value.
_GRAPH_StepVars_t_::bufferTick
uint16_t bufferTick
Definition: step_response.h:130
_GRAPH_StepVars_t_::stepResponse
uint16_t stepResponse
Definition: graph.h:155
GRAPH_BUFFER_NR1
Buffer define 1.
Definition: step_response.h:105
_GRAPH_Buffer_t_
Definition: graph.h:134
_GRAPH_StepVars_t_::pId_in
volatile float32_t * pId_in
Definition: step_response.h:136
_GRAPH_StepVars_t_::pIq_in
volatile float32_t * pIq_in
Definition: step_response.h:139
GRAPH_BUFFER_MASK
#define GRAPH_BUFFER_MASK
Definition: step_response.h:79
_GRAPH_StepVars_t_::bufferTickCounter
uint16_t bufferTickCounter
Definition: step_response.h:129
_GRAPH_StepVars_t_::bufferMode
GRAPH_STEP_RPM_Mode_e bufferMode
Definition: step_response.h:124
_GRAPH_StepVars_t_::spdRef_Default
float32_t spdRef_Default
Definition: graph.h:165
GRAPH_StepVars_t
struct _GRAPH_StepVars_t_ GRAPH_StepVars_t
GRAPH_BUFFER_NR0
Buffer define 0.
Definition: step_response.h:104
_GRAPH_StepVars_t_::IqRef_Default
float32_t IqRef_Default
Definition: step_response.h:147
GRAPH_STEP_RP_CURRENT
d-axis current step response
Definition: step_response.h:111
GRAPH_collectData
static void GRAPH_collectData(GRAPH_StepVars_t *pStepVars, GRAPH_BufferNR_e bufferNum, float32_t gData)
Data gathering function for any iq value.
Definition: step_response.h:199
GRAPH_Buffer_t
struct _GRAPH_Buffer_t_ GRAPH_Buffer_t
_GRAPH_StepVars_t_::IqRef_StepSize
float32_t IqRef_StepSize
Definition: step_response.h:148
_GRAPH_Buffer_t_::write
uint16_t write
Definition: graph.h:138
GRAPH_getBufferMode
static GRAPH_STEP_RPM_Mode_e GRAPH_getBufferMode(GRAPH_StepVars_t *pStepVars)
Definition: step_response.h:227
GRAPH_STEP_RPM_Mode_e
GRAPH_STEP_RPM_Mode_e
Definition: step_response.h:108
GRAPH_STEP_RP_TORQUE
q-axis current step response
Definition: step_response.h:113
_GRAPH_StepVars_t_::pId_in
float32_t * pId_in
Definition: graph.h:158

Copyright 2023, Texas Instruments Incorporated