Simplify some S7 STL code

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi, I have written something is STL.

In STL I'm a little beginner, so maybe, u guys can give some tips how to simplify my code or write it in an other way for some reason...


It's a positioning system.

When a certain pump starts, it has to regulate to a memorised position. When stopping the pump, 30s later, there must be a memorisation and then the system goes to neutral. That's all.



NW1:
Here I scale a measurement in 0 to 20mA Real Value. The sensor can give up to 24mA, so everything above 20mA is overflow.

NW2:
30s after stopping the pump, memorise the position and start (SET) regulation to neutral point (nw 3)

NW3:
regulation to neutral point

NW4:
regulation to memorised position when pump starts


here is the code:

NW1:
L #Turck
ITD
DTR
T #Turck_R
L 2.764800e+004
>R
= #I_Overflow
JCN OK
L 2.764800e+004
T #Turck_R
OK: L #Turck_R
L 2.764800e+004
/R
L 2.000000e+001
*R
T #Turck_mA
T #Actual_mA

NW2:
A #Pump
L S5T#30S
SF #Shuttimer
LC #Shuttimer
T #Shuttime_30s
A #Shuttimer
FN #Membit_1
S #Memorise
S #Regel_Neutraal
R #Mahlo_Enable
A #Memorise
JCN END1
L #Turck_mA
T #MEMORY
T #Memorised_mA
R #Memorise
END1: NOP 0


NW3:
A #Regel_Neutraal
JCN END2
L #Turck_mA
L #Neutral_mA
-R
L 1.000000e+001
*R
RND
DTR
L 1.000000e+001
/R
T #error_1_10e
L #error_1_10e
L 5.000000e-001
>R
= #L
L #error_1_10e
L -5.000000e-001
<R
= #R
AN #L
AN #R
R #Regel_Neutraal
END2: NOP 0


NW4:
A #Pump
FP #Membit_2
S #Regel_Memory
A #Regel_Memory
JCN END3
L #Turck_mA
L #MEMORY
-R
L 1.000000e+001
*R
RND
DTR
L 1.000000e+001
/R
T #error_1_10e
L #error_1_10e
L 5.000000e-001
>R
= #L
L #error_1_10e
L -5.000000e-001
<R
= #R
AN #L
AN #R
R #Regel_Memory
S #Mahlo_Enable
END3: NOP 0
 
Network 1 -

(1) Use integer arithmetic where possible - it's quicker to execute in the lower spec CPU's.

(2) Remember that there are two accumulators (note that S7-400 series have 4 accumulators). This can save store/load to/from temp variables

(3) Don't duplicate variables that contain the same data

(4) Pre-calculate constants instead of coding (27648.0/20.0)

Here's my implementation

Code:
	  L	 27648
	  L	 #turck
	  <I	
	  =	 #i_overflow
	  JCN   ok2
	  TAK   
ok2:  ITD   
	  DTR   
	  L	 1.382400e+003
	  /R	
	  T	 #turck_ma
 
Hey

When no overflow you scale with Turck, when overflow you scale the value 27648. Tnx too the TAK instruction.
That's really clever!!!


L 27648
L #Turck
<I
= #I_Overflow
JCN OK
TAK
OK: ITD
DTR
L 1.382400e+003
/R
T #Turck_mA
 
Hey

This is what I have now:

NW1:
L 27648
L #Turck
<I
= #I_Overflow
JCN OK
TAK
OK: ITD
DTR
L 1.382400e+003
/R
T #Turck_mA

NW2:
A #Prod
L S5T#30S
SF #Shuttimer
LC #Shuttimer
T #Shuttime_30s
A #Shuttimer
FN #Membit_1
S #Memorise
S #Regel_Neutraal
R #Ext_Enable
A #Memorise
JCN END1
L #Turck_mA
T #MEMORY
T #Memorised_mA
R #Memorise
END1: NOP 0


NW 3:
A #Regel_Neutraal
JCN END2
L #Turck_mA
L #Neutral_mA
-R
L 1.000000e+001
*R
RND
DTR
L 1.000000e+001
/R
L 5.000000e-001
>R
= #L
TAK
L -5.000000e-001
<R
= #R
AN #L
AN #R
R #Regel_Neutraal
END2: NOP 0

NW4:
A #Prod
FP #Membit_2
S #Regel_Memory
A #Regel_Memory
JCN END3
L #Turck_mA
L #MEMORY
-R
L 1.000000e+001
*R
RND
DTR
L 1.000000e+001
/R
L 5.000000e-001
>R
= #L
TAK
L -5.000000e-001
<R
= #R
AN #L
AN #R
R #Regel_Memory
S #Ext_Enable
END3: NOP 0
 
Network 2 -

(1) you are not using the variable "Shuttime_30s" so I've eliminated the load/transfer (maybe this was for monitoring - you could always use a vat table to monitor the timer)

(2) The FN instruction conditions the RLO, again as you are not using the Memorise variable anywhere else, I've eliminated it and put the JCN straight after the FN instruction. The JCN instruction sets the RLO if it does not jump so "regel_neutraal" will get set and "ext_enable" will get reset.

(3) The variable "Memorised_mA" is a duplicate of "MEMORY" so I've removed it.

Here's my version of the code:

Code:
	 A	 #Prod
	 L	 S5T#30S
	 SF	#shuttimer
	 A	 #shuttimer
	 FN	#Membit_1
	 JCN END1
	 S	 #regel_neutraal
	 R	 #ext_enable
	 L	 #turck_ma
	 T	 #MEMORY
END1: NOP 0
 
Network 3 and 4 - the NEGR instruction negates the floating point number in accu1 so this can be used instead of the TAK and L -0.5

I am assuming that the variables "L" and "R" are outputs from the function block and they are not temporary variables. (If they are, then ABS can be used to find the absolute value of the error and then only one compare is required to detect when to reset Regel_Neutraal)

Code:
A #Regel_Neutraal 
JCN END2
L #Turck_mA
L #Neutral_mA
-R 
L 1.000000e+001
*R 
RND 
DTR 
L 1.000000e+001 
/R 
L 5.000000e-001 
>R 
= #L 
NEGR 
<R 
= #R 
AN #L
AN #R
R #Regel_Neutraal 
END2: NOP 0
 
Awesome

Simon, first about this:

NW2​

A #Prod
L S5T#30S
SF #shuttimer
A #shuttimer
FN #Membit_1
JCN END1
S #regel_neutraal
R #ext_enable
L #turck_ma
T #MEMORY
END1: NOP 0​

That u can place a JCN END1 after the FN is something I didn't know, but, I understand that when there is a negative edge that the RLO is 1 cycle High, this means that everything between the JCN instruction and the END label will be executed in that cycle. Really clever.
I left the timer_30s out, it was idd for monitorring.
Memorised_mA is not needed as u say.

Thanks for you're help


The about NW3 and 4, instead of the TAK and the load of the negative value I've used NEGR.

So, after calculation of 1/10th I load 0.5 in ACCU1, So my result is moved to ACCU2.
I do the compare ACCU2 > ACCU1
And then..
NEGR Negotiate like u said instead of TAK and Load -0,5.
So Negr makes the value in ACCU1 Negative, it's a real help.

Thank u all for the great help in my STL programming.


About L and R, these are physical outputs connected to relays, these relays need to control a DC-Motor for positioning. ABS, never heard about that instruction...
A littke question, to make a value negative, a did x (-1), but NEGR is much easier. Can you make a value also positive with some instruction ?
 
NEGD NEGD Convert Twos Complement Double Integer (32-Bit)
NEGI NEGI Convert Twos Complement Integer (16-Bit)
NEGR NEGR Convert Negate Floating-Point Number (32-Bit, IEEE-FP)

These will invert the number, pos to neg and neg to pos.
 
its an invertation of the sign bit if i understood it well :)
Not quite, it's a negation (invertion) of the value, not just of the sign Bit. For example, the invertion of -1 (FFFF) gives +1. If you just invert the sign Bit (EFFF) instead of +1 you get +32767, which is not quite the same!
 

Similar Topics

Hi, I need to trend some data in WinCC, so I wrote this: A M 69.0 JC HI L 0 T MW 100 JC...
Replies
5
Views
1,868
I'm using productivity 1000 plc for this. The process is simple i have a wheel with yarn wrapped around it made out of aluminum with evenly spaced...
Replies
9
Views
1,263
Hello everyone I'm trying to simplify this ladder in order to make it more accesible to modifications, just trying to use indirect addressing...
Replies
2
Views
1,936
Very often I have to reverse engineer something from an iFix parameter inside an array to a bit in iFix. It's a pain to do as I've yet to really...
Replies
2
Views
1,890
I'm working with Studio 5000 & FactoryTalk View Studio ME. I have a UDT that contains data for a part as it passes through a system, Timestamps...
Replies
0
Views
1,915
Back
Top Bottom