Step 7 SCL - help

lostcontrol

Lifetime Supporting Member
Join Date
May 2009
Location
NeverSayNever
Posts
1,069
Hi,
Can someone translate this for me please, or at least help to explain what the instructions mean?

Code:
      SET   
      SAVE  
      =     L      2.1
      L     DB1.DBW  1
      T     #inValue
      L     1000
      TAK   
      ==I   
      T     LW     4
      JC    lblx1
      JU    lblx2
lblx1: L     100
      T     #outResult
      JU    lblx0
lblx2: L     2000
      L     LW     4
      ==I   
      JC    lblx3
      JU    lblx0
lblx3: L     200
      T     #outResult
      JU    A7d0
lblx0: CLR   
      A     L      2.1
      SAVE  
      BE


Based on what I know of the application, I know that 'L 200 T #outResult' is setting #outResult to 200 (& 100 earlier).
What I cannot see exactly, is how the test is done? Is this a Select/Case type thing?

I can follow that the #inValue is checked/loaded & if equal to 1000, then set #outReslt to 100 & exit the case (JU lblx0 ?)


The lblxx are just jump labels.?


How far off am I?




Cheers 🍻
 
Is this from 300 or 400 and it won't convert directly anymore to FBD or ladder?



My SCL is rusty, but





SET // set RLO resulto to "1"
SAVE // save RLO bit to BR (binary result)
= L 2.1 // save to local temp bit 2.1

L DB1.DBW 1 // load int value from DB1.DBW0 to accu 1
T #inValue // move to stat area ( #invalue) or temp area?
L 1000 // load constant to accu 2
TAK // exchance accu1 and accu2
==I // if equal
T LW 4 // move accu2 to temp area LW4 (moving all time?)


JC lblx1 // jump to label lblx1, if compare is equal to 1000. (Note, this is not needed as lblx1 is next command if result is 1000)

JU lblx2 // jump to label lblx2, (if compare is not equal to 1000)



lblx1: L 100 // load 100
T #outResult move 100 to out result
JU lblx0 // jump to label lblx0 if BR is not "1" (if compare is not equal to 1000)


lblx2: L 2000 // load 2000
L LW 4 // Load 4
==I compare accu1 to accu2 (if db1.dbw1 = 2000)
JC lblx3 // jump if compare is "1"
JU lblx0 // jump if compare is "0"


lblx3: L 200 // load 200
T #outResult //move value to variable outresult
JU A7d0 //jump to a7d0 label


lblx0: CLR // set RLO to "0"
A L 2.1 // load local temp bit 2.1 (allways "1" state?)
SAVE // save bit status to BR (EN0 output ="1"
BE // Block end


(Why CLR and then saving "1" to same bits are even needed?






All it does

if compare is 1000, then move 100 to output
if compare is 2000, then move 200 to output and execute rung with label A7d0 (jump over clear command on end)


Does this make any sense?
 
Last edited:
To put it simply:

If DB1.DBW1 = 1000 Then
#outResult = 100
Elseif DB1.DBW1 = 2000 Then
#outResult = 200
Endif

The ==I instruction compares ACCU1 and ACCU2 (accumulators) as 16-bit integers. Every L (Load) instruction puts the value into ACCU1, and the value that was in AcCu1 moves over to ACcU2. TAK swaps the accumulator values around, which in your case puts the value of DB1.DBW1 back to ACCU1 and 1000 into ACCU2.

JC is jump conditional (RLO = 1), JU is jump unconditional. lbl... are your labels.
 
Thanks for the replies!!


Looks like Lare started writing his response long before me!

That JU A7d0 is a bit puzzling... Is this the whole block code? There is no label A7d0 in the posted code.
Opps, that was me copy/paste to make it more readable.
I am correct in that they are just labels ?

I guess the main thing I need to understand/learn, is the accumulators etc
So every time 'L' is used, the value is copied down the accumulators?
How many are there?
 
S7-300 has 2 Accumulators (except CPU 318-2 has 4)
S7-400 has 4 Accumulators

The L instruction only copies the operand into ACCU1, and the contents of ACCU1 are moved to ACCU2.

ahh, ok. Thanks!
So every time ACCU1 is loaded, the value that was in ACCU2 is discarded.?
 
ahh, ok. Thanks!
So every time ACCU1 is loaded, the value that was in ACCU2 is discarded.?


Yes.

L command Loads first contents of ACCU1 into ACCU2. Then it loads data to ACCU1.


ACCU contents can swapped so there is no need to use temp variable if data which is on accu2 is needed.(On your posted code with TAK command.)



For codind with STL and SCL you should study different meaning of BR, RLO and commands which needs RLO = 1 state at least.


http://www.plcdev.com/siemens_s7_status_word


https://support.industry.siemens.com/cs/us/en/view/18735131
 
ok team, how can I do a simple comparison to check if a value is between 2x values?
I've managed to hack this together which appears to work but have no idea if it any good or not?
I think ladder is by far much easier in this instance to follow though?

L 0
T #xPosition

x11: L #inOLM_PV
L 100
>=I
JC x12
JU x21
x12: L #inOLM_PV
L 200
<=I
L 10
T #xPosition
JC xEND


x21: L #inOLM_PV
L 201
>=I
JC x22
JU x31
x22: L #inOLM_PV
L 300
<=I
L 20
T #xPosition
JC xEND



x31: L #inOLM_PV
L 301
>=I
JC x32
JU xEND
x32: L #inOLM_PV
L 399
<=I
L 30
T #xPosition
JC xEND



xEND: L #xPosition
T #Position


It seems the help is quite good in explaining some things!
 

Similar Topics

Hello, what is wrong with the program like below to write 100 to DB81.DW24? %DB81.DW(IDX :=24) := 100; Or how should I write the program...
Replies
16
Views
5,009
I have made a small FB in SCL, in this blok i have to transfer to an array in a certan position, but I can't get it to work. It goes as follows...
Replies
6
Views
6,525
Help!! From reading previous threads, I know that the best way to index an array is using SCL. I have the SCL editor, I'm just not sure where to...
Replies
3
Views
4,236
I am logging real numbers into arrays in SCL. I am using these for buffer bit trends in WinCC Flexible. I need to cut some digits out. Some of the...
Replies
15
Views
13,193
Hi guys, i was trying to make a program in simatic step 7 with which i could with the useing of a switch choose between automatic, manual and step...
Replies
0
Views
4,643
Back
Top Bottom