S7 untidy stl

barryoc

Lifetime Supporting Member
Join Date
Nov 2009
Location
Kilkenny
Posts
148
Hi,

I'm doing a compare in s7 stl. The code i have written works fine but looks messy. What I'm trying to achieve is to set m9.0 when the PLC clock hour is 0, 4, 8, 12, 16, or 20 and then reset at half past the hour. Attached is the working code but if anyone has comments or suggestions to improve the code they are welcome.

Thanks,
Barry.

Capture.PNG
 
Possibly do something along the lines of dividing the time of day by 4 and if the result is a whole number then use a JL instruction.

or tidy that code up

A(
L 0
L time of day
==I
)
O(
L 4
==I
)
O(
TAK
L 8
==I
)
O(
TAK
L 12
==I
)
O(
TAK
L 16
==I
)
O(
TAK
L 20
==I
)
S M 9.0
 
Hello,

I think, you STL is neat and simple. For Keeping your code simple will let you find easily when there is a problem or need to modify existing code or after time passed by. May be this is my personal (beginner) thought. or otherwise, you can loop check by adding constant (since offset is +4), but scan time will increase. Waiting for expert idea to come in.

By the way, what step 7version you are using? It's TIA? thanks!
 
Code:
L "Time Of Day".Hour
L 4
MOD
L 0
==I
S M 9.0

L "Time Of Day".Minute
L 30
==I
R M 9.0


Just a thought......
 
Are you executing this code all the time?

If the code is executing all the time M9.0 will be true until 0:30, then it will be false for 1 minute then back true again at 00:31
 
Jeebs,

Excellent. I never thought of the MOD instruction.

LD,

Yes, this code will be excuting all the time. Good observation, I have only tried it on plcsim and only tried the hour to switch on and the 30 minutes to switch off. I will change the M9.0 reset this evening when i get a chance.

Many Thanks everyone,

Barry.
 
Are you executing this code all the time?
If the code is executing all the time M9.0 will be true until 0:30, then it will be false for 1 minute then back true again at 00:31

maybe a little change in Jeebs code could help if minute > 30 to reset

Code:
L "Time Of Day".Hour
L 4
MOD
L 0
==I
S M 9.0

L "Time Of Day".Minute
L 30
[COLOR="Red"][B]>[/B][/COLOR]I
R M 9.0
 
Last edited:
Hi LD

Go easy on me as this is one of my first posts and also just getting to grips with STL. Could you please explain why m9.0 would be false for one minute. I Keep trying to get my head round it but I feel its going to explode.
 
What do you think the orignally posted code will do? - consider the following times and evaluate the logic.

Firstly, if the hour is zero then M9.0 will be set to TRUE
Secondly, if and only if the minute is 30 will M9.0 be reset to FALSE

Remember that this logic is evaluating every scan.

HH:MM
-----
00:00 M9.0 will be set true, M9.0 will not be reset false
00:29 M9.0 will be set true, M9.0 will not be reset false
00:30 M9.0 will be set true, M9.0 will be reset false
00:31 M9.0 will be set true, M9.0 will not be reset false
 
As this thread has been revived, here's my coding. No SET/RESET, but a list of comparisons that determine when you want M9.0 to be ON

tim6.jpg
 
Only when the hour is 0, 4, 8, 12, 16, or 20

for the other hours, the following will happen

00:31 M9.0 will be set true, M9.0 will not be reset false
M9.0=True
01:00 M9.0 will not be set true, M9.0 will not be reset false
01:29 M9.0 will not be set true, M9.0 will not be reset false
01:30 M9.0 will not be set true, M9.0 will be reset false
M9.0=False
01:31 M9.0 will not be set true, M9.0 will not be reset false
M9.0=False

You cannot assume or guess with plc logic, get the data, execute the logic.
 
I thought that this was the case. Just out of interest on the code that you have submitted you load the accu with "tod#0.0.0.000" for example and compare it with the actual time.

Do you have to express how the clock function works, or are you just inputing a spectic time of day figure to compare to hence the tod#? like if you was dealing with a real number you would put ==r, but for time its tod#.

Or am I barking up the wrong tree?
 
I think I've found the answer to my question. What I was unsure about was the load tod# part but I have found its the format you would write the time of day to the accum. I think?
 

Similar Topics

i am new to simatic manager and i am trying to figure what this part do in the code : A I 5.6 = DB50.DBX 4.6...
Replies
3
Views
136
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
211
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
331
First off thank you in advance. Second I am very new to STL. I am trying to build a counter that has one count up and 23 count down options. Am...
Replies
6
Views
384
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
690
Back
Top Bottom