KNOWARE  

Software for Education and Industry


   Home   Order Form    Reviews   

PLC Structured Text

with

CODESYS V3.5

Want to learn how to program a PLC in Structured Text, make HMIs (Human Machine Interfaces) and be able to run your programs on a simulated PLC?  PLC Structured Text with CODESYS V3.5  shows you step-by-step how to program a PLC using free CODESYS software.

Simply download the free CODESYS software at http://store.codesys.com/codesys.html?___store=en&___from_store=default then follow the exercises in PLC Structured Text with CODESYS V3.5 to learn how to program in Structured Text, build HMIs, and run your programs on a simulated PLC. You do not need an actual PLC to use PLC Structured Text with CODESYS V3.5.

PLC Structured Text with CODESYS V3.5 is written in everyday, easy to understand language that shows you step-by-step what to do.  PLC Structured Text with CODESYS V3.5 is written in .html format so you can use your favorite internet browser with hyperlinks, bookmarks, and word searches.  PLC Structured Text with CODESYS V3.5 requires no software installation on your computer.  Just double click on the Table of Contents.html, and your Internet browser launches the program.

If you are already familiar with Structured Text and Codess programming, but want more programming practice, check out Advanced Exercises for PLC Structured Text with Codesys.

What is CODESYS?
CODESYS is a program written by the German company 3S-Smart Software Solutions to program various PLCs. It is written to conform to IEC 61131-3, an open international standard for PLC programming languages.  Another program similar to CODESYS called TwinCAT 3 was developed by the German company Beckhoff.  CODESYS has a built-in simulation PLC, built-in HMI capability (Human Machine Interface or Visualization), and can be programmed in various PLC languages, including:
Who uses CODESYS?
CODESYS is used by companies such as Bosch, ABB, Moeller, Wago, Eaton, Festo and others to program their PLCs.

What
PLC Programming with CODESYS V3.5 does:
This tutorial will show you step-by-step:

What PLC Programming with CODESYS V3.5 does NOT do:
This tutorial does not address:

No prior knowledge of PLCs is necessary.

This tutorial is written by a Professional Engineer with 14 years industrial experience and 20 years experience teaching electrical engineering technology at the college level.

If you want to learn how to use CODESYS to program PLC Ladder Diagram and Function Block programs, you can purchase my PLC Ladder Logic and Function Block Programming with CODESYS V3.5 tutorial at http://www.knoware-online.com/codesys.html. Or if you want to learn how to use CODESYS to program PLC Instruction List, you can purchase my PLC Instruction List with CODESYS V3.5 tutorial at http://www.knoware-online.com/il_codesys.html.


If you want to run and solve Ladder Logic programs without using CODESYS you can purchase my PLC Simulator 10 at http://www.knoware-online.com/pc-plc.html. This simulator turns your PC into a PLC, has the "look and feel" of Allen-Bradley RSLogix Micro software (though not exact), runs and solves Ladder Logic programs that you write, and allows you to build machines with limit switches, pilot lights, selector switches, solenoids, and conveyors that move in response to the ladder programs you write.   

How to use this tutorial:
Chapters 1 though 5 of this tutorial explain how to download CODESYS, install it, program a rung, build an HMI, and run the program. Perform the tasks in these chapters verbatim until you feel comfortable navigating within CODESYS.  You can use this tutorial without using CODESYS, but then you would loose the benefit of hands-on programming.

Chapters 6 thru 16 move at a little faster pace, explain many of the more advanced instructions of CODESYS, and present example programs that you can analyze and modify if desired.



PLC Structured Text

with

CODESYS V3.5


Table of Contents

Chapter

1. Introduction
What is a PLC?
History of PLCs
What is Structured Text?
What is CODESYS?
Who uses CODESYS?
What this tutorial does
What this tutorial does not do
How to use this tutorial
What you need to use this tutorial

                     

2.  Launching CODESYS
Download and Install the CODESYS Software
Start the CODESYS Program
Start a New Project
Save the Project
Summary                        
                   
3.  Programming Your First Instruction
Open the Project Created in Chapter 2
Open PLC_PRG
Write the Program
Understand Variable Types
Add a Comment
Save the Project
Summary                                   

4.  Creating an HMI

Open the Project Saved in Chapter 3
Create an HMI
Program a Dip Switch
Program a Lamp
Save the Project
Summary


5.  Running Your Program
Open the Project Saved in Chapter 4
Choose the Simulation PLC
Build (compile) the Program
Login to the Simulation PLC
Start the PLC
Close the Switch from the HMI
Close the Switch by Forcing It
Stop the PLC
Logout from the PLC
Save the Project

Summary
                       

6.  IF Instruction
Start a New Project
Example 1:  Using IF for a Switch in Series with a Coil          
Example 2:  Using IF for a Motor Starter Circuit 
Example 3:  Using IF for a Latch Relay                        
Save the Project

Summary


7.  WHILE and REPEAT Loops
Start a New Project
Example 1:  Using WHILE loops for a Switch in Series with a Coil       
Example 2:  Using WHILE loops for a Motor Starter Circuit
Using REPEAT Loops
Save the Project
Summary

8.  FOR Loop
Start a New Project
Example 1:  Using FOR Loop to Calculate 25
Example 2:  Using FOR Loop to Calculate 10 Factorial
Save the Project
Summary


9.  CASE Instruction
Start a New Project
Example 1:  Using CASE Instruction
Save the Project
Summary

10. Boolean Instructions (AND, OR, XOR)
Start a New Project
Program an AND Condition
What if the Inputs are Numbers?
AND two Decimal Numbers
AND two Binary Numbers
AND two Hex Numbers
AND two Octal Numbers
AND two Variables
Program an OR Condition
Program an XOR Condition
Save the Project
Summary

             

11.  Math Instructions (ADD, SUB, MUL, DIV, MOD)
Start a New Project
Program an ADD Instruction
Program an SUB Instruction
Program an MUL Instruction
Program an DIV Instruction
Program an MOD Instruction
Change the REAL Variables
Save the Project
Summary


12.  Compare Instructions (EQ, NE, LT, LE, GT, GE)
Start a New Project
Program a EQ Instruction
Program a NE Instruction
Program a LT Instruction
Program a LE Instruction
Program a GT Instruction
Program a GE Instruction
Save the Project
Summary

 

13.  Selection Instructions (SEL, MUX, MIN, MAX, LIMIT)
Start a New Project
Program an SEL Instruction
Program a MUX Instruction
Program a MIN Instruction
Program a MAX Instruction
Program a LIMIT Instruction
Save the Project
Summary


14.  Timers (TON, TOF, TP)
Start a New Project
Program a TON Timer
Program a TOF Timer
Program a TP Timer
Save the Project
Summary
             
15.  Counters (CTU, CTD, CTUD)
Start a New Project
Program a CTU Counter
Program a CTU HMI
Run the CTU Program
Program a CTD Counter
Program a CTD HMI
Run the CTD Program

Program a CTUD Counter
Program a CTUD HMI
Run the CTUD Program
Save the Project
Summary

16.  Examples
Example - Warning Light                       
Example - Reversing Motor Starter
Example - Washing Machine with TON
Example - Washing Machine with MUX
                        
Index            

 

 

Sample excerpt from... 

 Chapter 16.  Examples

Step 4) Example - Washing Machine with MUX

The MUX (multiplexer) instruction introduced in Chapter 13 can be used a sequencer.   Sequencers are much like the old drum controllers that rotated and closed various contacts at each position of rotation.  They are also something like a player piano, where at each beat a different set of keys are depressed to form a song. 

The clothes washing machine of Step 3) above can be controlled with a MUX by sending the output of the MUX to a new variable named Output.  Each valve or motor will be assigned to one bit of the variable Output as shown in Figure 9 below.

Figure 9  Washing Machine Cycle with Motors and Valves Assigned to Bits of the variable Output

Washing machine sequence of events for MUX

Open  CODESYS and start a new, standard, Instruction Lists project.  Name the project Washing Machine with MUX. See Chapter 2 if you need a refresher on how to do this.  If CODESYS is already open, click on File>>New Project... to start a new project.

Program the variables shown in Figure 10a below.

Figure 10a  Example - Washing Machine with MUX variables

Washing Machine with MUX variables

Program the instructions shown in Figure 10b below.

Figure 10b  Example - Washing Machine with MUX instructions

Washing Machine with MUX instructions


The scheme behind this program is as follows:

The essence of the program is the MUX instruction on line 14 of Figure 10b above. Figure 11 below illustrates that instruction.  The numbers (0, 1, 2, 20, etc.) being inputted to the MUX are the numbers necessary to turn on the proper bits of Output for each step of the washing machine.

Figure 11  MUX Instruction on Line 14 of the Program

MUX instruction illustrated

Lines 17 through 21 of the program in Figure 10b above energize various valves and motors by interrogating specific bits of the variable Output.  For instance, the instruction fill_valve:=Output.0 energizes the fill valve if bit 0 of the Output variable is 1 (True), and de-energizes the fill valve if bit 0 is 0 (False).  Similarly, the instruction agitate_mtr:=Output.1 energizes the agitate motor if bit 1 of the Output variable is 1 (True), and de-energizes the agitate motor if bit 1 is 0 (False), and so on.

Build a Visualization (HMI) as show in Figure 12 below.  See See Chapter 4 if you need a refresher on how to do this. This is the same Visualization used in step 3) above where we programmed the washing machine with timers (TONs).  Assign the switch and lights to the same variables as you did in step 3) above.


Figure 12  Visualization of Washing Machine with MUX

Visualization of washing machine with MUX


The large lamps on the left are what would appear on the front of the washing machine for the user.  The small lamps on the right are there just so we can see what outputs are being energized inside of the washing machine during the various steps of the washer. 

Run the program while viewing the Visualization tab.  See Chapter 5 if you need a refresher on running a program.  Click on the Start switch twice to simulate a momentary push button.   The washer should go through its sequence of operations and then stop.

Click on Online>Logout to stop the program, then save the program for future reference.

Hardware/Software Requirements: