Applies To:
  • CitectSCADA 3.x 4.x 5.x 6.x 7.x

Summary:
How can you manually scale a value from one set of units to another, for example, from Celsius to Farenheit?

How do you fix the v7 compile error:

Field: RAW_ZERO or RAW_FULL
Error: Invalid Number
Context: Value out of range for a given type

Solution:

The simplest way to scale a value is to use the built-in scaling in the variable tag's definition. This requires entering a raw zero, engineering zero, raw full, and engineering full value. The raw range refers to the value read from/written to the physical or disk device. The engineering range is the corresponding range of values that will be displayed in CitectSCADA. For example, if a PLC has a temperature in Celsius but it needs to be displayed in Farenheit, set the raw range to 0 to 100 and the engineering range to 32 to 212. This also restricts users to entering values between 32 and 112 degrees F. If a larger engineering range is needed, the raw range would need to be adjusted to match.

It is possible to display a value using two or more scales by defining more than one tag with the same I/O Device and Address. For example, a temperature sensor value may be stored as -4096 to 4095. If that represented 32 to 212 degrees F, create one tag with raw range -4096 to 4095 and an engineering range of 32 to 212. Create another tag for Celsius with raw range -4096 to 4095 and engineering range 0 to 100.

The scaled value could also be calculated in Cicode. This may be useful if the scale may change, such as a sensor that needs to be calibrated regularly, or if the minimum and maximum allowed values may change.

The basic formula to calculate engineering values is

Y = (M * X) + B

X is the input (raw) value.
Y is the output (engineering) value.
M is the scale factor.
B is the offset.

M = (Y2 - Y1) / (X2 - X1)
B = Y1 - (X1 * M)

X1 is the input minimum (raw zero).
X2 is the input maximum (raw full).
Y1 is the output minimum (engineering zero).
Y2 is the output maximum (engineering full).

For the above example of converting Celsius to Farenheit, use the following values:

X1 = 0
X2 = 100
Y1 = 32
Y2 = 212

Use those values to calculate M and B:

M = 1.8
B = 32

To convert any Celsius value to Farenheit, multiply the Celsius value by 1.8 and add 32. For example 37 C. would convert to 98.6 F, (37 * 1.8) + 32

To convert the opposite direction, swap X1 with Y1 and X2 with Y2 and recalculate the scale and offset (M and B). Or, use the original scale and offset, but subtract the offset then divide by the scale factor. For example (98.6 - 32) / 1.8 = 37.

If you want to keep the same scale factor but change the range of values an operator may enter for a tag, calculate the scale factor and offset, then use them to calculate the new min and max values. This can be helpful when upgrading to Citect v7 where integer tag scales are no longer allowed to exceed the limits of an integer (-32768 to 32767). For example, in version 6, a tag's raw scale was -100000 to 100000 and the engineering scale was -100 to 100. The scale factor is 0.001 with an offset of 0. In version 7, the raw scale of an integer cannot exceed -32768 to 32767. The engineering zero scale would then become -32.768 ((-32768 * 0.001) + 0) and engineering full would be 32.767. The attached Excel spreadsheet makes these calculations simpler for integer tags causing compile errors. Just enter the raw and engineering values from the v6 project and it calculates the scale and offset, and shows the adjusted engineering values to use so the tag doesn't exceed the range of an integer tag.


Keywords: