Siemens STL Logic to Jump for a Bit !?

cgehlhausen

Member
Join Date
Aug 2005
Location
Reno, Nevada
Posts
9
Need to Jump to different Tasks, based on different Bits.



Need Logic like this in STL:
If Bit1 = 1, Jump to Task1

If Bit2 = 1, Jump to Task2
If Bit3 = 1, Jump to Task3
If Bit4 = 1, Jump to Task4
Else Jump to END.

Simple task, but can't seem to get that into Siemens STL (S7). Trying to get the RLO to get Set!


Tried all of these, none work:

Attempt 1
L B#16#0 // Clear Accumulator
A "Bit1" // Load Bit1
JN Task1 // Jump to Task1 if Not Zero

Attempt 2
L B#16#0 // Clear Accumulator
A "Bit1" // Load Bit1
L STW // Load Status Word to ACCU1
SRW // Shift Right Word
JN Task1 // Jump to Task1 if Not Zero

Attempt 3
L B#16#0 // Clear Accumulator
A "Bit1" // Load Bit1
L STW // Load Status Word to ACCU1
LAR1 // Load ACCU1 to ADDR REG1
SRW // Shift Right Word
JN Task1 // Jump to Task1 if Not Zero
 
In attempt #1, shouldn't you be using 'OR' "Bit1" instead of AND?

0 ANDED with anything is still zero.

When in doubt, switch to LAD, code it there, and swtich back to see how Siemens thinks it should be done.
 
Where are these bits? Just access them directly. You don't need the status word for what you are trying to do.

This would work. Just subsitute your logic for the NOP's:

Code:
	 A	 #Bit[1]
	 JC	tsk1
	 A	 #Bit[2]
	 JC	tsk2
	 A	 #Bit[3]
	 JC	tsk3
	 A	 #Bit[4]
	 JC	tsk4
	 A	 #Bit[5]
	 JC	tsk5
	 A	 #Bit[6]
	 JC	tsk6
	 BEU
tsk1: NOP 0
	 BEU 
tsk2: NOP 0
	 BEU 
tsk3: NOP 0
	 BEU 
tsk4: NOP 0
	 BEU 
tsk5: NOP 0
	 BEU 
tsk6: NOP 0
	 BEU
 
Last edited:
When using logic and the RLO, use JC or JCN

When doing comparisons use JN, JZ, JP etc.

If the bits to select your task are flag bits then your code should look something like this:

A M0.0
jc Task1

A M0.1
jc Task2

A M0.2
jc Task3

etc...

(simultaneous post with S7Guy)
 
Last edited:
rdrast said:
In attempt #1, shouldn't you be using 'OR' "Bit1" instead of AND?

0 ANDED with anything is still zero.

When in doubt, switch to LAD, code it there, and swtich back to see how Siemens thinks it should be done.

In this case, you don't need an "OR" because there is only one bool instruction. The previous "Load" instruction has no bearing on the RLO.
 
JC Doesn't work on Bits

The suggestion of:

A "Bit1"
JC Task1

Is actually the first thing I tried, then found out that JC only works on the accumulator or register, not on bits. RLO remains 0







Siemens Definition
JC Jump if RLO = 1


After the A "Bit1" code executes, the RLO is still 0, but STA is the bit that changes to 1. That's why I tried loading the Status Word and Shifting it.


But in their ultimate wisdom, Siemens has prevented that as well:






Siemens Definition
L STW (instruction L with the address STW) loads ACCU 1 with the contents of the status word. The instruction is executed without regard to, and without affecting, the status bits.


Note: 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.



Since my 4 Bits are in the bottom half of the same Word, I got it to work by using this:





L B#16#0 // Clear Accumulator


L "Word" // Load the Word
L 2#1 // Mask 1st Bit
AW // Compare 1st Bit
JN Task1 // Task1 if Not Zero

L B#16#0 // Clear Accumulator
L "Word" // Load the Word
L 2#10 // Mask 2nd Bit
AW // Compare 2nd Bit
JN Task2 // Task2 if Not Zero

L B#16#0 // Clear Accumulator
L "Word" // Load the Word
L 2#100 // Mask 3rd Bit
AW // Compare 3rd Bit
JN Task3 // Task3 if Not Zero

L B#16#0 // Clear Accumulator
L "Word" // Load the Word
L 2#1000 // Mask 4th Bit
AW // Compare 4th Bit
JN Task4 // Task4 if Not Zero

JU END // Jump Unconditionally to END


PS - The comments keep shifting left, even the Fixed System Font seems to ignore the space characters. Sorry, it's hard to read.
 
Convert LAD to STL automatically?

How exactly do you write something in LAD and have Siemens convert it to STL?

rdrast said:
In attempt #1, shouldn't you be using 'OR' "Bit1" instead of AND?

0 ANDED with anything is still zero.

When in doubt, switch to LAD, code it there, and swtich back to see how Siemens thinks it should be done.
 
It has (thankfully for me) been a while since I've had to program S7's, but in the editor window, you can switch representations with a menu selection, or (I think) with an ALT or CTRL key combination.
 
I have no idea why the JC didn't work. I have literally thousands of JC and JCN in existing code using bool instructions. Can you post an example of the code that didn't work?
 
One thing that always causes me a problem with the S7 is status of the RLO at any given point.

In your eample you showwed:


A "Bit1"
JC Task1



and said it didn't work. Depending on any logic operations you had done before this the RLO MAY have been zero. In that case ANDing "Bit1" with the RLO would still produce a zero in the RLO and the conditional jump would not have occurred.

After a while I just got in the habit of putting in a 'SET' instruction before I performed an operation like you show. This guaranteed the RLO was in the state I wanted it to bein for a valid compare. I know this is inefficient but it took away some doubt for me.

Keith
 
Keith, can you show an example? Like I say, I've never had that problem before, and I've written hundreds of thousands of lines of code. I wonder if that condition is specific to certain processors.
 
Last edited:
In case it's processor based, this is an S7 314C-2PtP.

I'll have to re-create the example, but it was just an M-bit in place of "Bit1" and a label to jump to in place of "Task1".

The RLO is definitely staying at 0, so I might try the SET.
 
Here is a snippet of code where I needed to use the SET:


A #Estop_OK
JC ESTP
L 0.000000e+000
T #Line_Speed_Cmd
BEU
ESTP: L #Desired_Speed
L #Line_Speed_Cmd
<>R
JC RUNV
L 0.000000e+000
T #Inst_Accel
SET
R #At_Break_Vel
BEU
RUNV: NOP 0




If I get to the point of comparing the line speeds I need to make sure the #At_Break_Velocity is reset if the comparison is false. I'm not a big S7 user so there is probably a better way of doing this than I did. However, it doesn't change the facts that:
A) Step7 let me enter this
B) If I don't put in the 'SET' the execution of the 'R' is contingent on the result of the '<>' above.

Since I did this, it is possible that cgehlhausen's code is set up similarly.

Keith
 
I just tried it with a 416, and it worked just as expected. Unfortunately, I don't have a 314 handy. Here is the exact code I tried:


Code:
	 A	 M	 50.0
	 JC	tsk1
	 A	 M	 50.1
	 JC	tsk2
	 A	 M	 50.2
	 JC	tsk3
	 A	 M	 50.3
	 JC	tsk4
	 A	 M	 50.4
	 JC	tsk5
	 BEU 
tsk1: AN	M	 60.0
	 =	 M	 70.0
	 BEU 
tsk2: AN	M	 60.1
	 =	 M	 70.1
	 BEU 
tsk3: AN	M	 60.2
	 =	 M	 70.2
	 BEU 
tsk4: AN	M	 60.3
	 =	 M	 70.3
	 BEU 
tsk5: AN	M	 60.4
	 =	 M	 70.4
 
kamenges said:
Here is a snippet of code where I needed to use the SET:


A #Estop_OK
JC ESTP
L 0.000000e+000
T #Line_Speed_Cmd
BEU
ESTP: L #Desired_Speed
L #Line_Speed_Cmd
<>R
JC RUNV
L 0.000000e+000
T #Inst_Accel
SET
R #At_Break_Vel
BEU
RUNV: NOP 0




If I get to the point of comparing the line speeds I need to make sure the #At_Break_Velocity is reset if the comparison is false. I'm not a big S7 user so there is probably a better way of doing this than I did. However, it doesn't change the facts that:
A) Step7 let me enter this
B) If I don't put in the 'SET' the execution of the 'R' is contingent on the result of the '<>' above.

Since I did this, it is possible that cgehlhausen's code is set up similarly.

Keith

Ok, that is a little different than what cgehlhausen is describing. He is having a problem with the JC executing. In your case, whether you need the SET is definitely processor dependent (I think you need it for the 300s, and don't need it for the 400s).
 

Similar Topics

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
675
I'm having trouble trying to convert this code to ladder, anyone able to help me? A M4.0 A M4.1 A M117.0 AN M17.7 A ( A I38.6 AN I3.7 O ( A M4.5...
Replies
8
Views
1,207
Hello, I am still new to STL. But from what I understand is the JC mnemonic should jump if RLO = 1. If we review both pictures the M0bf RLO = 1...
Replies
5
Views
1,051
Hello, I am working on a project to upgrade some old S5-100U processors. The programs are all uploaded and I don't have descriptors...ugh. Be that...
Replies
4
Views
1,167
I really struggle with STL in Siemens Step 7 Classic. I'll learn chunks, but then I don't use it enough to retain and build on the knowledge. When...
Replies
17
Views
3,216
Back
Top Bottom