FC105 SCALE Function in SCL: Resolving the "Function Type Not Valid or Not Exist" Error
The Siemens FC105 SCALE block is one of the most-used library functions for converting raw 16-bit analog input words (PEW/PIW) into engineering-unit REAL values inside STEP 7 and TIA Portal projects. When the function is invoked from an SCL source, the compiler frequently raises the diagnostic "Function type not valid or not exist" even when the block is present in the program. The root cause is almost always a missing or mis-typed return-value binding, because FC105 is declared as a function (FC) that returns a WORD error code, not a VOID function. This reference walks through the exact call syntax, the underlying scaling math, the bipolar/unipolar behavior, and the complete error-code table so that field engineers can implement FC105 in SCL on the first compile.
1. Overview of the SCALE / UNSCALE Library Pair
The SCALE / UNSCALE pair ships in the Standard Library > TI-S7 Converting Blocks for STEP 7 V5.x and in Libraries > Standard > Converters for TIA Portal V13 and later. The two functions are mirrored:
| Function | Direction | Input Type | Output Type | Return Type | Library Path (STEP 7 V5.x) |
|---|---|---|---|---|---|
| FC105 SCALE | INT/PEW → REAL | INT | REAL | WORD (error code) | Standard Library > TI-S7 Converting Blocks |
| FC106 UNSCALE | REAL → INT/PAW | REAL | INT | WORD (error code) | Standard Library > TI-S7 Converting Blocks |
FC105 scales a raw integer value (typically PEW – peripheral input word from an SM 331/SM 332 analog module) to a floating-point value bounded by LO_LIM and HI_LIM. The return word contains a bit-packed error code that should always be wired to a memory word or RET_VAL variable so the programmer can detect under/over-range conditions at runtime.
For full Siemens documentation see the STEP 7 - Converting Blocks help page and the TIA Portal V18 Standard Library reference.
2. Understanding the "Function Type Not Valid or Not Exist" Error
The SCL compiler reports "Function type not valid or not exist" when the call is syntactically built as if FC105 were a procedure without a return value. In STEP 7 and TIA Portal, an FC falls into one of two declaration categories, and the call-site grammar must match:
-
VOID FC (procedure) – declared with function type VOID. SCL allows the call as a standalone statement with only input parameters. Example:
SET_bit_LED(); - Typed FC (function) – declared with a return type (INT, REAL, WORD, BOOL…). SCL requires the call to be embedded in an expression so the return value is consumed. The call is treated like a function reference; the result must be assigned to a variable, passed into another parameter, or returned from the enclosing FB/FC.
FC105 is declared in the TI-S7 Converting Blocks library with return type WORD, which carries the RET_VAL (return value) error code. SCL therefore enforces that every call bind the return value to a target. Omitting the return-value binding produces the diagnostic:
The fix is not to change the FC; the fix is to correct the call site. Assign the return to a temporary variable, a marker word (e.g., MW0), or an element of a data block.
3. Prerequisites
Before you can compile the SCL source successfully, confirm the following:
-
CPU family: S7-300, S7-400, ET 200S, or S7-1500 with active library support. FC105/FC106 are library FBs and not firmware instructions on S7-1200/1500 (use the
SCALEandNORM_X/SCALE_Xinstructions from the basic instructions palette on those platforms). - STEP 7 / TIA Portal version: STEP 7 V5.4 SP5 or later; TIA Portal V13 SP1 or later. The TI-S7 library is automatically distributed with both.
- Library loaded: Open the project library, navigate to Standard Library > TI-S7 Converting Blocks (or Standard > Converters in TIA Portal), and ensure FC105 is in the program blocks. If it is missing, drag-and-drop from the library into the S7 program / S7-300/400 station.
-
Hardware configuration: The analog input module (e.g., 6ES7 331-7KF02-0AB0 SM 331 AI 8) is configured in HW Config, and the input address (e.g.,
PEW 128) is enabled. - Symbolic names: Open the symbol table and assign names to the DBs and memory words you will use. Symbolic addressing is required for clean SCL.
4. Proper FC105 SCL Call Syntax
The canonical call of FC105 in SCL assigns the return value to a WORD variable. The general form is:
SCALE_return := SCALE(
IN := <INT expression>,
HI_LIM := <REAL expression>,
LO_LIM := <REAL expression>,
BIPOLAR := <BOOL expression>,
OUT => <REAL variable>
);
Note the following grammar points:
- The
OUTparameter is an output, so it uses the=>assignment, not:=. The:=symbol is reserved for input parameters. - The function itself is on the right-hand side of an assignment; the left-hand side captures the
WORDreturn value. - The SCL parser does not accept the procedure-style call (a bare
SCALE(...)statement), because the function returns a non-VOID type.
4.1 Minimal Correct Example
// Pression in 0..5 bar (unipolar 4-20 mA at SM 331, channel 0)
IF first_scan THEN
// Initialize limits once
DB101.HiSensorPresion := 5.0;
DB101.LowSensorPresion := 0.0;
END_IF;
DB1.SimulacionPresion := INT_TO_REAL(0); // placeholder
SymbolTableData := SCALE(
IN := WORD_TO_INT(PEW 128),
HI_LIM := DB101.HiSensorPresion,
LO_LIM := DB101.LowSensorPresion,
BIPOLAR := FALSE,
OUT => DB1.SimulacionPresion
);
The left-hand side SymbolTableData is a WORD variable in the symbol table (e.g., MW 0). The OUT target DB1.SimulacionPresion is a REAL element of data block DB1. The conversion WORD_TO_INT(PEW 128) is required because PEW 128 is a WORD and the SCALE block's IN expects INT.
4.2 Declaring the Return Word
Pick one of the following target options for the return value:
| Target | Declaration | Use Case |
|---|---|---|
| Marker word |
MW 0 in symbol table, type WORD |
Quick commissioning, status only |
| Data block element |
DB100.Scale_Status typed WORD |
Structured data, archive-friendly |
| Local temp |
VAR_TEMP ret : WORD; END_VAR inside the FB |
Encapsulated function block, no global state |
| RET_VAL syntax (legacy) |
RET_VAL := MW0 in older SCL style |
STEP 7 V5.4 projects migrated from LAD/FBD |
5. Data Block Declarations for SCALE Parameters
All three of the user-supplied REAL parameters (HI_LIM, LO_LIM, OUT) must be declared in a data block or local variable area as type REAL (32-bit IEEE-754). The compiler will not perform implicit conversion from INT or DINT; mismatches produce the error "Different data types or types that cannot be implicitly converted".
5.1 Recommended DB Layout (DB101 "ScaleLimits")
DATA_BLOCK DB101
STRUCT
HiSensorPresion : REAL; // upper engineering unit, e.g. 5.0 bar
LowSensorPresion : REAL; // lower engineering unit, e.g. 0.0 bar
Scale_Status : WORD; // optional: capture RET_VAL here
OutValue : REAL; // optional: capture OUT here
END_STRUCT;
END_DATA_BLOCK
If the original error message includes "DB100.Hi" or "DB100.low", verify that the spelling matches the declaration exactly – SCL is case-insensitive, but the typographical error of writing Hi in the code and hi in the declaration will still trip the parser on some TIA Portal versions.
5.2 Local Variable Layout inside an FB
FUNCTION_BLOCK FB7
VAR_TEMP
retValue : WORD; // captures SCALE RET_VAL
Info : WORD; // diagnostic helper
END_VAR
VAR
Pressure : REAL; // engineering unit
END_VAR
BEGIN
retValue := SCALE(
IN := WORD_TO_INT(PEW 128),
HI_LIM := 5.0,
LO_LIM := 0.0,
BIPOLAR := FALSE,
OUT => Pressure
);
// Bit-encode the error to a bool for the calling OB
IF retValue <> 0 THEN
// Handle error
END_IF;
END_FUNCTION_BLOCK
6. Symbol Table Configuration
Symbolic addressing is the cleanest path for SCL. Define the following in the symbol table of the S7 program:
| Symbol | Address | Type | Comment |
|---|---|---|---|
| analog | DB 100 | FB / DB | Analog scaling instance |
| RETVAL1 | MW 0 | WORD | FC105 return value |
| PEW128 | PEW 128 | WORD | Analog input word, channel 0 |
| PRESS_OUT | DB 1.DBD 0 | REAL | Pressure output (bar) |
Best practice is to populate the symbol table before writing SCL. If a referenced symbol is unresolved at compile time, the SCL parser substitutes an implicit warning and sometimes the resulting call degrades to an absolute call that triggers the function-type error if a return is missing.
7. The Underlying Scaling Mathematics
FC105 implements the linear mapping:
Unipolar (BIPOLAR = FALSE, IN range 0..27648):
OUT = ( (FLOAT(IN) - 0) / (27648.0 - 0) ) * (HI_LIM - LO_LIM) + LO_LIM
Bipolar (BIPOLAR = TRUE, IN range -27648..+27648):
OUT = ( (FLOAT(IN) - (-27648)) / (27648.0 - (-27648)) ) * (HI_LIM - LO_LIM) + LO_LIM
Equivalently, bipolar mapping can be written as:
OUT = ( FLOAT(IN) / 27648.0 ) * (HI_LIM - LO_LIM) / 2.0
+ (HI_LIM + LO_LIM) / 2.0
The nominal analog full-scale of Siemens SM 331/SM 332 modules is 0..27648 for unipolar and -27648..+27648 for bipolar. Values above 27648 (e.g., 27649..32767) are over-range; values below 0 (unipolar) are under-range. FC105 sets the corresponding error bits in RET_VAL for both cases.
7.1 Worked Example
Assume a 4-wire 4-20 mA pressure transmitter with a 0-5 bar range, configured for unipolar 0-20 mA at an SM 331. At a current of 12 mA, the raw word is 13824 (mid-scale of 4-20 mA = 12 mA = 16384 because the channel scales 0-20 mA; verify with HW Config). With LO_LIM=0.0, HI_LIM=5.0, BIPOLAR=FALSE:
OUT = (13824 / 27648) * (5.0 - 0.0) + 0.0 = 0.5 * 5.0 = 2.5 bar
This corresponds to 50 % of the 0-20 mA span, or 12 mA, which is half of the 4-20 mA range above 4 mA = 2.5 bar. The match confirms the block is correctly converting to engineering units.
8. Bipolar vs. Unipolar Operation
| Parameter | Unipolar (BIPOLAR=FALSE) | Bipolar (BIPOLAR=TRUE) |
|---|---|---|
| IN range | 0 to 27648 | -27648 to +27648 |
| Typical sensors | 4-20 mA, 0-10 V, RTD | ±10 V, ±20 mA, thermocouple with bias |
| Center code | 0 → LO_LIM, 27648 → HI_LIM | -27648 → LO_LIM, 0 → mid, +27648 → HI_LIM |
| Hardware setting (SM 331) | A / B / C / D range selector on "D" | Range selector on "A" or "B" depending on sensor |
| Return-word bit pattern on overflow | Bit 0 set, bit 3 cleared | Bit 0 set, bit 3 cleared (same pattern) |
On S7-300 analog modules, the measurement range is set by hardware jumpers or via the AI configuration under HW Config ("Measuring mode"). Software cannot override the range; mismatches between HW range and FC105's BIPOLAR flag produce nonsensical outputs and trigger an under-range bit.
9. RET_VAL / Error-Code Reference
The return value is a 16-bit word. Bits are interpreted as:
| Bit | Hex mask | Meaning |
|---|---|---|
| 0 | 0x0001 | Invalid REAL number at OUT (NaN, Inf) |
| 1 | 0x0002 | LO_LIM > HI_LIM |
| 2 | 0x0004 | LO_LIM = HI_LIM (division by zero on scaling) |
| 3 | 0x0008 | OUT lies below LO_LIM (under-range after scaling) |
| 4 | 0x0010 | OUT lies above HI_LIM (over-range after scaling) |
| 5-15 | 0xFFE0 | Reserved (always 0) |
A healthy return value is 16#0000. Any non-zero value should be logged in a diagnostic buffer or raised to a higher-level alarm OB (OB82 / OB121). Always declare the destination word as WORD; do not use INT because the SCL parser will then treat the call as returning INT and fail to match the FC's signature.
10. FC105 vs. FC106 – SCALE and UNSCALE
FC106 UNSCALE is the inverse: it accepts an engineering-unit REAL and produces a raw INT suitable for driving an analog output (e.g., PAW 128). The call signature mirrors FC105:
retValue := UNSCALE(
IN := DB100.SetpointBar, // REAL
HI_LIM := 5.0, // REAL
LO_LIM := 0.0, // REAL
BIPOLAR := FALSE,
OUT => PAW 128 // INT
);
Use FC106 when you need to write a closed-loop setpoint to a 4-20 mA proportional valve or a variable-speed drive reference word. Pairing FC105 and FC106 on the same channel can confirm round-trip accuracy during commissioning.
11. Common Pitfalls and How to Avoid Them
| Symptom | Likely Cause | Fix |
|---|---|---|
| "Function type not valid or not exist" | FC105 called as a statement without return binding | Assign the call to a WORD variable |
| Compile warning: "Different data types" | OUT typed as INT or DINT, not REAL | Change the DB element to REAL (32-bit) |
| Output stuck at 0.0 even with live analog input | PEW address not assigned in HW Config, or wrong slot | Verify the input start address in HW Config matches the call |
| RET_VAL bit 3 set (under-range) | Hardware configured bipolar but BIPOLAR=FALSE, or vice versa | Match BIPOLAR flag to the configured measurement type |
| RET_VAL bit 1 set (LO_LIM > HI_LIM) | Operator entered reversed limits at runtime | Add limit-validation logic before the call |
| RET_VAL bit 2 set (LO_LIM = HI_LIM) | Both limits initialized to 0.0 and not updated | Initialize limits in OB100 (warm restart) or first-scan logic |
| Output drifts with random spikes | PEW read from SM 331 with no hardware filter, or wrong channel group | Check that the address belongs to the correct channel group; enable integration time in HW Config |
12. S7-1200/1500 Alternative – SCALE_X and NORM_X
On S7-1200 and S7-1500, FC105/FC106 are not part of the firmware. Use the basic-instructions SCALE_X and NORM_X blocks from the converter palette. The semantics are identical (linear scaling, bipolar/unipolar), and the blocks also return a BOOL error flag. The SCL call is:
// S7-1500
retValue := SCALE_X(
MIN := 0, // REAL lower bound of engineering range
MAX := 5.0, // REAL upper bound of engineering range
VALUE := NORM_X(MIN := 0, MAX := 27648, VALUE := PEW 128),
RET_VAL => scaleError // BOOL
);
See the TIA Portal V18 Standard Library and the S7-1200/1500 analog-value processing application note for the official guidance.
13. Verification and Commissioning
After the SCL compiles, perform the following steps to verify FC105 operation in the field:
- Online > Monitor / Modify: Force a known PEW value (e.g., 0) by shorting the input or using a calibrator, then watch the OUT REAL value. With LO_LIM=0 and HI_LIM=10, OUT should display 0.0.
- Force 27648: Apply 10 V or 20 mA from a calibrator, and confirm OUT = 10.0 (or the configured HI_LIM).
- Force 13824: Apply 5 V or 12 mA, confirm OUT = 5.0 (mid-scale).
- Force 0 with BIPOLAR=TRUE: Confirm OUT = (HI_LIM + LO_LIM) / 2.0.
- Monitor RET_VAL: Force a value greater than 27648 (e.g., 30000), and confirm bit 4 (0x0010) sets in the return word. The OUT should clamp at HI_LIM.
- Apply a real sensor: Connect the field device and compare the engineering unit with a hand-held reference (HART communicator or multimeter on a parallel shunt).
- Record the diagnostic snapshot: Save the online value of RET_VAL to a log tag, useful for plant-level diagnostics.
14. Putting It All Together – A Production-Ready Function Block
The following FB wraps FC105 with limit validation, error-bit decoding, and a status BOOL. Drop it into your project and call it from OB35 (cyclic interrupt) or OB1 (main).
FUNCTION_BLOCK FB50 "AnalogScale_PEW"
VAR_INPUT
iPEW_Address : INT; // e.g. 128
iLO_LIM : REAL; // engineering unit minimum
iHI_LIM : REAL; // engineering unit maximum
iBIPOLAR : BOOL; // TRUE for bipolar, FALSE for unipolar
END_VAR
VAR_OUTPUT
oOUT_Value : REAL; // scaled engineering value
oUnderRange : BOOL; // below LO_LIM
oOverRange : BOOL; // above HI_LIM
oConfigError : BOOL; // LO_LIM/HI_LIM invalid
oRAW_Invalid : BOOL; // OUT was set to NaN
END_VAR
VAR_TEMP
retVal : WORD;
rawINT : INT;
END_VAR
BEGIN
// Pre-check limits
IF iLO_LIM > iHI_LIM THEN
oConfigError := TRUE;
oOUT_Value := 0.0;
RETURN;
END_IF;
IF iLO_LIM = iHI_LIM THEN
oConfigError := TRUE;
oOUT_Value := 0.0;
RETURN;
END_IF;
rawINT := WORD_TO_INT(WORD#16#0000);
// Indirect PEW read via PEW_INTL pointer emulation:
// For the sake of portability, this example uses a fixed offset.
// Replace with a typed I/O symbol in your project.
rawINT := WORD_TO_INT(PEW[AREA#PI, AREA#I, AREA#Q, iPEW_Address]);
// (Above line simplified - actual syntax depends on STEP7 version)
retVal := SCALE(
IN := rawINT,
HI_LIM := iHI_LIM,
LO_LIM := iLO_LIM,
BIPOLAR := iBIPOLAR,
OUT => oOUT_Value
);
oUnderRange := (retVal AND 16#0008) <> 16#0000;
oOverRange := (retVal AND 16#0010) <> 16#0000;
oRAW_Invalid := (retVal AND 16#0001) <> 16#0000;
oConfigError := (retVal AND 16#0006) <> 16#0000;
END_FUNCTION_BLOCK
This FB keeps the SCL caller clean: only the four inputs are passed, and the engineer can wire a per-channel status into HMI tags without exposing the raw RET_VAL.
15. Frequently Asked Questions
Why does FC105 throw "function type not valid or not exist" in SCL?
FC105 is declared as a function (not a VOID procedure) that returns a WORD error code. SCL grammar requires the call to be embedded in an expression so the return value is consumed. The fix is to assign the call to a WORD variable, e.g. retVal := SCALE(IN := ..., OUT => ...);.
Can I use FC105 on an S7-1200 or S7-1500?
No. FC105/FC106 are library FBs distributed for the S7-300/400/ET 200S line. On S7-1200/1500 use the NORM_X and SCALE_X instructions from the basic-instructions palette, which provide equivalent scaling with BOOL return.
What is the difference between BIPOLAR = TRUE and BIPOLAR = FALSE?
Unipolar (FALSE) maps raw 0..27648 to LO_LIM..HI_LIM. Bipolar (TRUE) maps -27648..+27648 to LO_LIM..HI_LIM with 0 corresponding to the mid-point (LO_LIM + HI_LIM)/2. Hardware configuration of the analog module must match the BIPOLAR flag or under-range bits will be set in RET_VAL.
What does RET_VAL bit 0x0001 mean?
Bit 0 (mask 0x0001) signals an invalid REAL number at the OUT parameter, typically a NaN or Inf result caused by a corrupted DB or division by zero. The block writes 0.0 to OUT in this case. Check the integrity of the target DB and confirm that LO_LIM <> HI_LIM.
How do I capture the return word inside a function block?
Declare a TEMP variable of type WORD (e.g. retVal : WORD;) and assign the call: retVal := SCALE(IN := WORD_TO_INT(PEW 128), HI_LIM := 5.0, LO_LIM := 0.0, BIPOLAR := FALSE, OUT => outVal);. Use bit masks 0x0001/0x0002/0x0004/0x0008/0x0010 to decode the specific error condition.