Applies To:
  • CitectSCADA 1.00 1.01 1.10 1.11 1.20 2.00 2.01

Summary:
If you try to trend a Cicode expression or a digital tag, Citect will set the trend scale to 0 - 32000. This is because Citect would normally get the scaling from the tag definition (in the VARIABLE.DBF database), but digitals and simple Cicode expressions do not have a scale. (Also if an expression returns a Real value, this value may get rounded.) 

Solution:
The following example illustrates how you can trend an expression. The example uses a REAL value with a scale of 0 to 4.

First, define a real tag to use for scaling as follows.

Variable Tag Name : REALTAG
Data Type : REAL
Unit Name : PLC_1
Address : V496
Raw Zero Scale : 0
Raw Full Scale : 4
Eng Zero Scale : 0
Eng Full Scale : 4

Note : the above tag will use two words, ie V496 and V497. (In this example, the PLC type is TIWAY.)

Next, write a Cicode function for the expression as follows. The return type is a REAL (You can use INT if required.):

REAL
FUNCTION

TrendReal(Real temp)
/* the temp variable would not normally be used, scaling only */
REAL value; /* real, to temporally store expression result */
value = Sqrt(9.5); /* your expression */
RETURN value; /* function return, real value */

END

Third, define a Trend Tag as follows:

Trend Tag Name : TRENDTAG1
Expression : TrendReal(REALTAG)
Sample Period : 2
File Name : [Data]:TREND1

(You can use the format and other fields if required.)

When Citect finds a variable tag name in the expression field, it will use the scaling of this tag to scale the trend. This is the only use for the tag. If you need to trend several expressions, you can use the same variable tag for the scaling, providing the scale is the same.

The following example trends a digital variable

Digitals in Citect do not have scales. If a digital is trended, the scale would be set to 0 - 32000 and it would need to be rescaled at runtime. If you use an INT type tag in the trend expression field, Citect can then use the scale of this tag for the trend. A 2 - 2 scale is a suitable scale to use.

First, define the Digital Tag as normal, and an Integer Tag as follows:

Variable Tag Name : DIGITALSCALE
Data Type : INT
Unit Name : PLC_1
Address : V498
Raw Zero Scale : -2
Raw Full Scale : 2
Eng Zero Scale : -2
Eng Full Scale : 2

Next, write a Cicode function (that will be used in the Trend expression field) as follows.

INT
FUNCTION

TrendDigital(INT scalevar, INT trendedvar)
/* scalevar is not used in the function */
RETURN trendedvar; /* function return, digital value */

END

Third, define a Trend Tag as follows:

Trend Tag Name : TRENDTAG2
Expression : TrendDigital(DIGITALSCALE, BIT_1)
Sample Period : 2
File Name : [Data]:TREND2
Format : #

(You can use the format and other fields if required.)

BIT_1 is the digital to be trended. The value of the digital is simply passed to the function and returned without any manipulation. When Citect finds the first variable tag name in the expression field (DIGITALSCALE), it will use the scaling of this tag, to scale the trend. This is the only use for the tag.

 

Keywords:
 

Attachments