This action might not be possible to undo. Are you sure you want to continue?
Course № IC-1004
Introduction to Programming Design for Controllers
This document is the course text. You may review this material at your leisure before or after you purchase the course. If you have not already purchased the course, you may do so now by returning to the course overview page located at: http://www.pdhengineer.com/pages/IC‐1004.htm (Please be sure to capitalize and use dash as shown above.) Once the course has been purchased, you can easily return to the course overview, course document and quiz from PDHengineer’s My Account menu. If you have any questions or concerns, remember you can contact us by using the Live Support Chat link located on any of our web pages, by email at administrator@PDHengineer.com or by telephone toll‐ free at 1‐877‐PDHengineer. Thank you for choosing PDHengineer.com.
© PDHengineer.com, a service mark of Decatur Professional Development, LLC. IC‐1004 C1
relay. motors. or sensor. and is referred to as the “Von Neumann” computer architecture. The programming of early computers involved preparing a sequence of machine coded instructions. Document and maintain. John Von Neumann proposed a computer architecture that included storing instructions and data in the computer. In addition to the computer and programmable logic controllers (PLC). Run the program. Define the problem. Correct programming errors. 2. It is often referred to as a Boolean (BOOL) data type. IEC 61131-3 was published in 1993 for standardization of programmable controller programming. This is the computer architecture of most computers today. Convert the source code to a machine executable code. This is a common data type for inputs and 1 . An international standard. Analyze the requirements. Create a hierarchical chart 3. pseudocode. outputs and the processing task. embedded computers are very popular. Creating a program can be divided into seven steps: 1. Compile and run. The number of computing devices has grown from several research computers to over a billion computers today. The basic unit of data is the bit. Run test scenarios to verify outputs are correct. Fortran facilitated writing programs such as Finite Element Analysis programs that aided the engineering analysis of structures and mechanical components. a binary digit. Divide the processing task into subtasks. Logic design of the program. The bit has a value of 0 or 1. Fortran (Formula Translator). A bit can also represent an output control signal that can turn on lights. This can represent the state of a switch. which then performs the desired sequence of operations. In 1954. Convert the design into a formal programming language. Program Development A program is defined as a set of coded instructions for insertion into a machine. especially in hand-held devices.E. Introduction to Programming The modern concept of the computer originated in the mid 1940’s. The demand for programming has been driven by the need to program the many computing devices currently available. 6. 5. Write source code. Fortran is oriented to scientific programming and allowed one to write programs that could run on different computers. and state diagrams as required. All inputs have to be converted into a data type before processing. In 1945. valves and pumps. Specify inputs.Introduction to Programming Design for Controllers James Vogel P. Code the program. The purpose of the standard was to make programming more consistent among PLC systems. 4. John Backus invented the first popular high level programming language. Prepare flowcharts. Prepare user manuals and maintain the program. Test the program. 7. Defining the Inputs and Outputs Specifying the program’s inputs and outputs is an essential part of defining the programming problem.
Giving input and output addresses descriptive names makes the program more understandable. Programs are built from function blocks.767. A symbolic address is a way to reference input and output data using descriptive words. The following shows the common flowchart symbols. These are shown using a parallelogram. other names for these are subroutine. Programmable controllers are used to automate a variety of systems: HVAC. “PowerOn” is a symbolic address for a Power On switch input. This data type is useful for messages. Flow charts have been used for designing programs since the development of the modern computer. The programming components are organized in a hierarchical manner. Function blocks are sequences of code or graphical components to accomplish a specific task. There are a number of other useful data types. and calculations. Examples of outputs are O:4/2 and RedLight. function. Eight bits is called a byte and is sufficient to code a character. outputs of programmable controllers. Strong data typing can prevent mismatching data which can have unpredictable results. A sixteen bit signed number is often referred to as an integer (INT). Start/stop symbols indicate the beginning and ending of an instruction sequence. and robots. The string of characters is a text or STRING data type. An integer can represent positive and negative numbers of up to 32. and the others control the lights. process control. 2 . Decimal representation of numbers is useful to represent the output of sensors such as weight. procedure and method. The ASCII code refers to a binary coding scheme for coding characters. The following hierarchical chart shows the organization of a traffic light program showing the individual function blocks. alarm. value assignments. Data typing is common to most high level programming languages. traffic control. This data type is useful for counting. PowerOn controls startup. assembly lines. Most programs require inputs and outputs. An operation symbol commonly indicates actions. TrafficLight PowerOn GreenLight YellowLight RedLightX Logic Design A flow chart is a common design tool to graphically organize the sequence of instructions. water distribution. There are also DATE and TIME data types. Defining the Processing Tasks IEC 61131 International Standard provides methodologies for organizing programmable controller programs.Introduction to Programming Design for Controllers James Vogel P. For example. Textual data is usually longer than one character and requires more than one byte.E. Decimal numbers require 32 bits and are referred to as a float or REAL data type. pressure and temperature. A bit input can be identified as I:3/0 or PowerOn. Most programming languages allow a program to be divided into functional parts. Using locations to reference data is referred to as addressing. It is also common to group 16 bits in a word.
Start/Stop Operation Subroutine* Input/Output Decision Connector showing flow Basic Flowchart Symbols Using flow charts. “no”. selection. TrafficLight RedLightX PowerOn Set Yellow light on and other lights to off Turn off yellow light Turn on red light RedLightX Change light to red Set wait time based on remote signal Yes Is remote signal on? No GreenLight Turn on green light Turn off red light Wait 25 seconds Wait 5 seconds Wait 30 seconds YellowLight Turn on yellow light Turn off green light Wait 5 seconds Return 3 . programs can be divided into subroutines. A repetition of steps is a loop or iteration control structure. it is desired to sequence through red. Subroutines break a large program into smaller sections. green.Introduction to Programming Design for Controllers James Vogel P. The decision symbol indicates a test or condition that will result in two possible paths: one for when the condition is true. if the remote signal is on (the condition). In the RedLightX subroutine. the red light is on 30 seconds. In this program. In this program.the red light is on 5 seconds. The connecting line returns to the start of the sequence to show repetition. and one for when the condition is false. This is a selection or decision control structure.E. The flowchart of the following Traffic Light program shows the fundamental flow control structures. each subroutine turns on a different color light. All computer programs can be created using three fundamental control structures: sequence. the sequence of subroutines turns on each light. and iteration. “yes”. otherwise. In the following Traffic Light program. and yellow lights. A selection control structure bases the next step on a condition that is true or false. A consecutive series of steps is a sequence control structure.
“if…then.25 endwhile dispense selection output "Thank You" endif END State diagrams define a system using states and transitions between states. The “=” can mean a comparison of two values. These are shown below. False Pseudocode programs include words and symbols that describe computer operations such as input. “do while” statements for repeating instructions based on a condition being true(iteration). or an assignment of a value to a variable.50. In the beginning of a pseudocode program. Only one state is active at one time. output. Here we can see that when powered up. subtract (-). Pseudocode is a design tool that describes the instructions in an outline fashion.$0.25 dispense a quarter change = change . Pseudocode is similar to programming languages.50 quarter = $0.25 selection = “coffee”. START: output "Make A Selection" input selection if selection = “coffee” then price = $0. the machine will start in an idle state..50 else price = $1..25. The transitions are based on the inputs of sensors in the coffee machine. AND. $0. so coding into a computer language can be easier. one defines the variables used in the program. The following pseudocode is an example of a simple vending machine program design that dispenses coffee or coke and calculates the change.00 – price dowhile change is greater than or equal to $0. add (+).00 change $0.00 endif if dollarReader = True change = $1. $0. A state diagram for a simple coffee machine is given below. VARIABLES price $0. “coke” dollarReader = True. multiply (*) and divide (/).00. 4 .E.else” statements (selection).Introduction to Programming Design for Controllers James Vogel P. The states can indicate the operations that need to be further defined in detail. Pseudocode can implement the fundamental control structures: series of instructions (sequence). States are written in the circles and directional lines show the transitions to the next state. $1. OR.
It can also depend on the skills of the personnel available for the programming task. Program instructions are entered on “rungs”. motors. Ladder Diagram (LD) language is a graphical language based on relay ladder logic. the timer turns off the light and starts the next timer in the sequence. but it is simple. The programming language used can depend on whether the language is available for the controller or computing device. The end result of coding of the program is referred to as source code. Ladder diagrams can also include advanced functions such as timers like the one shown below. The diagram shows the timer enable (EN) output turning on the light by closing normally open (EN) contacts. It is more intuitive and easy for electricians and electrical technicians to understand. This is the popular method of programming controllers.Introduction to Programming Design for Controllers James Vogel P. The following includes examples of programs using the IEC standard controller programming languages. Ladder Diagrams are based on relay and switching logic. Input components are inserted on the left side and the outputs on the right. Coding the program Coding is the conversion of the program design into a formal programming language.E. Each light has a timer and the timer turns on the light. After a preset wait time.DN contacts. valves and lights. the timer done (DN) output turns off the light by opening normally closed (DN) contacts and starts the next timer by closing the normally open RedLight. Common outputs are relay solenoids. A Traffic Light sequencing program is shown below: The diagram looks complicated. Common input components are Normally Open and Normally Closed contacts. After the preset wait time. 5 .
DN TIMER ON DELAY Timer GreenLight Delay 25 seconds TIMER ON DELAY Timer RedLight Delay 30 seconds EN DN EN DN Rung 02 GreenLight. NOT) .DN G Yellow Light Rung 06 Y Ladder diagram programs can also include calculations.Introduction to Programming Design for Controllers James Vogel P. Mnemonics designate computer operations.E. The IL language can also include subroutines and functions such as timers.DN Rung 03 RedLight. LD speed GT 1000 JMPCN Volts_OK LD volts SUB 10 ST volts LD 1 ST Green_Light (* Load speed into storage register *) (* Is speed greater than 1000 *) (* If speed is NOT greater than 1000. Although this is not as intuitive as ladder logic. go to Volts_OK *) (* Load voltage value into storage register *) (* Subtract 10 from voltage value*) (* Store new voltage output value *) (* Load 1 in storage register *) (* Store 1 at Green_Light to turn on green light *) Volts_OK The IL language can perform logical operations (AND. The language is designed for easier coding of control structures. The following program reduces the voltage if a motor speed is greater than 1000. selections and loops. Instruction list (IL) language is more closely related to the instructions that the computer executes. PowerOn Rung 01 YellowLight. calculations using ADD. This programming is more suited for an engineer with a programming 6 . control loops and subroutines.DN R Green Light Rung 05 YellowLight. counting. A computer programmer is more familiar with this approach. Structured Text (ST) is a structured high-level programming language that is similar to the Pascal programming language. it is easier to have the instruction list language implemented on a programmable controller. OR.EN YellowLight.DN TIMER ON DELAY Timer YellowLight Delay 5 seconds EN DN Red Light Rung 04 GreenLight. It also turns on a green light.EN GreenLight. DIV instructions. MUL. This IL program uses instructions for a conditional test (GT) and a conditional jump (JMPCN) to code the selection structure.DN RedLight.EN RedLight. Programming using the Instruction List language is similar to using assembler code and can result in fast executing code. The ladder diagram strength is in performing switching and relay logic. SUB.
7 . (* A Normally Closed stop input *) current. The FBD is more common in the process industries. motor. If b is 0. The “*” is the multiply operation to calculate the power from current and volts.E.. END_VAR OUTPUT_VAR motor : BOOL. Each variable has an associated data type.Introduction to Programming Design for Controllers James Vogel P.(* Run motor *) mpower := current * volts. This program is used to turn on a motor when the start button is pressed. The mpower output variable represents the value of electrical power. The variables used for inputs. (* Switching Logic and Calculation Example *) FUNCTION Run_Motor INPUT_VAR start : BOOL. The following compares a function block and structured text. volts: REAL.DO” statements for iterations. The “FOR…DO” statements are used for a fixed number of repetitions. temperature setting or tank level. ST programs require identifying the data types used in the program. background or a computer programmer. volts. outputs and calculations are “declared” at the beginning of the program and their data type are identified. it provides a 0 output.(* Motor power *) END_VAR motor := (motor OR start) AND stop. Other mathematic operations used in structured text are add (+). and divide (/).(* Motor control relay output *) mpower: REAL. The motor output variable represents the relay that applies power to the motor.. This shows a divide function block. A divide by zero can cause serious errors for a computer and can halt operations. before proceeding. stop. Function Block Diagram (FDB) is a graphical language that uses function blocks and connections that show data and signal flow. like a time setting. This function block checks to be sure “b” is not zero.(* Power calculation *) END_FUNCTION Structure Text also includes “IF… THEN… ELSE” statements for implementing the selection structure and “WHILE. and calculate the electrical power. the Run_Motor function uses six variables: start. This is useful for situations involving a fixed count. or a setting is reached. (* A Normally Open start input *) stop : BOOL. For example. and mpower. The “WHILE…DO” statement is useful for checking whether a sensor is on. subtract (-). ST strength is in performing complex calculations and it is easy to read and understand. current.
FUNCTION_BLOCK divide VAR_INPUT a: INT.Introduction to Programming Design for Controllers James Vogel P. the program sequences traffic lights through red. Unlike other languages. The transition condition for this case is that the timer must complete the set time. SFC also allows steps to be programmed in other languages. ELSE c := 0. Each step shown has actions and a transition condition (bar). b: INT. The SFC is a design tool that is focused on describing the sequential behavior of a control program. END_VAR VAR_OUTPUT c: INT. simultaneously. The strength of SFC is the capability for synchronization of steps. The transition condition needs to be met before proceeding to the next step. END_VAR IF b <> 0 THEN c := a / b. The basic elements of an SFC diagram are shown in the Traffic Light program below: Initialization (Transition Condition) PowerSwitch = 1 (Start simultaneous operations) Turn red Light on Start 30 second timer Turn on WALK Light Start 10 second timer 30 second timer done 10 second timer done Turn green light on Start 25 second timer Turn on CAUTION Light Start 10 second timer 25 second timer done 10 second timer done Turn yellow light on Start 5 second timer Turn on DON’T WALK Light Start 40 second timer (End simultaneous operations) 5 second Traffic Light timer AND 40 second Crosswalk timer done In this example. END_FUNCTION_BLOCK divide a c b Sequential Function Chart (SFC) is a charting methodology that is also a graphical programming language. the SFC allows simultaneous execution of steps in parallel branches. green and yellow and also sequences a crosswalk (WALK/DON’T WALK) sign. END_IF. It is also suited for complex control problems. 8 .E.
Instruction Lists. alarm systems. and other programming languages like C and Visual Basic. Visual Basic is a programming language that includes many features that can allow one to create visual displays of processes. motion control. it is not included in the controller programming language standard. however. controllers can be programmed in higher level languages like the C programming language. Another language that is not a standard controller language is Visual Basic. Microsoft Visual Studio is an integrated program development system that allows one to create. Structured Text. robots. it usually indicates that it can’t. The programs can involve many lines of code and can be in different languages. Function Blocks. compiling and running programs. The closer the language is to the machine instructions. The references below provide web sites that include more details in programming. RSlogix software for the Allen Bradley PC-5 controllers is an example. so corrections to the program can be made. some errors will occur through program usage. Similarly one can have a variety of programming languages for implementing the design: Ladder Diagrams. compile and run programs in a number of languages.E. Testing is the process of running scenarios or test cases to verify that the program provides the intended outputs and operates as expected. the less complicated the compiler needs to be. demonstrations and evaluation software to explore programming further. Hierarchical charts.Introduction to Programming Design for Controllers James Vogel P. and calculations in the different programming languages. PLC’s have programming software for creating. Testing and Maintenance Compiling is the process of converting the instructions in the programming language to machine code instructions. In addition to the previously mentioned standard languages. 9 . This is the last step in which final documentation is prepared and maintenance is performed. When there is confidence that all errors are corrected. HVAC. The previous examples show traffic light sequencing. flowcharts and pseudocode are good tools for designing programs. Other High Level Languages and Programs. the program is made available for users. Compiling. a motor control. Maintenance involves the correcting of the errors that users discover. This has provided an overview of the different programming languages and code one could see. There are many systems that use computing devices that require programming: process control. Once the program is converted to machine code it can be executed or run. The programming of visual display interfaces does not usually require the precision timing of controller programs. gas monitoring. State diagrams are oriented on detailed digital logic and Sequential Function Charts are oriented for more complex control systems design. assembly lines. Conclusion Programming design can involve a number of methodologies for designing and implementing a program. Compilers check the source instructions for common errors. If the compiler can not convert the source code to machine code. and power generation. Even though testing can eliminate most errors. C is an ANSI standard language.
1999 Lewis. N. Microsoft MSDN. Institute of Electrical Engineers. The C++ Programming Language. 2007. UK. McGraw-Hill. Rob. 2007.att. http://msdn. GNU Free Document License 1996-2007 http://claymore.Y. Allen B. Programming Industrial Control Systems using IEC 1131-3 Revised Edition. The Practice of Programming. W. 2005 Robertson.. PLCs. PLCopen. Fourth Edition. http://www.org Tim Young. Logic Problem Solving. http://plcopen. N. Reading. Tools for PLC Programming.Y.E.gvsu. Brian W.html 10 . AT&T labs. Mass 2004 Tucker.thelearningpit. Bibliography Farrell. Frank D. and Pike. Programmable Logic Controllers. http://www.Introduction to Programming Design for Controllers James Vogel P.microsoft.N. Fundamentals of Computing I. Lesley Anne.com/vstudio/express/hardware/ Bjarne Stroustrup. 2004. The Learning Pit Dot Com. Automated Manufacturing Systems. Mass 2002 Kernighan. http://www..com/ LogixPro 500. Simple Program Design.research. R. Course Technology. Mass. 2007.N.engineer.html Hardware Development – Projects you can build. 1995 Web Sites Hugh Jack.edu/~jackh/books/plcs/ PLCopen for efficiency in automation.Y. Addison-Wesley.plcdev.Y. Joyce.com/~bs/C++.com/lp/logixpro. Course Technology. 1998 Petruzella. Inc and TAMU. McGraw-Hill. Programs and Computers. et al. Boston.org. Programming Logic and Design. Boston. 2007..
This action might not be possible to undo. Are you sure you want to continue?