AM243x Motor Control SDK  09.02.00
filter_fo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef FILTER_FO_H
34 #define FILTER_FO_H
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 #include "dcl.h"
42 #include <stdlib.h>
43 
59 #define _FILTER_FO_Obj_ dcl_df11
62 
63 //*****************************************************************************
64 //
70 //
71 //*****************************************************************************
72 static inline float32_t
74 {
75  return(handle->a1);
76 } // end of FILTER_FO_get_a1() function
77 
78 //*****************************************************************************
79 //
85 //
86 //*****************************************************************************
87 static inline float32_t
89 {
90  return(handle->b0);
91 } // end of FILTER_FO_get_b0() function
92 
93 //*****************************************************************************
94 //
100 //
101 //*****************************************************************************
102 static inline float32_t
104 {
105  return(handle->b1);
106 } // end of FILTER_FO_get_b1() function
107 
108 //*****************************************************************************
109 //
115 //
116 //*****************************************************************************
117 static inline float32_t
119 {
120  return(handle->d1);
121 } // end of FILTER_FO_get_x1() function
122 
123 //*****************************************************************************
124 //
130 //
131 //*****************************************************************************
132 static inline float32_t
134 {
135  return(handle->d2);
136 } // end of FILTER_FO_get_y1() function
137 
138 //*****************************************************************************
139 //
146 //
147 //*****************************************************************************
148 extern void
150 
151 //*****************************************************************************
152 //
162 //
163 //*****************************************************************************
164 extern void
166  float32_t *py1);
167 
168 //*****************************************************************************
169 //
179 //
180 //*****************************************************************************
181 extern void
183 
184 //*****************************************************************************
185 //
195 //
196 //*****************************************************************************
197 extern FILTER_FO_Handle
198 FILTER_FO_init(void *pMemory, const size_t numBytes);
199 
200 //*****************************************************************************
201 //
210 //
211 //*****************************************************************************
212 static inline float32_t
213 FILTER_FO_run(FILTER_FO_Handle handle, const float32_t inputValue)
214 {
215  return(DCL_runDF11(handle,inputValue));
216 } // end of FILTER_FO_run() function
217 
218 //*****************************************************************************
219 //
228 //
229 //*****************************************************************************
230 static inline float32_t
232 {
233  float32_t a1 = handle->a1;
234  float32_t b0 = handle->b0;
235  float32_t d2 = handle->d2;
236 
237  //
238  // Compute the output
239  //
240  handle->d2 = (b0 * inputValue) - (a1 * d2);
241 
242  return(handle->d2);
243 } // end of FILTER_FO_run_form_0() function
244 
245 //*****************************************************************************
246 //
252 //
253 //*****************************************************************************
254 static inline void
256 {
257  handle->a1 = a1;
258 
259  return;
260 } // end of FILTER_FO_set_a1() function
261 
262 //*****************************************************************************
263 //
269 //
270 //*****************************************************************************
271 static inline void
273 {
274  handle->b0 = b0;
275 
276  return;
277 } // end of FILTER_FO_set_b0() function
278 
279 //*****************************************************************************
280 //
286 //
287 //*****************************************************************************
288 static inline void
290 {
291  handle->b1 = b1;
292 
293  return;
294 } // end of FILTER_FO_set_b1() function
295 
296 //*****************************************************************************
297 //
303 //
304 //*****************************************************************************
305 static inline void
307 {
308  handle->d1 = x1;
309 
310  return;
311 } // end of FILTER_FO_set_x1() function
312 
313 //*****************************************************************************
314 //
320 //
321 //*****************************************************************************
322 static inline void
324 {
325  handle->d2 = y1;
326 
327  return;
328 } // end of FILTER_FO_set_y1() function
329 
330 //*****************************************************************************
331 //
337 //
338 //*****************************************************************************
339 extern void
341 
342 //*****************************************************************************
343 //
351 //
352 //*****************************************************************************
353 extern void
355  const float32_t d2);
356 
357 //*****************************************************************************
358 //
366 //
367 //*****************************************************************************
368 extern void
370  const float32_t b1);
371 
374 #ifdef __cplusplus
375 }
376 #endif
377 
378 #endif // FILTER_FO_H
FILTER_FO_get_b0
static float32_t FILTER_FO_get_b0(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b0.
Definition: filter_fo.h:88
FILTER_FO_Handle
DCL_DF11 * FILTER_FO_Handle
Definition: filter_fo.h:61
FILTER_FO_setInitialConditions
void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle, const float32_t d1, const float32_t d2)
Sets the initial conditions of the first-order filter.
FILTER_FO_get_b1
static float32_t FILTER_FO_get_b1(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b1.
Definition: filter_fo.h:103
FILTER_FO_run_form_0
static float32_t FILTER_FO_run_form_0(FILTER_FO_Handle handle, const float32_t inputValue)
Runs a first-order filter of the form y[n] = b0*x[n] - a1*y[n-1].
Definition: filter_fo.h:231
FILTER_FO_set_b0
static void FILTER_FO_set_b0(FILTER_FO_Handle handle, const float32_t b0)
Sets the first-order filter numerator coefficient b0.
Definition: filter_fo.h:272
DCL_DF11
_DCL_VOLATILE struct dcl_df11 DCL_DF11
FILTER_FO_set_b1
static void FILTER_FO_set_b1(FILTER_FO_Handle handle, const float32_t b1)
Sets the first-order filter numerator coefficient b1.
Definition: filter_fo.h:289
FILTER_FO_get_y1
static float32_t FILTER_FO_get_y1(FILTER_FO_Handle handle)
Gets the first-order filter output value at time sample n=-1.
Definition: filter_fo.h:133
DCL_runDF11
_DCL_CRIT_ACCESS float32_t DCL_runDF11(DCL_DF11 *df, float32_t ek)
Executes a 1st order Direct Form 1 controller.
Definition: dcl_df11.h:273
FILTER_FO_getNumCoeffs
void FILTER_FO_getNumCoeffs(FILTER_FO_Handle handle, float32_t *pb0, float32_t *pb1)
Gets the first-order filter numerator coefficients.
FILTER_FO_run
static float32_t FILTER_FO_run(FILTER_FO_Handle handle, const float32_t inputValue)
Runs a first-order filter of the form y[n] = b0*x[n] + b1*x[n-1] - a1*y[n-1].
Definition: filter_fo.h:213
FILTER_FO_getDenCoeffs
void FILTER_FO_getDenCoeffs(FILTER_FO_Handle handle, float32_t *pa1)
Gets the first-order filter denominator coefficients.
dcl.h
Top level header that contains all collections of Digital Controller Library functions.
FILTER_FO_getInitialConditions
void FILTER_FO_getInitialConditions(FILTER_FO_Handle handle, float32_t *px1, float32_t *py1)
Gets the initial conditions of the first-order filter.
FILTER_FO_setNumCoeffs
void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle, const float32_t b0, const float32_t b1)
Sets the first-order filter numerator coefficients.
FILTER_FO_Obj
DCL_DF11 FILTER_FO_Obj
Definition: filter_fo.h:60
FILTER_FO_set_x1
static void FILTER_FO_set_x1(FILTER_FO_Handle handle, const float32_t x1)
Sets the first-order filter input value at time sample n=-1.
Definition: filter_fo.h:306
FILTER_FO_get_x1
static float32_t FILTER_FO_get_x1(FILTER_FO_Handle handle)
Gets the first-order filter input value at time sample n=-1.
Definition: filter_fo.h:118
FILTER_FO_set_y1
static void FILTER_FO_set_y1(FILTER_FO_Handle handle, const float32_t y1)
Sets the first-order filter output value at time sample n=-1.
Definition: filter_fo.h:323
FILTER_FO_get_a1
static float32_t FILTER_FO_get_a1(FILTER_FO_Handle handle)
Gets the first-order filter denominator coefficient a1.
Definition: filter_fo.h:73
FILTER_FO_init
FILTER_FO_Handle FILTER_FO_init(void *pMemory, const size_t numBytes)
Initializes the first-order filter.
FILTER_FO_setDenCoeffs
void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle, const float32_t a1)
Sets the first-order filter denominator coefficients.
float32_t
float float32_t
Definition: dcl_common.h:58
FILTER_FO_set_a1
static void FILTER_FO_set_a1(FILTER_FO_Handle handle, const float32_t a1)
Sets the first-order filter denominator coefficient a1.
Definition: filter_fo.h:255