s7 shift function

darren.s

Member
Join Date
Apr 2005
Posts
46
L MW20
T # TEMP
L 1
SLW
SRW 1
T LB2
in the above code the SRW 1 shifts the word one bit to the right.
SLW is shift word left if there is no number present is this function doing anything. or is it shifting a whole byte.
 
Last edited:
The SLW is not doing anything. S7 lets you call the shift instruction without a value (i.e. shift 0), probably so it can handle indirect shift values such as SRW [MW20].
 
SLW instruction used in this fashion shifts ACCU1-L by value in ACUU2-L-L.
So in this case "1" is moved to the left by value in MB21.
 
Directly from Siemens help on SLW:

SLW (shift left word) shifts only the contents of ACCU 1-L to the left bit by bit. The bit places that are vacated by the shift instruction are filled with zeros. The bit that is shifted out last is loaded into the status word bit CC 1. The number of bit positions to be shifted is specified either by the address <number> or by a value in ACCU 2-L-L.

SLW <number>: The number of shifts is specified by the address <number>. The permissible value range is from 0 to 15. The status word bits CC 0 and OV are reset to zero if <number> is greater than zero. If <number> is equal to zero, then the shift instruction is regarded as a NOP operation.

SLW: The number of shifts is specified by the value in ACCU 2-L-L. The possible value range is from 0 to 255. A shift number >16 always produces the same result: ACCU 1-L = 0, CC 1 = 0, CC 0 = 0, and OV = 0. If 0 < shift number <= 16, the status word bits CC 0 and OV are reset to 0. If the shift number is zero, then the shift instruction is regarded as a NOP operation.

Cheers
Borte
 
Just a quick note, you appear to be using local data referenced by variable name "#temp" and local data referenced by address "LB 2". Using an address for local data may cause you problems if you re-order your local data and then "forget" to update what LB 2 is actually referencing. I would recommend using named temporary local data. (Of course if the code has been produced using ladder, the editor will use local data referenced by address)
 

Similar Topics

Hi everyone im a student from mexico and i have a problem using the ladder function BSR AND BSF (BIT Switch left and right), I use connected...
Replies
3
Views
2,964
Hi, I am using a color sensor to detect 4 different color labels on different boxes to direct routing to a specific location; Lane #1 - Lane #4. I...
Replies
4
Views
2,926
I'm using a siemens plc, I was wondering is there a function that I could use to transfer Floating point (REAL) to a every 1/2 hrs to a different...
Replies
12
Views
3,557
I've got a Powerflex 700 that doesn't like to get going in the mornings. This motor will run anywhere from 30 seconds to 5 minutes before it just...
Replies
3
Views
162
I am attempting to reject a bottle If the label fails. The rejection works fine at normal line speed but at low speed the rejector fires (air...
Replies
35
Views
1,148
Back
Top Bottom