The text of a manual · part 6 of 38
DL06 Micro PLC User Manual, Volume 2 of 2, pages 50 to 59
Pages 50 to 59 of 370
The original document is the PDF (6.0 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Page 50
Chapter 7: RLLPLUS Stage Programming
1 Introduction to Stage Programming Stage Programming provides a way to organize and program complex applications with relative ease, when compared to purely relay ladder logic (RLL) solutions. Stage programming 2 does not replace or negate the use of traditional boolean ladder programming. This is why Stage Programming is also called RLL You won’t have to discard any training or 3 experience you already have. Stage programming simply allows you to divide and organize a RLL program into groups of ladder instructions called stages. This allows quicker and more intuitive ladder program development than traditional RLL alone provides. 4 Overcoming “Stage Fright” Many PLC programmers in the industry have 5 become comfortable using RLL for every PLC program they write... but often remain skeptical or 6 even fearful of learning new techniques such as stage programming. While RLL is great at solving boolean logic relationships, it has disadvantages as 7 well: • Large programs can become almost unmanageable, 8 because of a lack of structure. • When a process gets stuck, it is difficult to find the 9 rung where the error occurred. • Programs become difficult to modify later, because they do not intuitively resemble the application 10 problem they are solving. It’s easy to see that these inefficiencies consume a 11 lot of additional time, and time is money. Stage programming overcomes these obstacles! We believe a few moments of studying the stage concept 12 is one of the greatest investments in programming speed and efficiency a PLC programmer can make! 13 So, we encourage you to study stage programming and add it to your “toolbox” of programming techniques. This chapter is designed as a self-paced tutorial on stage programming. For best results: 14 • Start at the beginning and do not skip over any sections. • Study each stage programming concept by working through each example. The examples build A progressively on each other. • Read the Stage Questions and Answers at the end of the chapter for a quick review. B C D PLUS
X0
X4
C0 RST
C1
Y0 SET
STAGE!
X3
Y2
OUT
7–2
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 51
Chapter 7: RLLPLUS Stage Programming
Learning to Draw State Transition Diagrams
1 Introduction to Process States Ladder 2 Outputs Those familiar with ladder program execution know that Inputs Program the CPU must scan the ladder program repeatedly, over and over. Its three basic steps are: 3 1. Read the inputs 4 2. Execute the ladder program 1) Read Execute Write 3. Write the outputs Execute 2) Read Write 5 The benefit is that a change at the inputs can affect the 3) Read (Etc.....) outputs in just a few milliseconds. 6 Most manufacturing processes consist of a series of activities or conditions , each lasting for several seconds. minutes, or even hours. We might call these “process states”, which are either active or inactive at any particular time. A challenge for RLL programs is that a particular 7 input event may last for just a brief instant. We typically create latching relays in RLL to preserve the input event in order to maintain a process state for the required duration. 8 We can organize and divide ladder logic into sections called “stages”, representing process states. But before we describe stages in detail, we will reveal the secret to understanding stage 9 programming: state transition diagrams. The Need for State Diagrams 10 Sometimes we need to forget about the scan nature of PLCs, and focus our thinking toward the states of the process we need to identify. Clear thinking and concise analysis of an application gives us the best chance at writing efficient, bug-free programs. State diagrams are 11 just a tool to help us draw a picture of our process! You’ll discover that if we can get the picture right, our program will also be right! 12 A 2–State Process Consider the simple process shown to the right, which controls 13 an industrial motor. We will use a green momentary SPST pushbutton to turn the motor on, and a red one to turn it off. 14 The machine operator will press the appropriate pushbutton for just a second or so. The two states of our process are ON and OFF. A The next step is to draw a state transition diagram, as shown to the right. It shows the two states OFF and ON, with two B transition lines in-between. When the event X0 is true, we transition from OFF to ON. When X1 is true, we transition from ON to OFF. C If you’re following along, you are very close to grasping the concept and the problem-solving power of state transition diagrams. The output of our controller is Y0, which is true any time D we are in the ON state. In a boolean sense, Y0=ON state. Inputs ON
OFF
Outputs
X0 X1
Motor
Ladder Y0 Program
Transition condition
State
X0
OFF
ON
X1
Output equation: Y0 = On
Next, we will implement the state diagram first as RLL, then as a stage program. This will help you see the relationship between the two methods in problem solving.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
7–3
Page 52
Chapter 7: RLLPLUS Stage Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D 7–4
The state transition diagram to the right is a picture of the solution we need to create. The beauty of it is this: it expresses the problem independently of the programming language we may use to realize it. In other words, by drawing the diagram we have already solved the control problem! First, we’ll translate the state diagram to traditional RLL. Then we’ll show how easy it is to translate the diagram into a stage programming solution.
RLL Equivalent The RLL solution is shown to the right. Output control relay, Y0, has a dual pupose. It turns the motor on and off and acts as a latching relay. When the On pushbutton (X0) is pressed, output coil Y0 turns on and the Y0 contact on the second row latches itself on. So, X0 turns on the motor output Y0 which now has power flow and sets the latch Y0. It will remain on after the X0 contact opens. When the Off pushbutton (X1) is pressed, it opens the normally-closed X1 contact, which turns off moter output Y0 and also resets the latch.
X0 OFF
ON
X1 Output equation Y0 = ON
Set
Reset
Output
X0
X1
Y0 OUT
Latch Y0
Stage Equivalent SG The stage program solution is shown to the right. OFF State S0 The two inline stage boxes S0 and S1 correspond to the two states OFF and ON. The ladder rung(s) Transition below each stage box belong to each respective stage. S1 X0 This means that the PLC only has to scan those JMP rungs when the corresponding stage is active! For now, let’s assume we begin in the OFF State, so SG ON State S1 stage S0 is active. When the On pushbutton (X0) is Output pressed, a stage transition occurs. The JMP S1 Always On SP1 Y0 instruction executes, which simply turns off the Stage OUT bit S0 and turns on Stage bit S1. So on the next PLC scan, the CPU will not execute Stage S0, but will Transition execute stage S1! S0 X1 In the On State (Stage S1), we want the motor to JMP always be on. The special relay contact SP1 is defined as always on, so Y0 turns the motor on. When the Off pushbutton (X1) is pressed, a transition back to the Off State occurs. The JMP S0 instruction executes, which simply turns off the Stage bit S1 and turns on Stage bit S0. On the next PLC scan, the CPU will not execute Stage S1, so the motor output Y0 will turn off. The Off state (Stage 0) will be ready for the next cycle.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 53
Chapter 7: RLLPLUS Stage Programming
Let’s Compare Right now, you may be thinking “I don’t see the big advantage to Stage Programming... in fact, the stage program is longer than the plain RLL program”. Well, now is the time to exercise a bit of faith. As control problems grow in complexity, stage programming quickly out-performs RLL in simplicity, program size, etc. For example, consider the diagram below. Notice how easy SG it is to correlate the OFF and ON states of the state OFF State S0 transition diagram below to the stage program at the right. S1 X0 Now, we challenge anyone to JMP easily identify the same states SG in the RLL program on the ON State S1 previous page! SP1
Initial Stages
Y0 OUT
X0
At powerup and Program-toOFF ON Run Mode transitions, the X1 PLC always begins with all normal stages (SG) off. So, the stage programs shown so far have actually had no way to get started (because rungs are not scanned unless their stage is active). Assume that we want to always begin in the Off state (motor off ), which is how the RLL program works. The Initial Stage (ISG) is defined to be active at powerup. In the modified program to the right, we have changed stage S0 to the ISG type. This ensures the PLC will scan contact X0 after powerup, because Stage S0 is active. After powerup, an Initial Stage (ISG) works just like any other stage! We can change both programs so that the motor is ON at powerup. In the RLL below, we must add a first scan relay SP0, latching Y0 on. In the stage example to the right, we simply make Stage S1 an initial stage (ISG) instead of S0.
S0
X1
JMP
Powerup in OFF State ISG S0
Initial Stage S1
X0
JMP SG S1 SP1
Y0 OUT S0
X1
JMP
Powerup in ON State SG S0 S1
X0
JMP
Powerup in ON State X0
X1
Y0 OUT
ISG S1
Initial Stage SP1
Y0 SP0
First Scan X1
Y0 OUT S0 JMP
NOTE: If the ISG is within the retentive range for stages, the ISG will remain in the state it was in before power down and will NOT turn itself on during the first scan.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
7–5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Page 54
Chapter 7: RLLPLUS Stage Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D 7–6
We can mark our desired powerup state as shown to the right, which helps us remember to use the appropriate Initial Stages when creating a stage program. It is permissible to have as many initial stages as the process requires.
Powerup
X0
OFF
ON X1
What Stage Bits Do You may recall that a stage is just a section of ladder program which is either active or inactive at a given moment. All stage bits (S0 to 1777) reside in the PLC’s image register as individual status bits. Each stage bit is either a boolean 0 or 1 at any time. Program execution always reads ladder rungs from top to bottom, and from left to right. The drawing below shows the effect of stage bit status. The ladder rungs below the stage instruction continuing until the next stage instruction or the end of program belong to stage 0. Its equivalent operation is shown on the right. When S0 is true, the two rungs have power flow. • If Stage bit S0 = 0, its ladder rungs are not scanned (executed). • If Stage bit S0 = 1, its ladder rungs are scanned (executed). Actual Program Appearance
Functionally Equivalent Ladder
SG S0
S0
(includes all rungs in stage)
Stage Instruction Characteristics
SG S0
The inline stage boxes on the left power rail divide the ladder program rungs into stages. Some stage rules are: • Execution – Only logic in active stages are executed on any scan. • Transitions – Stage transition instructions take effect on the next occurrence of the stages involved. • Octal numbering – Stages are numbered in octal, like I/O points, etc. So “S8” is not valid. • Total Stages – The DL06 offers up to 1024 stages (S0 to 1777 in octal).
SG S1
SG S2
• No duplicates –Each stage number is unique and can be used just once. • Any order – You can skip numbers and sequence the stage numbers in any order. • Last Stage – The last stage in the ladder program includes all rungs from its stage box until the end coil.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
END
Page 55
Chapter 7: RLLPLUS Stage Programming
Using the Stage Jump Instruction for State Transitions
1 Stage Jump, Set, and Reset Instructions 2 The Stage JMP instruction we have used deactivates the stage in which the instruction occurs, while activating the stage in the JMP instruction. Refer to the state transition shown below. When contact X0 energizes, the state transition from S0 to S1 occurs. The two stage examples 3 shown below are equivalent. So, the Stage Jump instruction is equal to a Stage Reset of the current stage, plus a Stage Set instruction for the stage to which we want to transition. 4 S0 S1 5 6 7 8 Please Read Carefully – The jump instruction is easily misunderstood. The “jump” does not 9 occur immediately like a GOTO or GOSUB program control instruction when executed. Here’s how it works: 10 • The jump instruction resets the stage bit of the stage in which it occurs. All rungs in the stage still finish executing during the current scan, even if there are other rungs in the stage below the jump instruction! 11 • The reset will be in effect on the following scan, so the stage that executed the jump instruction previously will be inactive and bypassed. 12 • The stage bit of the stage named in the Jump instruction will be set immediately, so the stage will be executed on its next occurrence. In the left program shown below, stage S1 executes during the same scan as the JMP S1 occurs in S0. In the example on the right, Stage S1 executes on the next scan 13 after the JMP S1 executes, because stage S1 is located above stage S0. 14 A B C D X0
SG S0
SG S0
X0
S1
Equivalent
S0
X0
JMP
RST S1
SET
SG S0
Executes on next scan after Jmp
SG S1
X0
S1
S1
JMP
Executes on same scan as Jmp
SG S1
S1
Y0
OUT
Y0
OUT
SG S0
X0
S1
JMP
NOTE: Assume we start with Stage 0 active and Stage 1 inactive for both examples.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
7–7
Page 56
Chapter 7: RLLPLUS Stage Programming
1 Stage Program Example: Toggle On/Off Lamp Controller A 4–State Process 2 In the process shown to the right, we use an ordinary momentary pushbutton to control a light bulb. The 3 ladder program will latch the switch input, so that we will push and release to turn on the light, push and release again to turn it off (sometimes called toggle 4 function). Sure, we could just buy a mechanical switch with the alternate on/off action built in... However, this 5 example is educational and also fun! Next we draw the state transition diagram. 6 A typical first approach is to use X0 for both transitions (like the example shown to the right). However, this is incorrect (please keep reading). Note that this example differs from the motor example, because now we have just one 7 pushbutton. When we press the pushbutton, both transition conditions are met. We would just transition around the state diagram at top speed. If implemented in Stage, this solution 8 would flash the light on or off each scan (obviously undesirable)! The solution is to make the push and the release of the pushbutton separate events. Refer to 9 the new state transition diagram below. At powerup we enter the OFF state. When switch X0 is pressed, we enter the Press-ON state. When it is released, we enter the ON state. Note that X0 with the bar above it denotes X0 NOT. 10 11 12 13 14 When in the ON state, another push and release cycle similarly takes us back to the OFF state. Now we have two unique states (OFF and ON) used when the A pushbutton is released, which is what was required to solve the control problem. B The equivalent stage program is shown to the right. The desired powerup state is OFF, so we make S0 an initial C stage (ISG). In the ON state, we add special relay contact SP1, which is always on. D Note that even as our programs grow more complex, it Inputs
Toggle
Outputs
X0
Ladder Y0 Program
Powerup
X0
OFF
ON
X0
Output equation: Y0 = ON
Powerup
X0
Push–ON
ISG S0
X0
OFF State
S1
X0
OFF
ON
X0
Push–OFF
X0
JMP
SG S1
Push–On State
S2
X0
JMP
SG S2
ON State
Output
SP1
Y0 OUT S3
X0
JMP
SG S3 is still easy to correlate the state transition diagram with the stage program!
7–8
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Push–Off State
X0
S0
JMP
Page 57
Chapter 7: RLLPLUS Stage Programming
Four Steps to Writing a Stage Program By now, you’ve probably noticed that we follow the same steps to solve each example problem. The steps will probably come to you automatically if you work through all the examples in this chapter. It’s helpful to have a checklist to guide us through the problem solving. The following steps summarize the stage program design procedure:
1. Write a Word Description of the application. Describe all functions of the process in your own words. Start by listing what happens first, then next, etc. If you find there are too many things happening at once, try dividing the problem into more than one process. Remember, you can still have the processes communicate with each other to coordinate their overall activity.
2. Draw the Block Diagram. Inputs represent all the information the process needs for decisions, and outputs connect to all devices controlled by the process. • Make lists of inputs and outputs for the process. • Assign I/O point numbers (X and Y) to physical inputs and outputs.
3. Draw the State Transition Diagram. The state transition diagram describes the central function of the block diagram, reading inputs and generating outputs. • Identify and name the states of the process. • Identify the event(s) required for each transition between states. • Ensure the process has a way to re-start itself, or is cyclical. • Choose the powerup state for your process. • Write the output equations.
4. Write the Stage Program. Translate the state transition diagram into a stage program. • Make each state a stage. Remember to number stages in octal. Up to 1024 total stages are available in the DL06, numbered 0 to 1777 in octal. • Put transition logic inside the stage which originates each transition (the stage each arrow points away from). • Use an initial stage (ISG) for any states that must be active at powerup. • Place the outputs or actions in the appropriate stages.
You’ll notice that Steps 1 through 3 just prepare us to write the stage program in Step 4. However, the program virtually writes itself because of the preparation beforehand. Soon you’ll be able to start with a word description of an application and create a stage program in one easy session!
DL06 Micro PLC User Manual, 3rd Edition Rev. A
7–9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Page 58
Chapter 7: RLLPLUS Stage Programming
1 Stage Program Example: A Garage Door Opener Garage Door Opener Example 2 In this next stage programming example we’ll create a garage door opener controller. Hopefully most readers 3 are familiar with this application, and we can have fun besides! The first step we must take is to describe how the 4 door opener works. We will start by achieving the basic operation, waiting to add extra features later. 5 Stage programs are very easy to modify. Our garage door controller has a motor which raises 6 or lowers the door on command. The garage owner pushes and releases a momentary pushbutton once to raise the door. After the door is up, another push7 release cycle will lower the door. In order to identify the inputs and outputs of the 8 Up limit switch system, it’s sometimes helpful to sketch its main components, as shown in the door side view to the 9 right. The door has an up limit and a down limit Raise Motor Lower switch. Each limit switch closes only when the door has reach the end of travel in the corresponding 10 direction. In the middle of travel, neither limit switch is closed. 11 The motor has two command inputs: raise and lower. Door When neither input is active, the motor is stopped. Command 12 The door command is just a simple pushbutton. Whether wall-mounted as shown, or a radio-remote control, all door control commands logical OR 13 Down limit switch together as one pair of switch contacts. Draw the Block Diagram 14 The block diagram of the controller is shown to the right. Input X0 is from the pushbutton door control. Inputs Outputs A Input X1 energizes when the door reaches the full up position. Input X2 energizes when the door reaches B the full down position. When the door is positioned Ladder between fully up or down, both limit switches are Program open. C The controller has two outputs to drive the motor. Y1 is the up (raise the door) command, and Y2 is the D down (lower the door) command. Toggle
X0
To motor:
Up limit
X1
Y1
X2
Y2
Raise
Down limit
7–10
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Lower
Page 59
Chapter 7: RLLPLUS Stage Programming
Draw the State Diagram Now we are ready to draw the state transition diagram. Like the previous light bulb controller example, this application also has just one switch for the command input. Refer to the figure below. • When the door is down (DOWN state), nothing happens until X0 energizes. Its push and release brings us to the RAISE state, where output Y1 turns on and causes the motor to raise the door. • We transition to the UP state when the up limit switch (X1) energizes, and turns off the motor. • Then nothing happens until another X0 press-release cycle occurs. That takes us to the LOWER state, turning on output Y2 to command the motor to lower the door. We transition back to the DOWN state when the down limit switch (X2) energizes.
Powerup
X0
X0 Push–UP
RAISE
X1 ISG S0
DOWN
DOWN State S1
X0
UP
JMP
X2
LOWER
Push–DOWN
X0
SG S1
X0
Push–UP State S2
X0
JMP
Output equations: Y1 = Raise
Y2 = Lower SG
S2 The equivalent stage program is shown to the right. For now, we SP1 will assume the door is down at powerup, so the desired powerup state is DOWN. We make S0 an initial stage (ISG). Stage S0 X1 remains active until the door control pushbutton activates. Then we transition (JMP) to Push-UP stage, S1. A push-release cycle of the pushbutton takes us through stage S1 SGS3 to the RAISE stage, S2. We use the always-on contact SP1 to X0 energize the motor’s raise command, Y1. When the door reaches the fully-raised position, the up limit switch X1 activates. This SG takes us to the UP Stage S3, where we wait until another door S4 control command occurs. X0 In the UP Stage S3, a push-release cycle of the pushbutton will take us to the LOWER Stage S5, where we activate Y2 to SG S5 command the motor to lower the door. This continues until the SP1 door reaches the down limit switch, X2. When X2 closes, we transition from Stage S5 to the DOWN stage S0, where we began.
RAISE State Y1 OUT S3 JMP
UP State S4 JMP
Push–DOWN State S5 JMP
LOWER State
X2
NOTE: The only special thing about an initial stage (ISG) is that it is automatically active at powerup. Afterwards, it is just like any other.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Y2 OUT S0 JMP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
7–11