Download presentation
Presentation is loading. Please wait.
Published byClifton Daniel Modified over 8 years ago
1
PLC programming Part 2: Programming
2
Topics The structure of a PLC program PLC operation Execution of a PLC program Programming languages
3
The structure of a PLC program A PLC program consists of rules that make logic relation between inputs and outputs of the controller. Basically it uses logic operands: AND, OR, negation The structure of the rules is IF…THEN…ELSE…
4
Inputs, outputs, PLC program InputsOutputs & & ≥1 Input sideOutput sidePLC program switch relay Internal states
5
PLC operation Read all field input devices via the input interfaces. Execute the user program stored in application memory, then, based on whatever control scheme has been programmed by the user. Turn the field output devices on or off, or perform whatever control is necessary for the process application.
6
PLC operation scheme Power-on the PLC Clear the output table Input links Input table update PLC program Instruction 1 Instruction 2 … Instruction n Output table update Output links …… Input signals Output signals
7
Execution of a PLC program The PLC resolves the program rule by rule (sequential execution). The PLC operates in a synchronous way i.e. inputs does not change under a scan cycle.
8
Order of execution Put the result into an internal variable Set the output
9
Program languages Standardized by the IEC 61131-3 in 1993: Structure Text Programming (ST) Functional Block Programming (FB) Instruction List (IL) Sequential Function Chart (SFC) Ladder Diagram (LD) - most common
10
Structured Text Programming A high level language Used to express the behavior of functions, function blocks and programs It has a syntax very similar to PASCAL Strongly typed language Functions: assignments expressions statements operators function calls flow control
11
Data Types SINTshort integer1 byte INTinteger2 bytes DINTdouble integer4 bytes LINTlong integer8 bytes USINTunsigned short integer1 byte UINT unsigned integer2 bytes UDINTunsigned double integer4 bytes ULINTunsigned long integer8 bytes REALreal4 bytes LREALlong real8 bytes TIMEtime duration DATEcalendar date TODtime of day DTdate and time of day STRINGcharacter strings BOOLboolean1 bit BYTEbyte1 byte WORD16 bit bit string16 bits DWORD32 bit bit string32 bits LWORD64 bit bit string64 bits
12
Derived Data Types TYPE (* user defined data types, this is a comment*) pressure : REAL; temp : REAL; part_count: INT; END_TYPE; Structure: TYPE data_packet: STRUCT input : BOOL; t : TIME; out : BOOL; count: INT; END_STRUCT; END_TYPE;
13
Variable Declarations Local variable: Use VAR, VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT, VAR_GLOBAL, VAR_EXTERNAL for different variable types. VAR I,j,k: INT; v: REAL; END_VAR
14
Operators and Expressions ( )parenthesized expression function( )function **exponentiation -negation NOTBoolean complement + - * /math operators MODmodulus operation =comparison operators =equal <>not equal AND, &Boolean AND XORBoolean XOR ORBoolean OR Y := X+1.0; y := a AND b; v := (v1 + v2 + v3)/3 output := (light = open) OR (door = shut);
15
Condition Statements IF a > 100 THEN redlight := on; ELSEIF a > 50 THEN yellowlight := on; ELSE greenlight := on; END_IF; CASE dial_setting OF 1 :x := 10; 2 :x := 15; 3 :x := 18; 4,5:x := 20; (* 4 or 5 *) ELSE x := 30; END_CASE
16
Iteration Statements FOR I:= 0 to 100 BY 1 DO light[I] := ON; END_FOR I := 0; REPEAT I := I + 1; light[I] := on; UNTIL I > 100; END_REPEAT I := 0; WHILE I < 100 DO I := I + 1; light[I] := on; END_WHILE
17
Functions FUNCTION add_num : REAL VAR_INPUT I,J : REAL END_VAR add_num := I + J; END_FUNCTION Call a function: x:= add_num(1.2, 5.6); Built-in Functions: ABS, SQRT, LN, LOG, EXP, SIN, COS, TAN, ASIn, ACOS, ATAN, ADD, MUL, SUB, DIV, MOD, EXPT, MOVE), logic functions (AND, OR, XOR, NOT), bit string functions (SHL, SHR shift bit string left and right, ROR, ROL rotate bit string), etc.
18
Programs PROGRAM example7.1 VAR_INPUT MSI: BOOL; C1:BOOL; C2: BOOL; C3:BOOL; C4:BOOL; END_VAR VAR_OUTPUT R1:BOOL : FALSE; R2:BOOL : FALSE; R3:BOOL : FALSE; R4: BOOL : FALSE; END_VAR R1 := MS1 AND (NOT R4); R2 := R4 AND (NOT C3) AND (NOT C2); R3 := C4 AND (NOT C3); R4 := C1; END_PROGRAM
19
Functional Block Programming Functional block (FB) is a well packaged element of software that can be re-used in different parts of an application or even in different projects. Functional blocks are the basic building blocks of a control system and can have algorithms written in any of the IEC languages.
20
An Up Counter Function Block FUNCTION BLOCK CTU VAR_INPUT CU : BOOL; R : BOOL; PV : INT; END_VAR VAR_OUTPUT Q : BOOL; CV : INT; END_VAR IF R THEN CV := 0; ELSEIF CU AND (CV < PV) THEN CV := CV + 1; END_IF; Q := (CV >= PV); END_FUNCTION_BLOCK CU : input to be counted R : reset PV : preset value Q : contact output CV : counter value. The algorithm in Structured Text:
21
A PID Control Function Block PID block diagram PID control algorithm SPset point PVsensor feedback KPproportional error gain TRintegral gain TDderivative gain AUTOcalculate XOUToutput to process XOmanual output adjustment cycletime between execution
22
Instruction List Programming A low level language which has a structure similar to an assembly language. Since it is simple, it is easy to learn and ideally for small hand-held programming devices. Each line of code can be divided into four fields: label, operator, operand, and comment. For example: LD MS1 STR1 loopANDNC3
23
Operators Operator Modifiers Description LDNload operand into register STNstore register value into operand Sset operand true Rreset operand false ANDN, (Boolean AND &N, (Boolean AND ORN, (Boolean OR XORN, (Boolean XOR ADD(addition SUB(subtraction MUL(multiplication DIV(division GT(greater than GE(greater than and equal to EQ(equal NE(not equal LE(less than and equal to LT(less than JMPC, Njump to label CALC, Ncall function block RETC, Nreturn from function or function block )execute last deferred operator Modifier “N” means negate. “(“ defers the operator. “C” is a condition modifier, the operation is executed if the register value is true.
24
Sequential Function Chart A graphics language used for depicting sequential behavior. The IEC standard grew out of the French standard Grafcet which in turn is based on Petri-net. A SFC is depicted as a series of steps shown as rectangular boxes connected by vertical lines. Each step represent a state of the system being controlled. The horizontal bar indicates a condition. It can be a switch state, a timer, etc. A condition statement is associated with each condition bar. Each step can also have a set of actions. Action qualifier causes the action to behave in certain ways. The indicator variable is optional. It is for annotation purposes.
25
SFC Action Qualifiers: Nnon-stored, executes while the step is active Rresets a store action Ssets an action active Ltime limited action, terminates after a given period Dtime delayed action. Pa pulse action, executes once in a step SDstored and time delayed DStime delayed and stored SLstored and time limited
26
Ladder diagram Based on relay logic: ON/OFF ON/OFF events mean logic values: TRUE/FALSE Instructions have the logic form: IF…THEN…ELSE Conditions and consequences consist of TRUE/FALSE values combined with AND/OR and NOT operations. Ladder diagram is a graphical interpretation of the control laws.
27
Example: motor control (I.) For a process control, it is desired to have the process start (by turning on a motor) five seconds after a part touched a limit switch. The process is terminated automatically when the finished part touches a second limit switch. An emergency switch will stop the process any time when it is pushed.
28
Example: motor control (II.) Limit switch 1-2 (LS1-2) is on: true LS1-2 is off: false Push button (PB1) is on: true PB1 is off: false Relay 1-2 (R1-2) is on: true R1-2 is off: false Timer <5 sec: false =5 sec: true
29
Example: motor control (III.) IF (LS1 = true OR R1=true) AND PB1=false AND LS2=false THEN R1 := true; ELSE R1 := false; END_IF; IF R1 = true AND Timer=true THEN R2 := true; ELSE R2 := false; END_IF;
30
Elements of a ladder diagram ( ) Open contact Closed contact Inverter/Negation Coil Application instruction Rising pulse Falling pulse Horizontal link Vertical link Open branch Closed branch Rising pulse open branch Falling pulse open branch In the followings the Mitsubishi nomenclature will be used.
31
Normally open contact Ladder diagramInstruction list This symbol conducts when the associated device is energized. Program operation: Device name
32
Normally closed contact This symbol conducts when the associated device is de-energized. Ladder diagramInstruction list Program operation: Device name
33
Coil This symbol always appears just before the right vertical ladder rail. It becomes energized when the logic before it conducts. When energized, the output with the same address becomes active. In instruction mode the mnemonic is OUT, for OUTPUT ACTIVATE. This symbol occupies 1 step of program space, unless being used for a timer or counter instruction, when it can occupy up to 5 steps.
34
Application instruction This symbol usually appears just before the right vertical ladder rail when used for bit control. This symbol is typically used for word device commands; however there are a few bit instructions that use the brackets as well. It becomes energized when the logic before it conducts. This symbol occupies multiple steps of program space depending on the command used.
35
Invert This symbol inverts the state of all logic before it. If the logic is true (positive) at the point of the invert, the output of the invert is false (negative). If the logic is false, the invert output is true.
36
Rising/Falling pulse It works similar to open contact/closed contact, however it conducts for one cycle starting at the moment when the signal changes, i.e. rises up from 0 to 1/falls down from 1 to 0.
37
AND instruction Ladder diagramInstruction list Program operation:
38
OR instruction Ladder diagramInstruction list Program operation:
39
The problem of multiple outputs A typical programming error to set the value of the same device in several instructions. Condition merging solves this problem.
40
SET/RST instructions Ladder diagramInstruction list Program operation:
41
PLS/PLF instructions Ladder diagram Instruction list Program operation:
42
Data movement (I.) Ladder diagramInstruction list Program operation:
43
Data movement (II.) Ladder diagramInstruction list Program operation:
44
Devices Device nameTypeFunction XInputGets the input signal of the PLC YOutputGives the output signal of the PLC MAuxiliary relayA logic valued internal register TTimerTiming function CCounterCounts signal changes DData register16/32 bit data container
45
Inputs Name: X Role: Denotes the physical PLC inputs. Explanation: IF X0=true AND X1=false then Y10:=true; ELSE Y10:=false; END_IF; (1)(2)
46
Outputs Name: Y Role: Denotes the physical PLC outputs. Explanation: IF (X0=true OR Y10=true) AND X1=false then Y10:=true; ELSE Y10:=false; END_IF; (1) (2)
47
Auxiliary relays Name: M Role: internal programmable state marker Explanation: IF (X0=true OR M507=true) AND X1=false then M507:=true; ELSE M507:=false; END_IF; Other applications: general state marker, special internal register, PLC diagnostics (1) (2)
48
16 bit data registers 16 bit data range: 0000h – FFFFh (Hex) 0-65535 (Decimal) 0:= positive number 1:= negative number 16 bit data
49
32 bit data registers 32 bit data range: 00000000h – FFFFFFFFh (Hex) 0-4 billion (Decimal) 0:= positive number 1:= negative number 32 bit data
50
Special data registers: constants Notation: K Role: decimal constant values Types: 16 (-32768 - +32767) and 32 (-2147483648 - +2147483647) bit Usage: in counters, timers, instruction parameters Notation: H Role: Hexadecimal constant values Types: 16 (0 - FFFF) and 32 (0 – FFFF FFFF) bit Usage: in counters, timers, instruction parameters
51
Timers Ladder diagramInstruction list Program operation:
52
Retentive timers Ladder diagram Instruction list Program operation:
53
Counters Ladder diagram Instruction list Program operation:
54
References http://www.gandhcontrols.com/Downloads/Manuals/PLC Programming.ppt www.dcc.ttu.ee/lap/lap5760/jy992d48301-j_fx.pdf
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.