0% found this document useful (0 votes)
80 views2 pages

PI Controller Header File

This document defines a PI controller structure and macro. The PI controller structure defines the inputs, outputs, parameters and internal variables of a PI controller. It includes fields for the reference setpoint, feedback, controller output, proportional and integral gains, saturation limits, and internal variables to store proportional, integral and saturated output terms. The macro defines the calculations performed by the PI controller on a given structure. It calculates the proportional term from the error, integrates the error to obtain the integral term if the output has not saturated, calculates the unsaturated control output, and saturates the output between the upper and lower limits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views2 pages

PI Controller Header File

This document defines a PI controller structure and macro. The PI controller structure defines the inputs, outputs, parameters and internal variables of a PI controller. It includes fields for the reference setpoint, feedback, controller output, proportional and integral gains, saturation limits, and internal variables to store proportional, integral and saturated output terms. The macro defines the calculations performed by the PI controller on a given structure. It calculates the proportional term from the error, integrates the error to obtain the integral term if the output has not saturated, calculates the unsaturated control output, and saturates the output between the upper and lower limits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

=================================================================================
File name: PI.H
===================================================================================
*/

#ifndef __PI_H__
#define __PI_H__

typedef struct { _iq Ref; // Input: reference set-point


_iq Fbk; // Input: feedback
_iq Out; // Output: controller output
_iq Kp; // Parameter: proportional
loop gain
_iq Ki; // Parameter: integral gain
_iq Umax; // Parameter: upper
saturation limit
_iq Umin; // Parameter: lower
saturation limit
_iq up; // Data: proportional term
_iq ui; // Data: integral term
_iq v1; // Data: pre-saturated
controller output
_iq i1; // Data: integrator storage:
ui(k-1)
_iq w1; // Data: saturation record:
[u(k-1) - v(k-1)]
} PI_CONTROLLER;

/*-----------------------------------------------------------------------------
Default initalisation values for the PI_GRANDO objects
-----------------------------------------------------------------------------*/

#define PI_CONTROLLER_DEFAULTS { \
0, \
0, \
0, \
_IQ(1.0), \
_IQ(0.0), \
_IQ(1.0), \
_IQ(-1.0), \
_IQ(0.0), \
_IQ(0.0), \
_IQ(0.0), \
_IQ(0.0), \
_IQ(1.0) \
}

/*------------------------------------------------------------------------------
PI_GRANDO Macro Definition
------------------------------------------------------------------------------*/

#define PI_MACRO(v)
\
\
/* proportional term */
\
v.up = v.Ref - v.Fbk;
\

\
/* integral term */
\
v.ui = (v.Out == v.v1)?(_IQmpy(v.Ki, v.up)+ v.i1) : v.i1; \
v.i1 = v.ui;
\

\
/* control output */
\
v.v1 = _IQmpy(v.Kp, (v.up + v.ui)); \
v.Out= _IQsat(v.v1, v.Umax, v.Umin); \
//v.w1 = (v.Out == v.v1) ? _IQ(1.0) : _IQ(0.0); \

#endif // __PI_H__

You might also like