Example for a C-block (deprecated)

This article contains an example for a C-block created in logi.CAD 3. The C-block calculates parameters for a controller provided by the OSCAT library.

ST-Interface for C-block

See "Creating the interface for a C-block or C++-block (deprecated)" for information how to create an ST-interface.

Example: Content of ST-interface
{extern_c}
FUNCTION_BLOCK CONTROL_SET2
VAR_INPUT
KS : REAL;
TU : REAL;
TG : REAL;
PI : BOOL;
PID : BOOL;
END_VAR
VAR_INPUT CONSTANT
P_K : REAL := 1.0;
PI_K : REAL := 0.9;
PI_TN : REAL := 3.33;
PID_K : REAL := 1.2;
PID_TN : REAL := 2.0;
PID_TV : REAL := 0.5;
END_VAR
VAR_OUTPUT
KP : REAL;
TN : REAL;
TV : REAL;
KI : REAL;
KD : REAL;
END_VAR
END_FUNCTION_BLOCK

Code within the C-block

See "Entering code within the C-block or C++-block (deprecated)" for information on the C-block.

Example: Content of C-block
#ifndef LC_PROT_LCFU___CONTROL_SET2__C
#define LC_PROT_LCFU___CONTROL_SET2__C
 
#include <lcfu___control_set2.h>
 
#define V(VAR) (LC_this->LC_VD_##VAR)
 
void lcfu___CONTROL_SET2(LC_TD_FunctionBlock_CONTROL_SET2* LC_this,
struct _lcoplck_epdb_1_impl* pEPDB)
{
LC_TD_REAL TX;
 
if (V(TU) > 0.0 && V(KS) > 0.0)
{
TX = V(TG) / V(TU) / V(KS);
}
if (V(PI) && V(PID))
{
V(KP) = 0.0;
V(TN) = 0.0;
V(TV) = 0.0;
}
else
{
if (V(PID))
{
V(KP) = V(PID_K) * TX;
V(TN) = V(PID_TN) * V(TU);
V(TV) = V(PID_TV) * V(TU);
}
else
{
if (V(PI))
{
V(KP) = V(PI_K) * TX;
V(TN) = V(PI_TN) * V(TU);
}
else
{
V(KP) = V(P_K) * TX;
}
}
}
 
/* KI and KD are calculated */
if (V(TN) > 0.0)
{
V(KI) = V(KP) / V(TN);
}
else
{
V(KI) = 0.0;
}
V(KD) = V(KP) * V(TV);
}
#endif