Wednesday, September 30, 2015

Data Blocks in Simatic Step 7 Siemens




Data Blocks (DBs) can be used by your program to save data in the CPU. Your hard disk contains up to 8 Kbytes(8192Bytes) space. There are two types of data blocks. Global DBs, where all OBs, FBs and FCs read all saved data or can even write in the DB and local instance DBs, which are assigned a particular FB. In the DBs, different data types (e.g. BOOL or WORD) can be saved in arbitrary order. This structuring of a DB follows through input in a table with the tool LAD, STL, FBD - S7 Block Programming.
In the program structure from STEP 7, data blocks are found as follows:
Figure 1 Data Blocks

Data blocks are generated and opened like program blocks in the tool LAD, STL, FBD: Programblocks. They serve e.g. for the saving of data and system states.
Figure 2 Addressing Data elements

Before create Data Blocks (DBs), we must understand about addressing Data in Simatic Step7. Figure 2 show the addressing data elements in Simatic Step7. There is 3 elementary data type:
  • Bit data Type (Bool, Byte, Word, DWord, Char)
  • Mathematical data type (Int, Dint, Real)
  • Time types (s5Time, Time, Date, Time_of_Day)
In the figure 2, 1 box represent 1 Bit memory. 1 Bool have length 1 Bit, and 1 Byte have length 8 Bit. For more detail you can see in table below

Type
Size in Bit
Range and Number Notation
Bool
1
True/False
Byte
8
B#16#0 to B#16#FF
Word
16
W#16#0 to W#16#FFFF
DWord
32
DW#16#0000_0000 to DW#16#FFFF_FFFF
INT
16
-32768 to 32767
DINT
32
-2147483648 to 2147483647
Real
32
Upper Limit +/- 3.402832e+38
Lower Limit +/- 1.175495e-38
S5Time
16
S5T#0H_0M_0S_10MS to
S5T#2H_46M_30S_0MS and
S5T#0H_0M_0S_0MS
Time
32
T#24D_20H_31M_23S_648MS
to
T#24D_20H_31M_23S_647MS
Date
16
D#1990-1-1 to
D#2168-12-31
Time_Of_Day
32
TOD#0:0:0.0 to
TOD#23:59:59.999
Char
8
A, B, etc.

How to Generate Data Blocks (DBs) in Simatic S7-PLCSim


Step 1: Create New Project

Follow Step 1 to Step 3 of the article about Learning PLC Programming With SIMATIC S7-PLCSIM
Start from  Step 1: Setup PG/PC Interface, Step 2: Create New Project and Step 3: Add Station Object

Step 2: Insert S7 Program

Insert a new S7-Program, in INSERT menu select PROGRAM and then S7 PROGRAM
Figure 3 Insert S7 program

Step 3: Insert Data Block

Highlight the folder Block
Figure 4  Folder Block

Insert Data Block, in INSERT menu select S7 Block and then Data Block
Figure 5 Insert Data Block

Enter the number for Data Block in Name and type (in this case I set DB1), choose Shared DB so DB can accessed by another program. For Symbolic Name and Symbolic Comment is optional. Accept with OK
Figure 6 Data Block

Step 4: Create Data variable

Open the data block DB1 with double click or open object.
Figure 7 Data Block DB1

The Data Block is generated with a symbol Name. The Type, an Initial value as well as aComment (optional) are entered.The address is automatically generated and cannot be altered. In Data
Figure 8 Program Block for Data Block

Fill the Data Block like figure below, Click save for save all changes.
Figure 9 Data Block

Step 5: Store data into Data Block

Now we create program to write data to Data Block, in simatic manager double click on OB1. When Properties – Organization Block Window open choose LAD in Created in Language. Click OK.
Figure 10 Open program Block

Figure 11 Organization Block Properties

Expand folder counter in library, select S_CU function and drag to, main window.

Figure 12 Insert S_CU Function

Figure 13 Insert S_CU Function

Function Description

Parameter
Data Type
Memory Area
Description
C no
Counter
C
Counter Identification Number
CU
BOOL
I,Q,M,L,D
Count up input
S
BOOL
I,Q,M,L,D
Set Input for Presetting counter
PV
Word
I,Q,M,L,D, or Constant
Enter Counter value as C#<value> in the range from 0 to 999
R
BOOL
I,Q,M,L,D
Reset Input
CV
Word
I,Q,M,L,D
Current Counter Value, hexadecimal number
CV_BCD
Word
I,Q,M,L,D
Current Counter Value, BCD coded
Q
BOOL
I,Q,M,L,D
Status of the Counter.

In this case, we will not use all parameter in S_Cu Function. We only use Input counter CU and Counter Value CV for store data in DB1. Create program like figure below
Figure 14 Counter Function

Step 6: Simulation

Save and close program object window. Run PLCSim with click on PLCSim icon.
Figure 15 PLCSim

And create input output variable for IB 0 (Input), C 0 (Counter), and DB1.DBW0 (Data Block).
Figure 16 PLCSim ON

Download program
Figure 17 Download Program

Run simulation
Figure 18 Run Simulation

Figure 19 Simulation Store data in DB

Set IB 0.0 to 1, and see counter in C 0 count 1 and counter store data into DB1.DBW0. Set IB 0.0 to 0 and repeat set IB 0.0 to 1 again, see the count in counter increase and store to DB1.DBW0.

Step 7: Data View Mode in Data Block

Double click on DB1 in Simatic manager, to open DB1 editor
Figure 20 Open DB1

In VIEW menu select Data View,
Figure 21 Data View

Select Monitor mode
Figure 22 Monitor mode

And check data in DB1 in PLCSim and Program Object Data Block, it must be same.
Figure 23 Data Block Monitor

Download project file click here
Video Demonstration: Data Blocks in Simatic Step 7 Siemens


Labels:




Newer Post Older Post Home

You may also like these ebook:

Get Free PLC eBook directly sent to your email,
and email subscription to program-plc.blogspot.com




We hate SPAM. Your information is never sold or shared with anyone.

Your Email Will Be 100% Secured !

Your email is stored safely on Google FeedBurner