|
AM263x Digital Power SDK
09.01.00
|
|
Go to the documentation of this file.
48 #include "../dcl_common.h"
55 typedef struct dcl_pid_sps
69 #define PID_SPS_DEFAULTS { 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f }
98 #define PID_DEFAULTS { 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, \
99 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, \
100 &(DCL_PID_SPS)PID_SPS_DEFAULTS, &(DCL_CSS)DCL_CSS_DEFAULTS }
110 #define PID_INT_DEFAULTS .d2=0.0f, .d3=0.0f, .i10=0.0f, .i14=1.0f, \
111 .sps=&(DCL_PID_SPS)PID_SPS_DEFAULTS, .css=&(DCL_CSS)DCL_CSS_DEFAULTS
118 #define DCL_initPID() &(DCL_PID)PID_DEFAULTS
126 #define DCL_initPIDasParam(kp,ki,kd,kr,_c1,_c2,umax,umin) &(DCL_PID){ .Kp=kp, .Ki=ki, .Kd=kd, .Kr=kr, \
127 .c1=_c1, .c2=_c2, .Umax=umax, .Umin=umin, PID_INT_DEFAULTS }
140 #define DCL_initPIDasSPS(pid_ptr,sps_ptr) \
142 DCL_PID* new_pid = (pid_ptr) ? pid_ptr : DCL_initPID(); \
143 DCL_PID_SPS* new_sps = (sps_ptr) ? sps_ptr : &(DCL_PID_SPS)PID_SPS_DEFAULTS; \
146 *new_pid = (DCL_PID){ (new_sps)->Kp, (new_sps)->Ki, (new_sps)->Kd,(new_sps)->Kr,\
147 (new_sps)->c1, (new_sps)->c2, (new_sps)->Umax, (new_sps)->Umin, 0.0f, 0.0f, \
148 0.0f, 1.0f, (DCL_PID_SPS*)new_sps, &(DCL_CSS)DCL_CSS_DEFAULTS }; \
162 pid->d2 = pid->d3 = pid->i10 = 0.0f;
175 #ifdef DCL_ERROR_HANDLING_ENABLED
176 float32_t tau = (2.0f - pid->sps->c1 * pid->css->T) / (2.0f * pid->sps->c1);
177 float32_t ec2 = pid->sps->c1 * (pid->css->T - 2.0f * tau) / 2.0f;
182 err_code |= ((pid->sps->Kp > 0.0f) && (pid->sps->Ki > 0.0f) && (pid->sps->Kd > 0.0f) && (pid->sps->Kr > 0.0f)) ?
dcl_none :
dcl_param_range_err ;
191 pid->Kp = pid->sps->Kp;
192 pid->Ki = pid->sps->Ki;
193 pid->Kd = pid->sps->Kd;
194 pid->Kr = pid->sps->Kr;
195 pid->c1 = pid->sps->c1;
196 pid->c2 = pid->sps->c2;
197 pid->Umax = pid->sps->Umax;
198 pid->Umin = pid->sps->Umin;
209 #ifdef DCL_ERROR_HANDLING_ENABLED
210 float32_t tau = (2.0f - pid->sps->c1 * pid->css->T) / (2.0f * pid->sps->c1);
211 float32_t ec2 = pid->sps->c1 * (pid->css->T - 2.0f * tau) / 2.0f;
216 err_code |= ((pid->sps->Kp > 0.0f) && (pid->sps->Ki > 0.0f) && (pid->sps->Kd > 0.0f) && (pid->sps->Kr > 0.0f)) ?
dcl_none :
dcl_param_range_err ;
227 pid->Kp = pid->sps->Kp;
228 pid->Ki = pid->sps->Ki;
229 pid->Kd = pid->sps->Kd;
230 pid->Kr = pid->sps->Kr;
231 pid->c1 = pid->sps->c1;
232 pid->c2 = pid->sps->c2;
233 pid->Umax = pid->sps->Umax;
234 pid->Umin = pid->sps->Umin;
269 #ifdef DCL_ERROR_HANDLING_ENABLED
282 pid->sps->c1 = 2.0f / (T + (2.0f * tau));
283 pid->sps->c2 = (T - (2.0f * tau)) / (T + (2.0f * tau));
298 #ifdef DCL_ERROR_HANDLING_ENABLED
310 pid->c1 = 2.0f / (T + (2.0f * tau));
311 pid->c2 = (T - (2.0f * tau)) / (T + (2.0f * tau));
322 float32_t tau = ((2.0f - pid->c1 * pid->css->T) / (2.0f * pid->c1));
323 return(1.0f / (2.0f *
CONST_PI * tau));
338 #ifdef DCL_ERROR_HANDLING_ENABLED
357 float32_t a0p = 4.0f + (alpha1 * 2.0f * T) + (alpha0 * T * T);
358 float32_t b0 = zpk->
K * (4.0f + (beta1 * 2.0f * T) + (beta0 * T *T)) / a0p;
359 float32_t b1 = zpk->
K * (-8.0f + (2.0f * beta0 * T * T)) / a0p;
360 float32_t b2 = zpk->
K * (4.0f - (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
361 float32_t a2 = (4.0f - (alpha1 * 2.0f * T) + (alpha0 * T * T)) / a0p;
363 float32_t tau = (T / 2.0f) * (1.0f - c2) / (1.0f + c2);
364 pid->sps->c1 = 2.0f / (T + 2.0f * tau);
369 #ifdef DCL_ERROR_HANDLING_ENABLED
380 float32_t k1 = ((c2 * b0) - b1 - ((2.0f + c2) * b2)) / det;
381 float32_t k2 = (c2 + 1.0f) * (b0 + b1 + b2) / det;
382 float32_t k3 = ((c2 * c2 * b0) - (c2 * b1) + b2) / det;
384 pid->sps->Ki = k2 / k1;
385 pid->sps->Kd = k3 / (k1 * pid->sps->c1);
387 #ifdef DCL_TESTPOINTS_ENABLED
404 #ifdef DCL_ERROR_HANDLING_ENABLED
423 float32_t a0p = 4.0f + (alpha1 * 2.0f * T) + (alpha0 * T * T);
424 float32_t b0 = zpk->
K * (4.0f + (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
425 float32_t b1 = zpk->
K * (-8.0f + (2.0f * beta0 * T * T)) / a0p;
426 float32_t b2 = zpk->
K * (4.0f - (beta1 * 2.0f * T) + (beta0 * T * T)) / a0p;
427 float32_t a2 = (4.0f - (alpha1 * 2.0f * T) + (alpha0 * T * T)) / a0p;
429 float32_t tau = (T / 2.0f) * (1.0f - c2) / (1.0f + c2);
430 pid->sps->c1 = 2.0f / (T + 2.0f * tau);
435 #ifdef DCL_ERROR_HANDLING_ENABLED
445 pid->sps->Kp = ((c2 * b0) - b1 - ((2.0f + c2) * b2)) / det;
446 pid->sps->Ki = (c2 + 1.0f) * (b0 + b1 + b2) / det;
447 pid->sps->Kd = ((c2 * c2 * b0) - (c2 * b1) + b2) / (det * pid->sps->c1);
449 #ifdef DCL_TESTPOINTS_ENABLED
468 v5 = (pid->Kr * rk) - yk;
469 v8 = ((rk - yk) * pid->Ki * pid->Kp * pid->i14) + pid->i10;
471 v1 = yk * pid->Kd * pid->c1;
472 v4 = v1 - pid->d2 - pid->d3;
474 pid->d3 = v4 * pid->c2;
475 v9 = ((v5 - v4) * pid->Kp) + v8;
477 v12 = (v10 == v9) ? 1.0f : 0.0f;
480 #ifdef DCL_TESTPOINTS_ENABLED
498 float32_t v1, v4, v5, v6, v8, v9, v10, v12;
502 v8 = v5 * pid->Ki * pid->i14 + pid->i10;
504 v1 = v5 * pid->Kd * pid->c1;
505 v4 = v1 - pid->d2 - pid->d3;
507 pid->d3 = v4 * pid->c2;
510 v12 = (v10 == v9) ? 1.0f : 0.0f;
513 #ifdef DCL_TESTPOINTS_ENABLED
526 #endif // _DCL_PID_H_
DCL_PID_SPS * sps
updates controller parameter
Definition: dcl_pid.h:92
_DCL_CODE_ACCESS _DCL_CODE_SECTION bool DCL_updatePID(DCL_PID *pid)
A conditional update based on the update flag. If the update status is set, the function will update ...
Definition: dcl_pid.h:247
_DCL_VOLATILE struct dcl_pid DCL_PID
float32_t c1
D path filter coefficient 1, default is 1.
Definition: dcl_pid.h:80
#define DCL_isValue(x, y)
Determines numerical proximity to specified value.
Definition: dcl_aux.h:72
#define CONST_PI
Local definitions of the mathematical constant pi.
Definition: dcl_aux.h:55
float32_t Umin
Lower saturation limit
Definition: dcl_pid.h:83
float32_t K
Real gain.
Definition: dcl_zpk3.h:69
_DCL_CODE_ACCESS void DCL_setPIDfilterBW(DCL_PID *pid, float32_t fc)
Loads the derivative path filter shadow coefficients. Note: Sampling period pid->css->T are used in t...
Definition: dcl_pid.h:266
float32_t Kp
Proportional gain.
Definition: dcl_pid.h:57
float complex z2
Complex zeros 2.
Definition: dcl_zpk3.h:64
float32_t Umax
Upper saturation limit.
Definition: dcl_pid.h:63
#define _DCL_CODE_SECTION
Defines dcl function section that users can specify in the linker file(.cmd) and to accelerate perfor...
Definition: dcl_common.h:63
float complex p2
Complex poles 2.
Definition: dcl_zpk3.h:67
Defines DCL_PID shadow parameter set used for updating controller parameter.
Definition: dcl_pid.h:56
float32_t Umax
Upper saturation limit.
Definition: dcl_pid.h:82
DCL_PID object for storing PID specific parameters.
Definition: dcl_pid.h:74
#define DCL_runErrorHandler(ptr)
Prototype for basic error handler.
Definition: dcl_error.h:107
@ dcl_param_range_err
Parameter range exceeded.
Definition: dcl_error.h:58
float32_t Kd
Derivative gain.
Definition: dcl_pid.h:59
_DCL_CODE_ACCESS _DCL_CODE_SECTION float32_t DCL_runPIDParallel(DCL_PID *pid, float32_t rk, float32_t yk, float32_t lk)
Executes a parallel form PID controller.
Definition: dcl_pid.h:496
#define DCL_getUpdateStatus(p)
Determine whether a parameter update-in-progress flag is set.
Definition: dcl_css.h:122
float32_t d3
D path feedback value (c2)
Definition: dcl_pid.h:87
#define DCL_clearUpdateStatus(p)
Definition: dcl_css.h:116
float32_t c2
D path filter coefficient 2, default is 0.
Definition: dcl_pid.h:62
_DCL_CODE_ACCESS _DCL_CODE_SECTION void DCL_updatePIDNoCheck(DCL_PID *pid)
Loads PID tuning parameter from its SPS parameter with interrupt protection.
Definition: dcl_pid.h:206
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions (static inline/extern inline/none)
Definition: dcl_common.h:58
float complex p1
Complex poles 1.
Definition: dcl_zpk3.h:66
_DCL_CODE_ACCESS void DCL_resetPID(DCL_PID *pid)
Resets PID internal storage data with interrupt protection.
Definition: dcl_pid.h:158
_DCL_CODE_ACCESS void DCL_forceUpdatePID(DCL_PID *pid)
Loads PID tuning parameter from its SPS parameter without interrupt protection.
Definition: dcl_pid.h:172
float32_t Kp
Proportional gain.
Definition: dcl_pid.h:76
@ dcl_none
No error.
Definition: dcl_error.h:57
float32_t i14
I path saturation storage.
Definition: dcl_pid.h:89
uint32_t dcl_interrupt_t
Definition: dcl_common.h:99
_DCL_CODE_ACCESS float32_t DCL_getPIDfilterBW(DCL_PID *pid)
Calculates the active derivative path filter bandwidth in Hz. Note: Sampling period pid->css->T are u...
Definition: dcl_pid.h:320
float32_t Ki
Integral gain.
Definition: dcl_pid.h:77
_DCL_VOLATILE struct dcl_pid * PID_Handle
#define DCL_isZero(x)
Determines floating point numerical proximity to zero.
Definition: dcl_aux.h:77
float32_t Umin
Lower saturation limit.
Definition: dcl_pid.h:64
float32_t c2
D path filter coefficient 2, default is 0.
Definition: dcl_pid.h:81
float32_t Kr
Set point weight, default is 1.
Definition: dcl_pid.h:79
#define DCL_c2Limit
Defines the lower limit on derivative filter coefficient c2 in order for fc to lie below the Nyquist ...
Definition: dcl_aux.h:93
@ dcl_param_invalid_err
Parameter not valid.
Definition: dcl_error.h:59
_DCL_CODE_ACCESS void DCL_loadParallelPIDasZPK(DCL_PID *pid, DCL_ZPK3 *zpk)
Configures a parallel PID controller in ZPK form. Note: Sampling period pid->css->T are used in the c...
Definition: dcl_pid.h:402
#define DCL_runSat(data, Umax, Umin)
Macro to saturate a control variable but does not change the data itself unlike runClamp()
Definition: dcl_clamp.h:89
Defines the controller common support structure.
Definition: dcl_css.h:57
#define DCL_restoreInts(v)
Definition: dcl_common.h:98
float32_t i10
I path feedback value.
Definition: dcl_pid.h:88
Defines the DCL_ZPK3 controller structure.
Definition: dcl_zpk3.h:62
#define _DCL_VOLATILE
Defines volatile for DCL strctures Flags can be defined in dcl.h or user files before including DCL l...
Definition: dcl_common.h:71
DCL_CSS * css
configuration & debugging
Definition: dcl_pid.h:93
#define DCL_getErrorInfo(ptr)
Macro to store error info in CSS.
Definition: dcl_error.h:97
float32_t c1
D path filter coefficient 1, default is 1.
Definition: dcl_pid.h:61
float32_t Ki
Integral gain.
Definition: dcl_pid.h:58
#define DCL_setError(ptr, code)
Macro to set error code in CSS.
Definition: dcl_error.h:79
_DCL_CODE_ACCESS _DCL_CODE_SECTION float32_t DCL_runPIDSeries(DCL_PID *pid, float32_t rk, float32_t yk, float32_t lk)
Executes an ideal form PID controller.
Definition: dcl_pid.h:464
_DCL_CODE_ACCESS void DCL_setActivePIDfilterBW(DCL_PID *pid, float32_t fc, float32_t T)
Loads the PID derivative path filter active coefficients Note: Sampling period pid->css->T are used i...
Definition: dcl_pid.h:295
_DCL_CODE_ACCESS void DCL_loadSeriesPIDasZPK(DCL_PID *pid, DCL_ZPK3 *zpk)
Configures a series PID controller parameter in ZPK form. Note: Sampling period pid->css->T are used ...
Definition: dcl_pid.h:335
float float32_t
Defines single,double precision data type. Note: Assumes ABI to be TI_EABI, does not support legacy T...
Definition: dcl_common.h:54
float32_t d2
D path feedback value (Kd * c1)
Definition: dcl_pid.h:86
float32_t Kd
Derivative gain.
Definition: dcl_pid.h:78
float complex z1
Complex zeros 1.
Definition: dcl_zpk3.h:63
#define DCL_disableInts()
Define enable and disable interrupt operations.
Definition: dcl_common.h:97
float32_t Kr
Set point weight, default is 1.
Definition: dcl_pid.h:60