Manipulating individual statusbits in Step7

Bakkei

Member
Join Date
May 2006
Location
Arnhem
Posts
63
I'm looking for a decent way to set independent statusbits of the statusword in simatic Step7. (CC0 - CC1 - OV - BR - etc...)

When I want to set CC1 I use:

L 5
L 5
-I

When I want to reset CC1 I use

L 5
L 5
+I

I don't think this is the cleanest way to do this, so how do I adress the indepedent bits? I'm also looking for a way to evaluate statusbits without the jump instructions (JMZ, JBI, ...)
 
L STW - loads the status word into the accumulator
T STW - transfers the accumulator into the status word

For the S7-300 series CPUs, the statement L STW does not load the FC, STA, and OR bits of the status word. Only bits 1, 4, 5, 6, 7, and 8 are loaded into the corresponding bit positions of the low word of accumulator 1.
 
Last edited:
I go along with S7Guy, WHY????

I don't manipulate status bits, the logic I write does, I then react to the resulting status bits.

Why evaluate the status bits if you don't want to react, if you do want to react you have the instructions mentioned to do the reacting.

Mystery to me. :confused:
 
SimonGoldsworthy said:
L STW - loads the status word into the accumulator
T STW - transfers the accumulator into the status word

For the S7-300 series CPUs, the statement L STW does not load the FC, STA, and OR bits of the status word. Only bits 1, 4, 5, 6, 7, and 8 are loaded into the corresponding bit positions of the low word of accumulator 1.

Thanks Simon. That did the trick. For all the others that are breaking their head over why I want to do this:
I have to write a very quick shift register for 64 bits. For this I use RLDA. The bit that is shifted in has the value of CC1:

// Setting/Resetten CC1 according to #NewFirstBit

L STW
A #NewFirstBit
JC Set1

L W#16#FF7F
AW
JU Writ

Set1: L W#16#80
OW

Writ: T STW

// Shifting bits in PositionArray[1..64]

L P##PositionArray
LAR1
L DID [AR1,P#0.0]
CAD
RLDA
CAD
T DID [AR1,P#0.0]
L DID [AR1,P#4.0]
CAD
RLDA
CAD
T DID [AR1,P#4.0]
 
useful, shall have to remember that.

The CAD instruction does not reverse the bits in the bytes though, does it, just reverses the 4 bytes.
 
Peter Nachtwey said:
I think this is what is Bakkei wants to do. It makes sense to me otherwise he must shift the bits a byte at a time.

Exactly. The bit of code I posted above is tested.
 
Here's an alternative implementation that doesn't manipulate the status word. It uses SLD 1 for the first 16 bits (which puts a zero in the first bit) and then if the NewFirstBit is a one it uses the + 1 instruction (which doesn't modify CC1) to set bit 0 of the result.

Code:
	 L	 P##PositionArray
	 LAR1 
	 A	 #NewFirstBit
	 JC	sh1
sh0:	 L	 DID [AR1,P#0.0]
	 CAD 
	 SLD 1
	 JU	sh
sh1:	 L	 DID [AR1,P#0.0]
	 CAD 
	 SLD 1
	 +	 1
sh:	 CAD 
	 T	 DID [AR1,P#0.0]
	 L	 DID [AR1,P#4.0]
	 CAD 
	 RLDA 
	 CAD 
	 T	 DID [AR1,P#4.0]
 
Nice clean solution Simon. It's possible to make it even sleeker:

Code:
     	 L	 P##PositionArray
     	 LAR1 
     sh0:	 L	 DID [AR1,P#0.0]
     	 CAD 
     	 SLD 1
     	 A	 #NewFirstBit
     	 JC	sh1
     	 JU	sh
     sh1:	 +      1
     sh:	 CAD 
     	 T	 DID [AR1,P#0.0]
     	 L	 DID [AR1,P#4.0]
     	 CAD 
     	 RLDA 
     	 CAD 
     	 T	 DID [AR1,P#4.0]


Now the code is whopping 5 instructions shorter than my original version. Cool.
 
Last edited:
While taking a shower I realised we know the bitadress of the first element of the array, so you can do this:

Code:
   L	 P##PositionArray
  LAR1 
        
  L	 DID [AR1,P#0.0]
  CAD 
  RLDA
  CAD
  T	 DID [AR1,P#0.0]
        
  L	 DID [AR1,P#4.0]
  CAD 
  RLDA 
  CAD 
  T	 DID [AR1,P#4.0]
        
  A	 #NewFirstBit
  =	 PositionArray[1]

No more jumps. Saved 7 instructions in total. Ashamed to say: In the end the people who thought you shouldn't have to mess with the statusword were right. Still nice to know there were a few lessons to be learned here.
 
Last edited:
Bakkei said:
While taking a shower I realised.....

Those shower type flashes of inspiration are great first thing in the morning when you can implement your idea straight away. Not so nice when you have one of those moments after leaving a customer site and boarding a plane for a 10 hour flight - very frustrating !
 
SimonGoldsworthy said:
Those shower type flashes of inspiration are great first thing in the morning when you can implement your idea straight away. Not so nice when you have one of those moments after leaving a customer site and boarding a plane for a 10 hour flight - very frustrating !

Indeed! Even more so if it isn't the first time something like that happens...

Right now I have a problem with the code above when I use it in a multiple instance FB. The pointer then always points to the array of the first instance...
 
Bakkei said:
Indeed! Even more so if it isn't the first time something like that happens...

Right now I have a problem with the code above when I use it in a multiple instance FB. The pointer then always points to the array of the first instance...

And solved (thanks to a tip from a collegue). I present the multi-instance capable 64 bit shift register. (You need to add the value of AR2 for the offset)

L P##PositionArray
LAR1
TAR2
+AR1
L DID [AR1,P#0.0]
CAD
RLDA
CAD
T DID [AR1,P#0.0]

L DID [AR1,P#4.0]
CAD
RLDA
CAD
T DID [AR1,P#4.0]

A #NewFirstBit
= PositionArray[1]
 

Similar Topics

Using a 1769-L16ER-BB1B We are receiving a DINT from an external device. Then changing the sign using a SWPB order mode REVERSE dest Dint_2 same...
Replies
7
Views
3,060
I have a barcode scanner reading bin labels and handing a string to an Laser Guided vehicle to place the bin in its appropriate location based on...
Replies
1
Views
1,266
Hello, Have aoi written in Ladder to pass in and out string variables. String VAriables that interact with PLC program are declared as InOut...
Replies
5
Views
4,311
Hello everyone. I have a quick question regarding dates in Structured text. What I´m trying to do is to take the current date, add/subtract days...
Replies
3
Views
1,624
Hi, I was wondering if you could help. I am using a Micrologix 1400 where I have an 11 digit number loaded in a L# data type (doubleword). This...
Replies
5
Views
3,013
Back
Top Bottom