example - Celsius To Fahrenheit function in ST (TC3)
Learn more at Part 5 - Structures & functions (IEC 61131-3)
This function converts a temperature value in Celsius and returns its equivalent in Fahrenheit.
Copy the PLC Code:
FUNCTION Celsius_To_Fahrenheit : REAL
VAR_INPUT
fCelsius : Real;
END_VAR
VAR
END_VAR
----------------------------------------------------------------------
Celsius_ToFahrenheit := fCelsius * 1.8 + 32.0;
PROGRAM MAIN
VAR
fFahrenheit : REAL;
END_VAR
-----------------------------------------------------------------------
fFahrenheit := Celsius_To_Fahrenheit(fCelsius := 5.0);
How to create a Function
To create a function, right-click on POUs, select Add, Select POU.
Write the name of the function and fill in the data type of the return value. Make sure that structured text is selected.
This will create a shell for your function and now you can fill in the implementation.