The following example adds two values of the data type TIME and assigns the result to an output variable. Unlike other editors, ST always begins with the output variable.
- Declare all variables in the POU header
- Click into the programming window
- <Backspace> to delete the semicolon
This example uses templates and other shortcuts. A semicolon will automatically be added at the end of the instruction. If you prefer to type in commands and variables directly, start writing at the left-hand side of the semicolon and do not delete it.
- Press <F2>
The Variables pane is opened.
The list only contains the variables you have declared in the POU header. You can declare and assign new variables directly in the POU body. See Assigning operands for details.
- Use the sorting and filter settings to expedite programming
- Select time_value_3
- Double-click selected variable or select Insert variable from the context menu
- Enter the assignment instruction
:=
This instruction will assign a new value to the output variable.
- Press <Shift>+<F2> or to open the Instructions pane
- Enter ADD_TIME into the text search field
- Double-click the selected element or select Insert instruction from the context menu
The ADD_TIME template is inserted:
ADD_TIME( ?Time1_TIME? , ?Time2_TIME? );
- Double-click
?Time1_TIME?
- Press <F2>
The Variables pane is opened.
- Set location filter to <Header> to display the variables declared in the POU header only
- Double-click time_value_1
The variable is inserted instead of the placeholder.
- Double-click
?Time2_TIME?
in the programming window
- Double-click time_value_2 in the Variables pane
The command line should now look like this:
time_value_3:=ADD_TIME(time_value_1, time_value_2);
- Check the program
- Download the program to the PLC
- Change to RUN mode to start the program
While monitoring is active you can see the result of adding time_value_1 and time_value_2 stored in time_value_3.