Open Controller Organizer and expand the leaf Tasks | Main Tasks | Main Program. Right-click on Main Program and select New Routine as shown in the following screenshot:
Configure a new Ladder Logic program by setting the following values:
For our newly created routine to be executed with each scan of the PLC, we will need to add a reference to it in MainRoutine that is executed with each scan of the MainTask task.
Double-click on our MainRoutine program to display the Ladder Logic contained within it.
Next, we will add a Jump To Subroutine (JSR) element that will add our newly added Ladder Diagram program to the main task and ensure that it is executed with each scan.
Above the Ladder Diagram, there are tab buttons that organize Ladder Elements into Element Groups. Click on the left and right arrows that are on the left side of Element Groups and find the one labeled Program Control. After clicking on the Program Control element group, you will see the JSR element. Click on the JSR element to add it to the current Ladder Logic Rung in MainRoutine.
Next, we will make some modifications to the JSR routine so that it calls our newly added Ladder Diagram. Click on the Routine Name parameter of the JSR element and select the VALVES routine from the list as shown in the following screenshot:
There are three additional parameters that we are not using as part of the JSR element, which can be removed. Select the Input Par parameter and then click on the Remove Parameter icon in the toolbar above the Ladder Diagram. This icon looks as shown in the following screenshot:
Repeat this process for the other optional parameter: Return Par.
Now that we have ensured that our newly added Ladder Logic routine will be scanned, we can add the elements to our Ladder Logic routine. Double-click on our VALVES routine in the Controller Organizer tab under the MainTask task.
Find the Timer/Counter element group and click on the TON (Timer On Delay) element to add it to our Ladder Diagram.
Now we will create the Timer object. Enter the name in the Timer field as FC1001_TON
. Right-click on the TIMER object tag name we just entered and select New "FC1001_TON" (or press Ctrl + W).
In the New Tag form that appears, enter in the description FAULT TIMER FOR FLOW CONTROL VALVE 1001
and click on OK to create the new TIMER tag.
Next, we will configure our TON element to count to five seconds (5,000 milliseconds). Double-click on the Preset parameter and enter in the value 5000
, which is in milliseconds.
Now, we will need to add the condition that will start the TIMER object. We will be adding a Less Than (LES) element from the Compare element group. Be sure to add the element to the same Ladder Logic Rung as the Timer on Delay element.
The LES element will compare the valve position with the valve set point and return true
if the values do not match. So set the two parameters of the LES element to the following:
Now, we will add a second Ladder Logic Rung where a latched fault alarm is triggered after TIMER reaches five seconds.
Right-click under the first Ladder Logic Rung and select Add Rung (or press Ctrl + R).
Find the Favorites element group and select the Examine On icon as shown in the following screenshot:
Click on ? above the Examine On tab and select the TIMER object's Done property, FC1001_TON.DN, as shown in the following screenshot. Now, once the valve values are not equal, and the TIMER has completed its count to five seconds, this Ladder Logic Rung will be activated as shown in the following screenshot:
Next, we will add an Output Latched element to this Ladder Logic Rung. Click on the Output Latched element from the Favorites element group with our new rung selected.
Click on ? above the Output Latched element and type in the name of a new base tag we are going to add as FC1001_FLT
. Press Enter or click on the element to complete the text entry.
Right-click on FC1001_FLT and select New "FC1001_FLT" (or press Ctrl + W).
Set the following values in the New Tag form that appears:
Click on OK to add the new tag. Our new tag will look like the following screenshot:
It is considered bad practice to latch a bit without having the code to unlatch the bit directly below it. Create a new BOOL type tag called ALARM_RESET
with the following properties:
Click on OK to add the new tag. Then add the following coil and OTU to unlatch the fault when the master alarm reset is triggered.
Finally, we will add a comment so that we can see what our Ladder Diagram is doing at a glance.
Right-click in the far-right area of the first Ladder Logic Rung (where the 0 is) and select Edit Rung Comment (Ctrl + D).
Enter the following helpful comment: