We need to initiate Step 1. Before we do that, thought, we need to add another permissive bit. We will call that bit “System Ready”.
We know that if the system is enabled but not currently batching, it is ready to begin a batch. We need insert a new rung and create a “System Batching” and “System Ready”
bit.
Insert a new rung and program it as shown in Rung 0002.
You can see how Rung 0002 should look in the picture below. The “System Ready” bit will be on when the system is enabled, but not batching.
To actually initiate the batch and hold the batch in Step 1, we are going to use the Output Latch (OTL) instruction. This instruction works in conjunction with the Output Unlatch (OTU) instruction. The instructions will work on the same bit address, but are typically found on different rungs.
The batch will be started when the operator pushes the Start Batch button. We will latch that bit and label it Step 1.
As a side note, I am going to skip a few addresses in the B3 file. It is always a good idea to leave a gap here and there in the event that you need to add a bit later. It doesn’t affect the operation of the program, but it makes the data files more organized and easier to troubleshoot.
Insert a new rung at the bottom of the ladder. We need an XIC for the System Ready bit and an XIC for the Start Batch pushbutton at the beginning of the new rung.
Click and drag the XIC (examine if closed) tool button from the User menu to the left side of the new branch. Type in the address B3:0/2 and press enter.
To save some typing, you can copy and paste instructions. Highlight the Start Batch instruction in Rung 0002.
Press CTRL-C.
Click on the rung number for Rung 0004.
Press CTRL-V. The instruction is duplicated on Rung 0003. Copy and paste bit in the same way
Click and drag the OTL (output latch) tool button from the User menu to the right side of the new branch. Type in the address B3:0/10 and add the descriptor “Batch Step 1”.
However, what if the button is pressed if the system is already batching and in another step? To prevent that from happening, we will make sure that the only way the system can enter Step 1 is if it is not in another step already. Add a series of XIO instructions.
Address them from B3:0/11 to B3:0/14. Type in the appropriate descriptors. Verify the rung.
You can see how RSLogix handles rungs that are too long to be displayed on one side.
You can compensate for this by maximizing the LAD 2 window, or stretching it to the left. Remember that if you want to return to the default view, choose Window > Arrange >
Default Project.
You may wonder why we chose not to use the OTL output latch instruction in Rung 0001. Many times, it is a matter of personal choice; sometimes a “traditional” latch rung is better than using an OTL. In Rung 0001, we were able to keep all the logic affecting the System Batching bit on one rung. This makes it easier to read and a little more condensed. Some people view a traditional latch as a bit safer. It’s your call, though.
Analog Inputs
Before we continue with Step 1, we need to program the Mixing Tank Scales and the Ultrasonic Level Sensor. Since the logic associated with these devices is not necessary tied to Step 1, but common to the entire program, let’s put them in a sub-routine.
We do this by right-clicking on “Program Files” in the Project menu on the left and choosing “New”. The Name is limited to 11 characters, so we will call it ANALOG. The description will be “Mixing Tank Scales and Level Sensor”. Click OK.
That reminds us that we did not name LAD 2. Let’s do that right now. Right-click on LAD 2 and choose Rename. We will call it MAIN.
LAD 2 is, by default, the program that will run when the SLC is first powered up. Like subroutines in other programs like Visual Basic or C, we need to tell the main program to execute the sub-routine.
We need to put a JSR (jump to subroutine) instruction in LAD 2. In this case, it really doesn’t matter where it is placed, but putting it at the top makes sense.
Insert a rung at the top of the ladder. In the Instruction menu, click on the right arrow until the “Program Control” tab is shown. Click on the tab.
Drag the Jump to Subroutine (JSR) tool button to your new rung. Type in a “3” to tell the instruction to go to LAD 3.
Add the descriptor “Mixing Tank Scales and Level Sensor”. Verify the rung.
In the Project menu, double-click on LAD 3 – ANALOG. This opens the new ladder file you just created. Insert a new rung.
We are going to enter an instruction in a new way. Double-click on 0000 for Rung 0000.
This opens up the ASCII editor.
Type SCP in the box and press enter. SCP stands for “Scale with Parameters”. It allows you to take an analog input from a sensor and scale it to the output units you want.
Before we start scaling, let’s take a moment to see how the Allen-Bradley NI4 converts a 0-10VDC signal to a number. The NI4 is an analog-to-digital processor that takes the 0-10VDC signal and converts it to a number between 0 and 16384.
The NI4 will yield a number from 0 to 16384 that is directly proportional to the 0 to 10VDC signal that is applied at the input.
In other words, zero volts on the input of the NI4 means that the NI4 will provide 0 as a value to the PLC. Ten volts on the input will yield 16384. Five volts on the input will yield half of 16384, or 8192, and so on.
The SCP instruction starts out looking like this.
Each of the six parameters (Input, Input Min., Input Max., Scaled Min., Scaled Max. and Output) has two fields associated with them. Each field is currently filled with a question mark. The first field is a value that you assign. The second field is the actual value returned by the processor.
Setting up an SCP to calculate Tank Weight
The Input parameter is the value that will be scaled. Let’s use this SCP instruction for the Scales. The input we will use is the address we assigned to the analog input card;
that is, I:1.0.
The Input Min parameter is the value that is read by the analog card when there is no liquid in the tank. With our scales, this value is 0.
The Input Max is the value that is read by the card when the tank is full. Our Mixing tank weighs 2000 lbs. when it is full of liquid. We measured the voltage that the Scale put out when the tank was full and found it to be 10 volts.
So, in this case, 2000 lbs. in the tank equals 10 volts, which means the NI4 will read out 16384 when the tank has 2000 lbs. of liquid in it.
The Scaled Min parameter is the lowest value you want the SCP to calculate in the units you want. In this case, it is 0, and we are using pounds as our units.
The Scaled Max parameter is the highest value you want the SCP to calculate. For the Scales in our project, it is 2000.
The Output parameter is typically an address where you want to store the result of the SCP. We are going to put it in the N7 file (integer). We will store it specifically in N7:0.
Here is how the SCP instruction for our Scales looks.
Admittedly, the numbers rarely work out like this, but for simplicity’s sake, I made them easy to work with.
The real beauty of the SCP is apparent after you go online. Let’s say that you couldn’t really calibrate the scales previously by using voltmeter.
After you go online, and you are getting live data from the SCP instruction, you can visually verify that the tank is empty.
Hoverer, you are reading 133 from the NI4. You simply enter 133 as the Input Min parameter.
When the tank is full, you see that the reading is 14733. Enter 14733 as the Input Max parameter and the SCP will calculate the rest for you.
The important thing to remember is that the value in N7:0 is the actual weight of the tank in pounds. We will use that when we program the setpoint logic.
Setting Up An SCP To Calculate Tank Level
First, let’s insert a new rung and create an SCP the same way we did the first time.
This time, the Input will be I:1.1 The Input Min will be 0.
The Input Max will be 16384.
The Scaled Min is 0.
The Scaled Max is 100. We want to read the level of the tank as a percent of full.
The Output is stored in N7:1, with the descriptor “Liquid Level of Mixing Tank (%)”.
It looks like this.
There is one more rung we need to add to this ladder file. Do you remember the JSR instruction we used to get the program here? We have to tell it to go back.
Insert a new rung and the RET (return) instruction.
Back to Batching – Step 1
Click on the “Main” tab at the bottom on the Ladder window to return to the LAD 2 – MAIN file.
Now that we have our Scales working, we can add some water.
Insert a new rung at the bottom of the ladder.
We will open the city water valve in this rung, so we want to make sure that it is still safe and desirable to open the valve. That is, make sure that there are no faults, the E-Stop button has not been pressed and the Stop Batch pushbutton has not been pressed.
Using an XIC with the System Batching bit will confirm all of that. Insert an XIC with the address B3:0/2.
Since we only want to open this valve and add city water in Step 1, insert an XIC with the address B3:0/10.
Insert an OTE for the city water valve (O:5/1).
Remember that we want to put 1275 lbs. of water in the Mixing Tank. We will use the LEQ (Less than or Equal To) instruction to accomplish that.
Select the “Compare” tab on the instruction tool menu. Click and drag the LEQ tool button to the marker just to the left of the OTE.
Source A in the instruction is the Tank Weight, which is N7:0. Enter that address.
Source B is our setpoint, which as you recall from the Project Scope is 1275 lbs. Enter 1275 for Source B.
The LEQ instruction will remain true as long as the tank weight does not exceed 1275 lbs.
After the correct amount of city water has been added, we need to proceed to Step 2.
We will make use of the fact that we know the system is currently in Step 1, but the Mixing Tank has enough water (1275 lbs) to go to the next step.
We will use the OTU (Output Unlatch) instruction to turn off the bit we latched in Rung 0004.
Rung 0006 works like this:
The XIC instruction B3:0/10 Batch Step 1 is on. The Mixing Tank weight has reached the setpoint of 1275, so the GEQ (Greater Than or Equal To) instruction is also true. As a result, the bit B3:0/10 Batch Step 1 is unlatched (turned off) and B3:0/11 Batch Step 2 is latched (turned on).