Saturday, 27 November 2021

Designing Logic Gates in PLC Simulator


Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edgesHello friends, I hope you all are doing great. In today’s tutorial, we are going to design logic gates in PLC Simulator. It’s our 4th tutorial in Ladder Logic Programming Series. In our previous tutorial, we have Created First Project using Ladder Logic, where we designed a simple logic by using contact and coil. Today, we are going to extend that code and will design different logic gates in ladder logic.

We are discussing these logic gates because they are the main building block of complicated logic. Normally, complex logic is designed using multiple logic gates. So, today, we will simulate all basic logic gates i.e. AND, OR, NOT, NAND, NOR, XOR and XNOR in PLC Simulator. So, let’s get started:

Simulating ANR, OR, and NOT logic

  • The AND, OR, and NOT logic are considered the basic building block logic for designing the complicated logic to decide the output status.
  • By using two switches A and B and one output representing lamp or MOTOR, we can design and program these logics and simulate them on the PLCSIM simulator.
  • Table 1 lists the truth table of the three logic AND, OR, and NOT.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Table 1: Truth table of the AND, OR, NOT logic

Switch A Switch B Motor
AND LOGIC
0 0 0
1 0 0
0 1 0
1 1 1
OR LOGIC
0 0 0
0 1 1
1 0 1
1 1 1
NOT LOGIC
Switch Output
0 1
1 0

 

AND logic in PLC simulator

  • Let us once more enjoy learning further by validating and practicing on the simulator, here you can see in figure 19, on the right the AND logic has been programmed by connecting two switches A and B in series.
  • The motor status is the result of the AND logic between the two switches.
  • On the left, you can see the results of the simulation by setting the status of switches to simulate all truth table conditions and see the motor status changed accordingly.
  • In addition, you can see the truth table of the AND logic on the most right of the figure. So you can review and validate what is going on in the simulator.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 19: Simulating AND logic

 

OR logic in PLC Simulator

  • You can see in figure 20, on the right the OR logic has been established and programmed by connecting two switches A and B in parallel.
  • The motor status is the result of the OR logic between the two switches.
  • On the left, you can see the results of the simulation by setting the status of switches to simulate all truth table conditions of the OR logic and see the motor status charged accordingly.
  • In addition, you can see the truth table on the most right of the figure. So you can review and validate what is going on in the simulator.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 20: Simulating OR logic

Not logic in PLC Simulator

  • Also, the NOT logic is one of the primary logic functions, you can see in figure 21, on the right the NOT logic has been designed and programmed by connecting switches A in negative logic in series with the motor.
  • The motor status is the result of the NOT logic of switch A. On the left, you can see the results of the simulation by setting the status of the switch to simulate the two-state of the NOT logic truth table and see the motor status charged accordingly.
  • In addition, you can see the truth table on the most right of the figure. So you can review and validate what is going on in the simulator.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 21: simulating Not logic

Now! I appreciate your follow-up to our PLC tutorial. I am very happy to feel that, by moving further in our plc tutorial our experience is getting increasing bit by bit. However, some questions may come to our mind like does the operator needs to keep pressing input like the push button to keep the motor running? What happens if he released it, does the motor stop? Well! By asking such questions, I can affirm you start your way to master PLC programming and its logic. And let me say the answer to your questions is yes the operator needs to keep pressing the input push-button until the motor has done its task. But that is not the best practice in the real life. There are other techniques to keep the motor running by one touch of the push button, thanks to latching, setting, and resetting techniques as we will show you in the next sections.

Latching output

  • Figure 22 depicts the latching technique that we simply use to keep the motor running by pressing the input push button and having it keep running even after releasing the button.
  • As you can see, I have used the Output as a Virtual Input and placed it in parallel with actual input.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 22: Latching output

  • Table 2 lists the First three scan cycles to show the sequence of operations and how the latching process works when someone will press the Input.
  • In the first scan cycle, when the input gets HIGH, the plc will scan the input “Run (I0.0)” and will find it pressed/ON and thus will make the output “Motor (Q0.0)” HIGH.
  • In the second scan cycle, the input “Run (I0.0)” turned off after being released, but the motor contact is still ON from the previous scan cycle.
  • So, the compiler won’t change the status of the OUTPUT and we can say it’s latching the output.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Table 2: The first three scan cycles of latching operation

Scan cycle Run (I0.0) Motor status (Q0.0) Motor coil (Q0.0)
1 1 0 1
2 0 1 1
3 0 1 1
  • Now let’s add a way to terminate the latching and stop the motor as per request.
  • Well! Simply figure 23 shows a stop button is added for terminating the latching condition.
  • So in table 2, the RLO for letting the motor running will be unfulfilled by hitting the stop push button in the third scan cycle.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 23: latching with stop button

Simulation of the latching in ladder logic

We may be sure of the logic we wrote for coding the ladder logic of the latching technique. However, at this point how about going to the simulation lab to work out our latch ladder logic program to enjoy validating our ladder code by putting it in the simulator and see how far it match what it is designed for.

Latching Ladder code simulation

  • Now let’s try our latching ladder program in the PLCSIM simulator, by entering our ladder logic and starting the simulator.
  • Figure 24 shows the first four scan cycles. Notice on the left we can set the inputs on and off and see the effects on the right part.
  • In the first scan, every single input and output is at its initial state, so the output is not energized.
  • In the next scan cycle, you can notice we switch on input at I0.0 which is the start push button.
  • Therefore, the motor has been started and running. In the third scan cycle, the start button is switched back off.
  • However, the motor still runs thanks to the latching technique. WOW, we can see our logic is working as we designed for.
  • In the last scan cycle, we tried to test stop latching by hitting the stop pushbutton and indeed it stopped latching and the motor stop running.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 24: simulation result of the first ladder program

We will concentrate on moving forward with ladder coding which is our target. However, we just tried to show you at any time you can validate your ladder at any point to enjoy and confirm you are on the right track as long as you are working on your project.

Latching using set and reset

Let’s use another approach for latching which is based on using set and reset coil. Figure 25 shows the set and reset methods.

  • By hitting set_valve at address I0.2, the valve at Q0.0 will be set ON until a reset command is present by hitting the reset_valve pushbutton at I0.3.
  • It is very easy but you need to take extra care while using set and reset as the last set/reset command will overwrite the previous commands.
  • But wait, what’s if an operator keeps pressing the rest or set button for a long time or if the pushbuttons are the stuck and same thing for the stop button.

Well! The rational expectation is that the motor won’t be able to start. However, the good thing is there is a magic solution to differentiate between the situation of this is a normal stop request by the operator or the button is hold pressed unintentionally or due to an issue with the switches. The one-shot technique can magically recognize the event of pressing or releasing the pushbuttons. Therefore, when it is held for a long time or forever that is only one button press event and for triggering it needs to release and pressed once again. That’s amazing but how does it work? Well! Let’s go demonstrate the concept of how it works, implementation using ladder logic, and give an example to understand it consistently and enjoy the magic of one-shot action.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 25: set and reset for easy latching output

The signal edges

Two edges happened when a pushbutton pressed and released which are falling edge and rising edge as shown in figure 26. It depicts the rising edge when the button is pressed and the falling edge when it has been released. Now, let’s move to ladder logic, there are two equivalent rising and falling edge contacts that can be used to tell the PLC this is a one-shot signal. Figure 27 shows how the use of the rising edge of the reset pushbutton |P| at address I0.3. it shows that despite the reset being pressed, its effect in the moment of pressing and then it needs to be released and pressed again to reset the valve at Q0.1. in the next section, let’s get to business and work out one practical example which represents a real problem in the industry just to harvest the fruit of what we have learned so far.

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 26: The rising and falling edge [2]

Ladder logic contact, Normally open contact, Normally close contact, The coil, Create our very first ladder program, Creating a new project on the TIA portal, Writing the first program on the TIA portal software, Simulating the first ladder logic program, Simulating our first program, Simulating ANR, OR, and NOT logic, AND logic, OR logic, NOT logic, Enjoying simulation of the latching ladder program, Latching output, Latching ladder code simulation, Latching using set and reset, The signal edges

Figure 27: The effects of one-shot technique in ladder logic

So, that was all for today. I hope you have enjoyed today’s lecture. Thanks for reading.

The post Designing Logic Gates in PLC Simulator appeared first on The Engineering Projects.



No comments:

Post a Comment