Sunday, April 7, 2013




  1. Learn the fundamentals of PLC operations.
  2. Learn how to create a program for custom applications.
I. Basic PLC Fundamentals
System Components

All Programmable Logic Controllers (PLC) consist of nearly the same components regardless of the manufacturer or platform. Common components generally consist of:

  1. Processor- The component responsible for containing and executing the program or code. It contains the memory (volatile, non-volatile or a combination of both), the program processor and one or more communication ports (Com Port or Fieldbus Connection) that allow the user to connect, download and monitor a program and allow communication to other components connected to a network.
  2. Physical I/O- Input and Output modules that allow “real world” information to be made available to the Processor. The physical I/O can obtain and output both discrete data such as from switches, etc. and analog or numerical data such as from flow, pressure and temperature instruments, potentiometers, etc. There are also specialty modules that can obtain other types of information such as from encoders and high speed pulse devices.
  3. Power Supply- Generally, a PLC will need a 24V DC source to operate. A 24V DC power supply can be either a rack mounted or remote mounted device. Wago PLC systems require a remote mounted supply.
  4. Figure 1-1 below is an example of a typical Wago PLC arrangement.     
Figure 1-1
Basic Theory of Operation     

            We first must understand the various memory areas involved. There is “Input Image”, “Output Image” and “Internal Memory” areas. Some manufacturers may subdivide the internal memory into more than one area. For the Wago platform, the following designations apply:

            %I-      Input Image

            %M-    Internal or “Flag” memory

            %Q-     Output Image

            It is also important to understand the various “Data Types” commonly used. A “Data Type” simply means the type of information that will be stored and how much memory space will be required to store it. For the Wago platform, the following designations apply:

            BOOL-            A single bit value ranging from 0 to 1.

            BYTE-                        An 8 bit value ranging from 0 to 255

            WORD-          A 16 bit unsigned value ranging 0 to 65535.

INT-                A 16 bit signed value consisting of a 15 bit value plus a sign bit ranging from -32767 to +32767.

DWORD-       A 32 bit value consisting of two 16 bit registers ranging from 0 to 4294967295.

DINT-             A 32 bit value consisting of two 16 bit registers containing a 31 bit value plus a sign bit ranging from -2147483648 to 2147483648.

REAL-            Also know as a “Floating Point” number. A 32 bit value (double word) containing a value and an exponent ranging from 1.175494351e-38 to 1.175494351e+38

How memory is accessed needs to be understood as well. Basically, memory can be accessed as 1 (bit), 8 (byte), 16 (word or integer) or 32 (double word or real) bits at a time. The following are typical memory addressing examples for the Wago platform:


%MW100                                                        %IX10.4

%M- Internal Memory Area                           %I- Input Image Area

W- Word (16 bits)                                           X- Boolean (1 bit)

100- Register Word Address                          10- Register Word Address

                                                                        .4- Bit Location of the Word Address

We can assign names to portions of data in memory. These are referred to as “variable names” or simply “variables”. Each variable name must be unique. There are basically two types of variables, “Local” and “Global”. Local variables are created and generally used only within the POU that they are created and defined in. Global variables are created in a separate variable table and can be used throughout the program. The following is an example of how a variable is defined;


MyVariable AT %MW100 : WORD;

MyVariable- Name of the variable

 %MW100- Memory Location

WORD- A 16 bit unsigned value ranging 0 to 65535.

The last important part to understand about memory is how the I/O is addressed. First, the word addresses are counted and then bit addresses. This is true for both inputs and outputs. Below is an example of how the inputs are addresses by the bus coupler:

Figure 1-2

 There are several operations carried out within the processor other than simply the executing of the computations as defined by the user program. These operations are carried out in an “order of execution” or predefined steps set forth by the firmware. Understanding the order of execution is important when writing a program because certain events precede others.

            In a Wago processor, the first operation is to read any forces that exist into the memory area(s) chosen.  Next, the physical input statuses, both bit and analog, are loaded, or read into, the Input Image table. The program is executed and any results are loaded into the internal memory and the Output Image. The last step is to move, or output, the Output Image to the physical outputs. Notice that the forces are read first and then the Input Image is read and then the code is executed, this is why sometimes it seems that some forces have no effect in various parts of the program.

            A program is divided into individual tasks or collections of similar tasks and stored in individual POU’s or Program Organizational Units. Once a POU is created and the program instructions are entered into the POU, a “call” or a command to execute the POU’s instructions must be entered into the main cyclical POU called PLC_PRG. The PLC_PRG is the only POU that will automatically execute and every program must have a POU named PLC_PRG.

CoDeSys programming software.

            CoDeSys is the programming software used for the Wago platform. The software supports several programming languages. The two most commonly used languages used within M&I’s software packages are Ladder Logic and Structured Text.

Ladder Logic is the most commonly used across many other manufactures as well since it very closely mimics relay logic that many people can easily understand. The main limitation with Ladder Logic is that mathematical processes become visually complex on the screen of the programming device.

Structured Text somewhat mimics the Basic programming language. It supports complex math easily however bit logic becomes difficult to read and understand to many users.

            Although components and software may look very different from one manufacturer to the next, all share a great deal in common. All PLC systems will consist of the same basic components, a processor, I/O modules and some sort of programming software. All PLC processors will execute the operations in generally the same manner as described above.


II.      Creating a program

 Defining project requirements.

            Every project requires a good amount of planning in order to divide complex operations into smaller, more manageable tasks. Attention to the order of execution is also very important. Any operation can be divided into a series of much simpler steps stored in the processor in individual sections or POU’s (Program Organizational Units) and then executed in a user defined order.

            In our example project, we will have a 750-841 Bus Coupler (the processor with an Ethernet port), one 4 point discrete input module, one 2 point discrete output module, one 2 channel analog input module, one 2 channel analog output module and one end module.

            Our first example project will be simply toggling an output bit on and off at a one second interval, 500ms on and 500ms off. Don’t worry; it will get much more complicated later on.

Create a new file

            Open the CoDeSys software on you PC or Laptop. Go to “File> New”. You will see a popup window prompting you to enter the type of bus coupler that will be used. Select WAGO_750-841 and then “OK”.

Figure 2-1

            Each individual POU can be created to use a language that will best suite the task or tasks that the POU will execute, the preferred language must be selected. In our example project, select ST (Structured Text) for the PLC_PRG and then click “OK”. See figure 2-2 below.

Figure 2-2
            We will need to save and name the project. Go to “File> Save As” and save the project on your local drive with the name “First Project”.


C:\First Project

 Create a new POU

We could enter our instructions into the PLC_PRG but in order to maintain a structure to the program, we will create a new POU to accomplish this. Click on the POU tab at the bottom of the screen. Move your cursor over the and right click, a popup will appear. Select “Add Object”. Again, a popup will appear and we will type in the name “Blink” as the name of our POU, select “LD” (Ladder Diagram) as the language and click “OK”.

Figure 2-3

            You will notice now that a new window has been opened on the screen with “Blink (PRG-LD) in the upper left corner of the window. This is where we will enter the code and create the variables. Also notice that the window is divided into two areas, the upper area is where the variables will be created and the lower area is where the ladder “rungs” will be entered. See Figure 2-4 below.

Figure 2-4
            At this point, there are a number of items on the screen that need to be noted.

Figure 2-5

            We must define or “declare” our I/O variables. Click on the “Recourses” tab on the bottom of the screen and then right click on “Global Variables” and then “Add Object”.

Figure 2-6

In the pop-up window, name the new Global Variable List “IO_Variables” as shown below.

Figure 2-7
            Declare the first digital output in the stack as Output1 as shown below.


Output1 AT %QX2.0 : BOOL;

Output1 - Name of the variable

 %QX2.0 - Memory Location

BOOL - A single bit.

Figure 2-8
           Now we will begin to enter our code to create a program that will cause an output of our PLC to blink as mentioned earlier. Click on the “POUs” tab at the bottom of the screen and then on the “Blink” POU created earlier. On the fist rung, enter a normally closed contact, an on-delay timer (TON) and an output coil as shown below.

Figure 2-9
Then, copy and past the rung to Rung 2 and change the contact at the first of the rung to a Normally Open contact.

Now we can assign the tagnames that will be used in the “Blink” POU. We will name our On Delay Timer (TON) BlinkTmr and the output of the rung Blink. We well declare these as “Local Variable” or within the top window of our POU. Below the VAR heading in the top window, type the following:

BlinkOffTmr : TON;

BlinkOnTmr : TON;

BlinkOff : BOOL;

BlinkOn : BOOL;

BlinkOffDuration : TIME :=T#500ms;

BlinkOnDuration : TIME :=T#500ms;

Now assign the tagnames to the objects in the ladder rung. When complete, the declarstions and ladder should appear as sown below in figure 2-10.

 Figure 2-10

Next, we need to tie the BlinkOn tagname to the physical output. Insert another rung like Figure 2-11 connecting BlinkOff to Output1.
Figure 2-11

Finally, we need to add the name of the new POU into the main cyclical POU or PLC_PRG. Under the POUs tab, open the PLC_PRG. In the first line type:


Figure 2-12

Now save the project, download and test!

Link DownLoad Wago PLC Documents:

0 nhận xét:

Post a Comment