Step7 CPU300 question

laura

Member
Join Date
Jul 2006
Location
Torshavn
Posts
79
Hello there.

I'm not familiar with programming in STL, I usually use Ladder.o_O

For my aplication, I guess I have to program in STL, but I dont know how.

The thing is: I want to move values from my PIW752 into a datablock every 5 seconds. I do not want the values in the datablock to be overwritten, so I was thinking like this
DB1.DBD[MD10], where MD10 will be added with the value 4 before every move. So the first time the values will be stored in DB1.DBD0, and after 5 seconds in DB1.DBD4 etc. etc..

Can someone please guide me through this ?

I have read some topics about it, but Im just not getting it.

Thanks

Laura
 
For example, DB size is limited to 16 kbytes for CPU315. You store dword - 4 bytes - every 5 seconds. 4096 values will be stored approximately 6 hours. What you want to do after this? It's first question.
 
Also PIW is 2 bytes, why do you want to save every 4 bytes, are the other two bytes used for an index number or something.

Sounds like it's something you want to save to a database rather than in the PLC.

For a bit of help on the pointer, you would start at 0, then SLD 3 before transferring to MD10 (in your example), as the offset address takes the byte/bit address format.

So you could use MW8 to store the offset, each time after the initial transfer do

L MW8
L 2 (or 4)
+I
T MW8
SLD 3
T MD10

The indirect example you put would be correct then.
 
FUNCTION_BLOCK "Buffer"
TITLE =
VERSION : 0.1


VAR_INPUT
Value : WORD ;
END_VAR
VAR
BuffCnt : INT ;
Value0 : WORD ;
Value1 : WORD ;
Value2 : WORD ;
Value3 : WORD ;
Value4 : WORD ;
Value5 : WORD ;
END_VAR
VAR_TEMP
SaveAR1 : DWORD ;
Offset : DWORD ;
END_VAR
BEGIN
NETWORK
TITLE =

L #Value;
L 1;
+I ;
L 200;
TAK ;
>I ;
JC lbl1;
L 0;
lbl1: T #Value;
NETWORK
TITLE =

L #BuffCnt;
L 1;
+I ;
L 5;
TAK ;
>=I ;
JC lbl;
L 0;
lbl: T #BuffCnt;
ITD ;
SLD 4; // Word offset
T #Offset;
NETWORK
TITLE =
//Saving of AR1 contents.
TAR1 ;
T #SaveAR1;
NETWORK
TITLE =

L P##Value0;
LAR1 ;
L #Offset;
+AR1 ;
L #Value;
T DIW [AR1,P#0.0];
NETWORK
TITLE =

L #SaveAR1;
LAR1 ;
END_FUNCTION_BLOCK

This example uses DI for storing of 5 values. Network 1 can be removed - it is used to change Value only.
 
For those who wish to keep as much as possible in ladder, I use a function which allows read/write access to an array of data starting at any offset in a global DB. Just call the function in ladder and fill in the parameters. (To generate the FC cut/paste the code into a STL source file in the source folder and then compile it - change the number of the FC if it clashes with one you already have)

Code:
FUNCTION FC139 : VOID
TITLE =
//Access an array of real values 
//
//Address is iIndex  + iStartOffset in dbDataBlock
//
//If bWrite is true write rDataIn to address.
//Always return value at address.
//
VERSION : 0.2
VAR_INPUT
  bWrite : BOOL ;   //True to write value in to data
  iIndex : INT ;	//Index in to data
  iStartOffset : INT ;  //Start of data area
  rDataIn : REAL ;  //Value to transfer in to the data
  dbDataBlock : BLOCK_DB ;  //Block that holds the data
END_VAR
VAR_OUTPUT
  rDataOut : REAL ; //Value read out of data
END_VAR
BEGIN
NETWORK
TITLE =Generate the pointer
	  L	 #iIndex; 
	  +	 -1; 
	  SLD   2; // index * 4 for double words
	  L	 #iStartOffset; 
	  +I	; // offset + ((index - 1) * 4)
	  SLD   3; // Make in to a pointer
	  LAR1  ; // put pointer in to address reg. 1
	  OPN   #dbDataBlock; // Open the block where the data is being held
NETWORK
TITLE =Check the logic of what to do
	  AN	#bWrite; 
	  JC	get; // so just get
	  ju	set; 
NETWORK
TITLE =Set the data
set:  L	 #rDataIn; 
	  T	 DBD [AR1,P#0.0]; // Store the value @ DBD [p#(offset + (index * 2))]
	  JU	get; 
NETWORK
TITLE =read out the data
get:  L	 DBD [AR1,P#0.0]; // read the value
	  T	 #rDataOut; // output the data
	  SET;
	  SAVE;
END_FUNCTION
 
Simon, I think your example is really good thing. Indirect addressing isn't simple especially for LAD people. They don't need knowledge of it in most cases. "Black boxes" with IO variables is a good choise for them.
 
Thank You very much.

Sorry, I have messed it up. I want to save words as words in a datablock and not as DW.

What does SLD 3 means ?
 
Hi friends.

I dont even know how to make the recommended FC and compile it.

Now I have maked it all more confused, by telling You something wrong, about my words and dwords. Im sorry.

Every 5 seconds, I want to move the value from PIW752 to a datablock, without overwriting.

How can I make it easy ?

(Sometimes I wish I never switched over to LADDER from STL, because I seem to have forgotten all about it ).
 
Laura

SLD 3 means Shift Left Doubleword 3 bits..

A pointer (which is what you need for indirect addressing) is made up of 32 bits.


0000 0000 0000 0000 0000 0000 0000 0000



There's the 32 bits above. The three bits on the far right make up the 'bit' part of the address and the 16 bits to the left of those make up the 'byte' part of the address. So.. if you wanted to address M10.5 then the 3 bits on the far right would be 101 (ie 5 in binary).

Because you want to load a 'byte' address in your pointer, you load in the number and then SLD 3 (ie. shift the bits to the left by 3) this means that whatever number you loaded in gets moved into the 'byte' part of the pointer and out of the 'bit' part of the pointer...

Hope that ridiculously convoluted explaination makes some sense to you..

;-)
 
laura said:
Every 5 seconds, I want to move the value from PIW752 to a datablock, without overwriting.

I think the main worry about how you are trying to achieve this (as has been mentioned earlier) is the bit about "without overwriting"..

Sooner or later you are going to have to overwrite something cos otherwise you are just going to fill the datablock...

Have you plans for how this is going to be dealt with?
 
If you describe the application we might have a better idea about what to do when the DB is full up e.g. switch to another DB, start at the beggining of the DB ?
 
I dont even know how to make the recommended FC and compile it.
1. In the sources folder within your project, Right click and insert new STL Source.

2. Open your new source by hitting Enter.

3. Copy and Paste the code from within this thread.

4. Click on the Compile button.

5. After a successful compile the block is ready for use in the Block Folder

SLD 3 Instruction

SLD " shift left Doubleword (32bit)

shifts the whole contents of the Accumulator left, in this case 3 places.

Press F1 on the instruction within the LAD/STL/FBD editor for an example of this.

Hope this helps

STL
 
Thank You so very much.

Im slowly beginning to sense a bit of it. But I still cant think of the STL code for saving the values in the datablock without overwriting.

Maybe if I read it another 1000 times, I will understand it.
 
There is a function in the ti library for first in first out table
use it will handle everything including the addressing
 

Similar Topics

This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
130
When you download a DB, the values get overwritten by what is in the "actual" column in offline DB. Does this happen at the start of the PLC...
Replies
6
Views
141
Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
127
Hi all, I am trying to convert RSLogix 5000 program to Step7. I need to bit shift left my array of double integers for tracking the product on...
Replies
2
Views
519
I have a word in some DB which I want to load to AR1 and use as a pointer. In order to do this I need to write L DBxy.DBW xy SLD 3 LAR1 I...
Replies
3
Views
533
Back
Top Bottom