7-1 Using the toolbar
12) Function Block ( )
Since function block produces output accumulated through many scans, it requires memory to hold the intermediate results during the computation. Consequently, instance variable must declared for function block, similar to variables. Instance variable is the collection of variables, and the most general types of function blocks are timer and counter.
※ The user can creat function block and the created function block is added to the collection of user functions.
(1) Basic Function Block Reference
① Counter
NO Function Block Functions
1 CTU Up Counter
2 CTD Down Counter
3 CTUD Up Down Counter
② Timer
NO Function Block Functions
1 TON On Delay Timer
2 TOF Off Delay Timer
(2) Descriptions of basic function blocks and program usage
A. CTU
Up Counter
Function Description
Input CU: Input condition of Up Counter Pulse R: Reset
PV: Preset Value Output Q: Up Counter Output CV: Current Value
A) Function
(a) When the pulse input CU changes from “0” to “1” (rising edge), the value of CV is incremented by one.
(b) However, CV never exceeds the integer value of 32767.
(c) If the reset input R is set to “1,” CV becomes “0,” that is, it is cleared. (d) Output Q gives “1” if CV is greater than PV.
B) Time Chart
R(Reset Input)
CU(Up Count Input)
CV(Current Value)
Q(Counter Output)
Maximum Coefficient (32767) PV (Preset Value)
C) Program Example
(a) Since CTU is a function block, instance variable must be declared in order to hold the intermediate results.
(b) On declaration of a CTU instance variable in the program, theinstance
name.Qfor counter output Q, and instance name.CVcurrent value are automatically created in this operation.
(c) Choose and select CTU from the windows of function block list.
(d) There is no restriction on the name of the variable, but use C1 for convenience and leave other windows as default values.
(e) If rising edge pulse is introduced through the toggle switch “0”(%IX0.0.0), the current value of input increments.
(f) %QW0.0.2.0 on the right will show the current value as the output.
(g) If the current value exceeds 10, the counter Output (C1.Q) becomes “1” and the lamp (%QX0.3.0) lights up.
(h) If the toggle switch “1”(%IX0.0.1) is turned ON, the current value and the counter output is resetted to become 0, "Zen".
(i) If the current value (C1.CV) goes out of range of between 0 and 9999, the _ERR, _LER flags are turned on by the INT_TO_BCD function.
(j) In the program below, the outputs %QX0.3.0 and %QX0.3.1 perform the same operation.
However, %QX0.3.1 show how the operation of the counter is driven by the value of C1, Q.
◈ LD confirmation using a simulator
B. CTD
Down Counter
Function Description
Input CD: Input condition of Down Counter Pulse
LD: Load Input PV: Preset Value
Output Q: Down Counter Output CV: Current Value
A) Function
(a) When the pulse input CD changes from “0” to “1” (rising edge), the value of CV is decremented by one, where the smallest possible integer value CV is allowed to take is -32768.
(b) If the load input LD is set to “1,” the preset value in PV is loaded into CV. (d) Output Q gives “1” if CV is less than or equal to 0.
B) Time Chart
LD (Load Input)
CD (Down CountI nput) CV (Current Value)
Q (Counter Output) Miinimum
Coefficient (-32768) PV
(Preset Value)
C) Program Example
(a) Since CTD is a function block, instance variable must be declared in order to hold the intermediate results.
(b) On declaration of a CTD instance variable in the program, the variablesinstance name Qfor counter output, andinstance name, CVfor current value are automatically created in this operation.
(c) Declares the instance variable of (CTD (for Example, C2). (d) Preset value is set to 10.
(e) On the initial pressing of %IX0.0.2, LD becomes “1” and PV(preset valve) is loaded to current value.
(f) If rising edge pulse is introduced into CD by the toggle switch “0”(%IX0.0.1), the current value of input is decremented.
(g) If the current value is less than 0, the counter Output (C2.Q) becomes “1” and the lamp (%QX0.3.0) lights up.
(h) If the toggle switch “1”(%IX0.0.2) is turned ON, LD becomes “1” and the preset value is loaded to CV again.
◈ LD confirmation using a simulator
C. CTUD
Up Down Counter
Function Description
Input CU: Up Counter Pulse Input CD: Down Counter Pulse Input R: Reset Input
LD: Load Value PV: Preset Value
Output QU: Up Counter Output QD: Down Counter Output CV: Current Value
A) Function
(a) CTUD is a counter where the current value CV increments by one if the CU goes from “0” to “1” and decrements by one if the CD goes from “0” to “1”, where the current value CV must be between the integer values -32768 and 32767.
(b) If the load input contact LD becomes “1,” the PV is loaded to current value CV. (CV=PV)
(c) If “1” is asserted on the reset input R, the current value CV is cleared to “0”. (CV=0)
(d) Output QU is set to “1” if CV is greater or equal to PV and QD is set to “1” if CV is less than or equal to “0.”
(e) For each input signals, the operation is down in the order R>LD>CU>CD, and if multiple signals are asserted simultaneously, the only the one with the highest priority is processed.
A) Time Chart LD(Load Input) R(Reset Input) CU(Up Count Input) CD(Down Count Input) PV(Preset Value) CV(Current Value) QU(Count Up Output) QD(Count Down Output)
C) Program Example
(a) Since CTUD is a function block, instance variable must be declared in order to hold the intermediate results.
(b) On declaration of a CTUD instance variable in the program, the instance variables automatically created:(instance name).QUfor the up count,(instance name). QDfor down count, and(instance name).CVfor current value.
(c) Declares the instance variable of CTD(for Example, C3). (d) Preset value is set to 10.
(e) If rising edge pulse is introduced into CU using the toggle switch %IX0.0.0, the current value of input is increased.
(f) If rising edge pulse is introduced into CD using the toggle switch %IX0.0.1, the current value of input is decremented.
(g) If the current value is greater than or equal to PV(preset value), C3, QU be comes “1” and %QX0.3.0 is set to “1.”
(h) If the current value is less than or equal to “0,” C3, QD becomes “1.” (i) If %IX0.0.2 is set to ON, the current value is cleared to “0.”
(j) If %IX0.0.3 is set to ON, LD becomes “1” and the preset value is loaded into the current value.
D. TON (ON Delay Timer)
Function Description
Input IN: Timer Activation Condition PT: Preset Time
Output Q: Timer Output ET: Elapsed Time
A) Function
(a) The time elapsed after IN became “1” is output to ET.
(b) If IN becomes before the ET reaches the preset time, ET is set to “0.” (c) If IN becomes “0” after Q becomes “1,” Q is set to “0.”
B) Time Chart IN Q ET PT Preset Time C) Program Example
(a) Since TON is a function block, instance variable must be declared in order to hold the intermediate results.
(b) On declaration of a TON instance variable in a program, variables are automati cally created:(instance name).Q, for the timer output and(instance name). ETfor elapsed time.
(c) Declare a instance variable for TON, for example named T1. (d) Set the PT preset timer for T1 as 5 seconds (T#5S).
(e) If the activation switch %IX0.0.0 is turned ON, the elapsed time (T1.ET) is displayed on the digital indicator.
(f) If the elapsed time T1.ET reaches 5 seconds, the timer output T1.Q becomes ON, making the outputs %Q0.2.0 "1" and %Q0.2.1 “0.”
(g) After switching T1.Q ON, switching OFF the activation switch (%IX0.0.0) makes T1.Q OFF.
E. TOF (OFF Delay Timer)
Function Description
Input IN: Timer Activation Condition PT: Preset Time
Output Q: Timer Output ET: Elapsed Time
A) Function
(a) Asserting “1” for IN sets Q to “1” and the time elapsed since IN becoming “0” exceeds the time set in PT, Q becomes “0.”
(b) The time elapsed since IN becoming “0” is output to ET.
(c) If IN becomes “1” before ET reaches the preset time, elapsed time is reset to “0.”
B) Time Chart IN Q ET Preset Time PT
C) Program Example
(a) Since TOF is a function block, instance variable must be declared in order to hold the intermediate results.
(b) On declaration of a TON instance variable in a program, variables are automati cally created:(instance name).Q, for timer output and(instance name).ETfor elapsed time.
(c) Declare a TOF instance variable, for example named T2. (d) Set the timer T2 to 3 seconds (T#3S).
(e) Setting the activation switch %IX0.0.0 to ON makes the timer output T2.Q to become ON.
(f) Setting the activation switch %IX0.0.0 to OFF causes the elapsed time T2.ET to be displayed on the digital indicator.
(g) If the elapse time T2.ET reaches the preset time of 3 seconds, timer output T2.Q becomes OFF.
F. TP (Pulse Timer)
Function Description
Input IN: Timer Activation Condition PT: Preset Time
Output Q: Timer Output ET: Elapsed Time
A) Function
(a) Asserting “1” for IN sets Q to “1” for the preset amount of time and goes back to “0” when ET reaches PT.
(b) Elapsed time ET starts increment when IN becomes “1” and remains still once it reaches PT until it is reset to “0” as IN becomes “0.”
(c) Even if IN changes to “0” and back to “1,” it will have no effect while ET is being incremented. B) Time Chart IN Q ET PT Preset Time PT C) Program Example
(a) Since TP is a function block, instance variable must be declared in order to hold the intermediate results.
(b) On declaration of a TP instance variable in a program, variables are automatically created:(instance name).Q, for the timer output and(instance name).ETfor elapsed time.
(c) Declare a TP instance variable for example named T3. (d) Set the timer T3 to 3 seconds (T#3S).
(e) Setting the activation switch %IX0.0.0 to ON makes the timer output T3.Q to become ON and stays that way for 3 seconds.
(f) Setting the activation switch to OFF has no effect while T3.ET is increasing. (g) Timer output T3.Q becomes OFF after 3 seconds.
D) Program Example
13) Return ( )
[Return] is the command to terminate execution if encountered during the execution, effectively blocking the execution of any statements to follow. (Shortcut key + )
(1) Function Description
※ USE UOUSE
① Choose from the toolbar.
② Move the mouse cursor to the desired position in the LD program window and left click.
※ USE KEY BOARD
③ Move the cursor to the location to return in the LD Program. ④ Choose Return from Toolbar in the menu (Shift-F7).
(2) Programming Application
As shown below, execution will continue up to the [Return] mark on the second row. Since encountering [Return] while executing terminates the execution, the statement in row 2 is not executed.
14) Branch (JUMP) ( )
Jump is a way to go to the desired (labeled) location for branching in an LD program. Destination is represented by a label. The jump in the main program must be provided a label within main program as a input, and the jump in the subroutine do- main can only branch to labels within the subroutine.
※ Program Example
① Choose from the toolbar.
② Move the mouse cursor to the desired position in the LD program window and left click.
15) Subroutine (CALL) ( )
In LD program, the execution is terminated on encountering an END command. However, there are cases when some program which exist after the END command must be evoked, in which case the subroutine can be convenient.
※ Program Example
(1) Subroutine
① Choose from the toolbar.
② Move the mouse cursor to the desired position in the LD program window and left click.
③ Choose and double-click the created subroutine LD and enter “ABC” as the label name.
(2) END Command
① Place the cursor at the last row of the program or desired row, for example row 2) and double-click.
② In the Label / Rung Description / End of Main Program dialog box, select “Show the end of the main program.”
(3) Label
① Place the cursor at the location to be called after the END command and double-click.
② Choose the label in the Label / Rung Description / End of Main Program dialog box.
③ Name the label as “ABC” in the Add Label dialog. (Maximum label length: 16 characters)
Switch Input Arithmetic Result (Assumption) Normally Open Contact Coil Normally
Closed Contact Reverse Coil
Positive Transition Detection Contact Positive Transition Detection Coil 1 scan 1 scan Negative Transition Detection Contact Negative Transition Detection Coil 1 scan 1 scan
Input/Output Time Chart of Operations (4) Program Description
The circuit shows how even if the contact of %I0.1.1 and %I0.1.2 activates, %Q0.2.0 can stay not active. This is because the call to the subroutine is located after the END command and so the call does not occur.
In this circuit, if the %I0.0.1 contact activates, ABC is called by the subroutine, and after %I0.1.1 and %I0.1.2 contact activates, the output %Q0.2.0 becomes active.