STEP7 Programming
STEP7 Programming
Siemens Step 7
S7-300
Programming
Step7_300 - 1
Table of Contents
Page
A. Starting a Project With the S7-300
1. Configuring Communications
2. I/O Configuration
3. Specifying Other Variables
4. Processor Download
B. Ladder Logic Programming
1. Two Contacts in Series (Logical AND)
2. Entering Branches (Logical OR)
3. Timers
4. Counters
C. Adding Comments to Ladder Logic
D. Assigning Symbols to Addresses
E. Displaying Memory Locations
F. Input/Output Forcing
G. Importing/Exporting Symbols
H. Saving Ladder Logic Program
I. Restoring Ladder Logic Program
J. Printing Ladder Logic Program
Step7_3003
Step7_3003
Step7_3004
Step7_3005
Step7_3005
Step7_3007
Step7_3007
Step7_3008
Step7_3008
Step7_3009
Step7_30010
Step7_30010
Step7_30011
Step7_30011
Step7_30012
Step7_30013
Step7_30013
Step7_30014
SiemensStep7_S7_300.doc
Step7_300 - 2
This document is a supplement to the Lab 1.doc lab exercise that introduces one to the
basics of ladder logic programming. The following equipment is assumed:
Siemens 6ES7 307-1EA00-0AA0 PS307 10A power supply
Siemens 6ES7 316-2AG00-0AB0 CPU316-2 DP processor
Siemens 6ES7 321-1BL00 32 chan. 24v disc. input
Siemens 6ES7 322-1BH01 16 chan. 24v disc. out/0.5A
This document is primarily for version 5.4 of the Step7 software. A MPI/DP PC adapter (6ES7
972-0CA23-0XA0) plus serial cable connection from the PC to the processor is also assumed.
In order to become familiar with basic ladder logic programming and addressing
techniques on the Siemens equipment, the steps to accomplish the first part of the first lab
exercise are outlined in sections A and B. The remainder of the sections outline the steps to
document your ladder, to print the ladder logic program, and to save your ladder logic diagram.
In an industrial setting, the initial PLC programming is done offline and then later
downloaded to the PLC when ready for the final test and debug. In addition, there is usually
only one project (program) for each PLC on the network. For these labs, the ladder
programming will be done online so that changes can be immediately tested.
Siemens Step 7 version 5.4 is used to program the S7-300 and S7-400 PLCs. An icon for
these programs should already be on the desktop.
The PLC and the PC used to program it are connected directly through a serial RS-232 link.
SiemensStep7_S7_300.doc
Step7_300 - 3
SiemensStep7_S7_300.doc
Step7_300 - 4
Click on Properties.
Click on the "MPI" tab. Verify that "PG/PC is the only master on the bus" is checked
and the Address is "3".
Click on the "Local Connection" tab. Verify that the COM port is "1" and the
transmission rate is "19200". Click on OK.
Click on OK.
You are now ready to configure the I/O channels.
2. I/O Configuration
Using the Step 7 software, configuration of the inputs and outputs involves two steps:
1.
2.
The second step is not absolutely necessary, but it is easier to specify symbols now than when
programming the ladder logic. The Step 7 programming software aids the programming of a
PLC because one does not need to memorize the I/O addresses and file addresses, but can refer
to them symbolically, as a variable.
The PLC will be set up so that the module configuration is as follows:
Slot Module
Description
Start Addr.
PS307
Power supply
2, 3
CPU316-2 DP
Profibus CPU
6ES7 321-1BL00
I0
SiemensStep7_S7_300.doc
Step7_300 - 5
Now drag-and-drop the module to slot 5 of either rack displayed on the left. It should
appear in slot 5 and the Q addresses should be automatically assigned.
Click on the Save icon (floppy disk).
Close the hardware configuration window by clicking on the red "X."
To assign symbols to the input/output channels, an organization block must be open. The
default organization block is OB1. To open it, keep expanding the project "tree" in the left pane
until the "Blocks" folder is visible. Select the "Blocks" folder. The OB1 block should now be
visible in the right pane. Double-click on "OB1" to open it. A window with a blank network 1
should open. To access the symbols, from the menu select Options | Symbol Table. A symbol list
with only OB1 defined will appear. To assign symbols to the discrete input channels,
Click in the symbol column of the second row.
Type "Start_PB" and press <Tab>.
The address column will now have "OB 2". Change the address to "I0.0" and press
<Tab>. The data type will change to BOOL.
Press <Tab> to place the cursor in the Comment column.
Type in a description, for example, "Start push button switch" and then press <Tab>.
Enter the other discrete input symbols. Note that the address automatically increments
to the next one.
Repeat the above 5 steps to specify the variables and descriptions for the other input
and output channels. Note that when entering the first discrete output symbol, the
address will need to be changed to "Q4.0."
To close the symbol editor, click on the red "X" in the upper right corner.
Close OB1 (click on red "X" in upper right corner).
3. Specifying Other Variables
It is good practice to enter all of the variables before you start programming. If you enter
a rung with undefined variables, errors will be reported. At that point, you can enter new
variables into the program and clear the verify errors.
However, since timers and counters are handled quite differently than other PLCs, they
will be defined as they are used.
To check that the processor is properly configured, the blank program should be
downloaded to the processor.
4. Processor Download
To download to the processor,
Highlight "Blocks" in the left pane.
Click on the Download icon (yellow arrow pointing down to a PLC rack).
A popup window will ask if you want to overwrite objects. Unless you know what
you are doing, you should answer "Yes" to this prompt.
SiemensStep7_S7_300.doc
Step7_300 - 6
A popup window will ask if you want to load system data. When downloading for the
first time, answer "Yes" to this prompt. On subsequent downloads due to program
changes, answer "No" to this prompt, unless you are changing system data (e.g.,
error log).
If you answered "Yes" to the last prompt, a popup window will ask if you want to
delete the system data. Answer "Yes" to this prompt.
If a prompt appears indicating that the processor will be stopped, answer "OK."
If a prompt appears asking whether you want to start the module, answer "Yes."
Go to the next section to start programming.
SiemensStep7_S7_300.doc
Step7_300 - 7
SiemensStep7_S7_300.doc
Step7_300 - 8
Click on the "eyeglasses" icon to turn on the program monitor.
Try the input switches in various combinations and observe the output. Also observe the
changing status of ladder components on the screen. Energized or true conditions cause the
elements to be highlighted (green) on the ladder diagram.
3. Timers
A new blank rung is added to the program by clicking on the New Rung icon, which
looks like a rung with one contact and coil with a dashed line beneath it.
The IEC-compliant timers are system function blocks and are added to the program
blocks when the first one is placed in the program. To place a timer block in a network:
Position the cursor where you want the timer block to appear.
The blocks are shown in the pane on the left side of the window Expand the
"Libraries" entry and then expand the "Standard Library" folder. Expand the
"System Function Blocks" folder. Note that the first six entries (SFB0 to SFB5)
are the normal timer and counter blocks.
Double-click on the "SFB4 TON" line. A TON timer is added to the current rung.
SiemensStep7_S7_300.doc
Step7_300 - 9
Now, add a symbol for the timer. Start the symbol editor by selecting Options |
Symbol Table. Note that the TON symbol with address and symbol type of SFB4
has been added.
Add a new timer symbol (e.g., "Tmr1" to the symbol column of the last line of the
symbol list. The address should be "DB1" and the data type is "SFB4." Actually,
the DB (data block) number can be any number as long it is not already assigned
as a data block. The data type must match the data type of the TON timer (SFB4,
in this case).
Save the new symbols by clicking on the disk icon in the menu bar.
Exit the symbol editor.
Now change the "???" above the TON block to the timer symbol you defined in the
previous step. Press <Enter>. You will be asked if you want to generate the data
block. Answer "Yes."
Place the logic for the IN timer input. You can add contact logic to the EN and IN
inputs. Generally, the EN input is connected directly to the power rail.
To specify the preset (PT) input, click on the PT input. Type in the preset value in the
IEC format for time.
You cannot connect a coil to the Q output. You can connect it to a symbol.
Since we added a SFB to the program, we must download it from the project manager
window (that shows the program blocks). Save OB1 and then exit from the LAD/STL/FBD
editor. Click on the download icon. You will need to answer "Yes" to the prompts about
overwriting blocks. You do not need to load the system data.
Re-open OB1 and observe the program operation.
4. Counters
An up-counter is SFB0. The procedure to add an up-counter is very similar to that of
adding a timer, except that the data type for the counter data block is "SFB0". To place a counter
block in a network:
Position the cursor where you want the counter block to appear.
Double-click on the "SFB0 CTU" line in the "System Function Blocks" folder. A
CTU counter is added to the current rung.
Now, add a symbol for the counter. Start the symbol editor by selecting Options |
Symbol Table. Note that the CTU symbol with address and symbol type of SFB0
has been added.
Add a new counter symbol (e.g., "Cnt1" to the symbol column of the last line of the
symbol list. The address should be "DB3" and the data type is "SFB0." Actually,
the DB (data block) number can be any number as long it is not already assigned
as a data block. The data type must match the data type of the CTU counter
(SFB0, in this case).
Save the new symbols by clicking on the disk icon in the menu bar.
Exit the symbol editor.
SiemensStep7_S7_300.doc
Step7_300 - 10
Now change the "???" above the CTU block to the counter symbol you defined in the
previous step. Press <Enter>. You will be asked if you want to generate the data
block. Answer "Yes."
Place the logic for the CU and R counter inputs. You can add contact logic to the EN,
CU, and R inputs. Generally, the EN input is connected directly to the power rail.
To specify the preset (PV) input, click on the PV input. Type in the preset value as an
integer.
You cannot connect a coil to the Q output. You can connect it to a symbol.
To display the CV while the program is executing, you must connect it to an INT
variable.
Since we added a SFB to the program, we must download it from the project manager
window (that shows the program blocks). Save OB1 and then exit from the LAD/STL/FBD
editor. Click on the download icon. You will need to answer "Yes" to the prompts about
overwriting blocks. You do not need to load the system data.
Re-open OB1 and observe the program operation.
SiemensStep7_S7_300.doc
Step7_300 - 11
To close the symbol editor, click on the red "X" in the upper right corner.
F. INPUT/OUTPUT FORCING
For inputs, the force function allows one to override the actual status of external inputs by
forcing individual discrete inputs to be ON or OFF. Input forces are written to the input image
table and have no effect on the actual input. The value in the force table overrides the actual
input. For example, if I0/1 is forced to 1 (ON), it will appear in the input image and ladder logic
as 1, regardless of the actual status of the device.
For outputs, the force function allows one to override the processor logic and force
individual discrete outputs to be ON or OFF. Output forces are written directly to the output
device and do not appear in the output image table. The value in the force table overrides the
value in the output image. For example, if Q4/2 is forced to 1 (ON), the actual output will be
ON, regardless of how it appears in the ladder and output image table.
Note: Enabling or disabling forces can result in sudden machine movement, possibly injuring
personnel. Applying of removing forces while forces are enabled takes place immediately,
with no prompt for confirmation. USE EXTREME CAUTION WHEN USING FORCES!
SiemensStep7_S7_300.doc
Step7_300 - 12
Note: for the S7-300 PLC, discrete outputs cannot be forced.
To force discretes, the Force Values Display must be invoked. The individual inputs or
outputs are forced from this display. To force values:
From the Step 7 manager menu, select PLC | Display Force Values. The Force
Values window pops up.
If the processor status is not displayed at the bottom, connect it to the processor by
selecting PLC | Connect to | Configured CPU.
Type the address or symbol of the discrete input to be forced in the table.
To force a discrete,
Type the force value ("1", "0", "true", or "false") in the Force Value column.
Right-mouse the force value and select Force.
When prompted if you want to continue, answer "Yes."
To remove a force
Right-mouse the force value and select Remove Force.
When prompted if you want to continue, answer "Yes."
The entry is deleted out of the table.
If a discrete is forced, a red "F" will appear in the first column of the Force Values
display. A forced discrete in a monitored program will appear with a yellow highlight.
G. IMPORTING/EXPORTING SYMBOLS
1. Importing Database from DIF file
To import an address/symbol/description database from a .DIF (data interchange format) file:
First open the symbol table. Open an organization block (usually OB1). From the menu
select Options | Symbol Table.
From the symbol table menu select Symbol Table | Import.
Select the appropriate file. Click on Open.
A pop-up will remind you that you cannot undo the action. Click on Yes to continue the
import.
The symbols are imported.
A pop-up will appear with a summary of the errors (if any). If you click on Yes, a log of
the import operation will be displayed. If there are no errors, you should click on No.
2. Exporting Database to DIF file
To export an address/symbol/description database to a .DIF (data interchange format) file:
First open the symbol table. Open an organization block (usually OB1). From the menu
select Options | Symbol Table.
From the symbol table menu select Symbol Table | Export.
Select the appropriate file name. Click on Save.
The symbols are exported to the file.
SiemensStep7_S7_300.doc
Step7_300 - 13
SiemensStep7_S7_300.doc
Step7_300 - 14
SiemensStep7_S7_300.doc