S7 STL:Indirectly Increment a Register

STL???

Member
Join Date
Sep 2005
Location
UK
Posts
879
Hi Everyone,

I'm trying to get to grips with siemens Statement List, basically im trying to display the contents of Memory bits M300.0(Step 0) to M305.7(Step 47)in DB or Memory Byte to display on a Simatic HMI. So when say m300.1 is displayed 1 is entered in the Storage Byte etc, as the current step active.

This is the current Code in the controller which seperates each Byte and increments it every Positive edge of the signal (Once energised it is latched Until end of Sequence.


A(
A M 300.0 //Step 0
FP M 10.0
O(
A M 300.1 //Step 1
FP M 10.1
)
O(
A M 300.2 //Step 2
FP M 10.2
)
O(
A M 300.3 //Step 3
FP M 10.3
)
O(
A M 300.4 //step 4
FP M 10.4
)
O(
A M 300.5 //Step 5
FP M 10.5
)
O(
A M 300.6 //Step 6
FP M 10.6
)
O(
A M 300.7 //Step 7
FP M 10.7
)
)
JNB M001
L MW 120
L 1
+I
T MW 120
M001: NOP 0



What i was thinking was something along these lines using the Loop Instruction along with this Code:

L 5
TOP:T #LOOP_COUNT //Temp Byte
SLW 3 //Enter Byte Area
LAR1 //Load into Address Register 1
L MB[AR1,P#300.0] //Range MB305 -> MB300
// Im Stuck Here??????
//
L #LOOP_COUNT
LOOP TOP // -1 until 0 Reached




Ive tried various Instructions, But im getting anywhere fast, Does anyone have any suggestions on achieving this?

Any help or critique would be gladly recieved

Thanks
 
Will there always be at least 1 bit on in m300.0 through m305.7 ?
If so, then instead of accessing bytes, set the count to 48 and scan for bits. As soon as you find a bit, you can jump out of the loop and set your step number to the loop_count-1

e.g. (I have cut/pasted your code and modified it but I have not tested it as I have no access to a simulator at present)

L 48

TOP:T #LOOP_COUNT //Temp Byte
LAR1 //Load into Address Register 1

A m[AR1,P#300.0] //Range MB305 -> MB300
jc bset

L #LOOP_COUNT
LOOP TOP // -1 until 0 Reached..(should never happen though)

bset: L #Loop_count
+ -1
T MW120
 
Hi Simon,
Thanks for that,I'll try it on the Test Rig tomorrow and see how i get on.
Will there always be at least 1 bit on in m300.0 through m305.7 ?
If so, then instead of accessing bytes, set the count to 48 and scan for bits. As soon as you find a bit, you can jump out of the loop and set your step number to the loop_count-1

Yes - There should be as it is currently programmed. Basically the process it supervises is heavy interlocked and in a timeout situation in Automatic, all step bits are zero'd. Due to warranty issues that cannot be changed,But fault finding can be difficult so one of our personal mapped the auto bits to the Memory Area and latched them so you can trace which step had faulted.

I wish to change the Mapping using BLOCK MOVE or FILL,which should be ok and Display all this Data to a Screen.

I thought this was a good Indirect learning exercise but quickly found out my limitations! still if you keep doing things you know - you dont learn

Thanks again.
 
Fast, faster, fastest

Simon has present the obvious brute force way of find the index of a set bit. I would load the first first 32 bits as a DWORD or DINT and test if it is zero. If so I would add 32 bits to my index and then get the next DWORD.

Actually, for huge arrays of bits I would OR two consecutive DWORDS or DINTS at a time and add 64 to the index if 0. If one I would divide and conquer until I got down to the byte with the bit that is set. Then I would scan like Simon suggested.

What happened to the ENCODE and DECODE instruction? Doesn't the S7 have one? I looked and couldn't find one.

BTW, I just got a new STEP7 5.3, SCL 5.3, CP5512,the USB to MPI adapter and a new S7315. I can now help more with S7 questions than in the past two or three years.
 
Please find below tested code to replace code from previous post #2:

Code:
	 L	 48						//loop count for 48 bits
TOP: T	 #Loop_count			   //Temp Byte
	 +	 -1						//correct bit address ready for
	 LAR1							//Load into Address Register 1
	 A	 M [AR1,P#300.0]		   //Range MB305 -> MB300
	 JC	bset					  //when bit is set then exit loop
	 L	 #Loop_count
	 LOOP TOP						// -1 until 0 Reached..(should never happen though)
 
bset: L	 #Loop_count			  //get current count
	 +	 -1						//adjust for bit position
	 T	 MW 120					//into result
 
Hi Guys,

Thank you Simon for the Updated Code and thanks Peter & Simon for sharing your vast knowledge of S7 with me. Ill try what you suggested and i'm sure ill be back with more questions! :unsure:

Best Regards.
 
Nice piece of code from Simon.o_O
But I dare to "improve" it a little bit.





Code:
[indent]L	 48 

 
 

[/indent]TOP:	+	 -1[indent]LAR1						 

 
A	 M [AR1,P#300.0]		 
JC	bset					 
LOOP TOP						
 

[/indent]bset:	 +	 -1					 

 
	 T	 MW 120

Harder to follow but more efficient.:)
 
Looks like it became hard to follow for myself as well. :sick:
So some corrections down below.


Code:
	 L	 48 
TOP: LAR1						 
	 A	 M [AR1,P#299.7] 
	 JC	bset					 
	 LOOP TOP						
bset: + -1
	 T	 MW 120










 
jacekd: Won't this code keep on looping if it doesn't see a 1 somewhere?

Simons code stops after 48 loops even if there is no 1 somewhere.

Cheers
Borte
 
Well, I didn't test this specific one but it should not.
From Step7 online manual: "LOOP <jump label> (decrement ACCU 1-L and jump if ACCU 1-L <> 0)"
 
I think you're right. I didn't read the code properly. :sick:

You have just removed the L and T commands since your not changing the ACCU1 inside the loop.

Cheers
Borte
 

Similar Topics

i am new to simatic manager and i am trying to figure what this part do in the code : A I 5.6 = DB50.DBX 4.6...
Replies
3
Views
125
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
201
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
308
First off thank you in advance. Second I am very new to STL. I am trying to build a counter that has one count up and 23 count down options. Am...
Replies
6
Views
362
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
649
Back
Top Bottom