Calculate a timer with speed value S7 STL

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi,

I need to calculate a time. I never used a variabele time, I always used S5 timers until now.

So a machine can run @ 30m/min @ max speed. When they hit button I2.0, then after 15 meters, a positioner q5.0 must start. In this case the time should be 30s.

So, If we run @ 20m/min for example, then the time should be

20m in one minute => (15m/min)/20m= 0,75 = 45s

how can I make the time variable ? and program this in a short way in stl ?
 
The TIME variable in S7, as used in the SFBs "TON, "TOFF" etc is a 32-bit long variable which holds a time duration as a number of milliseconds. If you were to enter a literal TIME actual parameter on one of these SFBs as it would appear as T#30s or T#1m30s etc. On the other hand if you assign an address such as MD100 as the actual parameter to hold the time value, you would need to enter a value of 30000 or 90000 respectively.

In your case everything seems related to the fixed quantity of 15m/min. The other values you have are the speed of the machine - let's call this #Speed. Since we want to end up with a number of milliseconds, rather than a fraction of a minute, we should convert the 15m/min to an appropriate range. Sixty seconds in a minute and 1000 milliseconds in a second, so rather than have it with a value of 15, it should have a value of 15 * 60 * 1000 = 900,000.

We then need to divide this 900,000 by whatever your current speed is to get the value of the time variable. For example, 900,000 / 30m/min = 30000 (i.e. 30 seconds expressed as milliseconds); or 900,000 / 20m/min = 45000 etc.
Code:
L L#900000
L #Speed
/D
T MD100

Obviously you'll need to surround this with appropriate logic to decide when to perform this calculation and loading of the timer.

regards

Ken
 
I aggree with Ken.

Even if it is still possible to use variable timers and do calculations on S5 timers, it is too much trouble. Better use the IEC timers.

One note: You say you want to do it in STL. This is a good thing as the IEC timers use the #TIME format which normally does not allow you to perform math. But in STL you can do it with no problems.
 
hi

But

When u multiply 15m/min by 60

u get 900m/h

if u multiply that by 1000, u get 900000 mm/h

that's how I see your calculation... ?


Can u explain a little more ?

and

I can do L MD100
T#

?
 
Distance for the positioner to trigger = 15m = 15000mm
Speed of the machine = X m/min ==> *1000/60 = Y mm/s

Delay time for the positioner = 15000/speed = time in seconds


Network 1

L 15000 //distance for the positioner to trigger (mm)
L #actual machine speed //(mm/s)
/D //divide double
T #triggertime


Network 2

call SFB4 //TON ondelay time
IN:=I2.0 //pushbutton
PT:=#triggertime //calculated time
Q:=Q5.0 //positioner
ET:=
 
Last edited:
Hi

I always feel I must be doing something right if Jesper agrees!

I'm sorry if I introduced confusion by using ',' in the value. I forgot this is commonly used in continental Europe as a decimal marker. I did not mean a floating-point value of 900.000 I intended tthe ',' to be the thousands separator we use it for in the UK. The value should have been shown as 900000
In my example the end result was being stored in MD100 and that is what you would use in the SFB4 call for the PT (preset) parameter. You could just as easily use a TIME-declared variable named #triggertime. I agree in principle with Garcia's method of getting everything in to the correct units of measurement. But he hasn't shown any of the additional code needed for converting machine speed in m/min into mm/s. And guess what, if you take one of your examples of 20m/min this corresponds to 333.3333 mm/sec. Immediately you start needing to use floating-point calculations.

Regards

Ken
 
The original requirement was to start something after 15 metres. You need to integrate the speed signal to get position. This way the processing will work even if the speed is changing. Do this processing in a timed interrupt and hold the integral in reset until your condition is met.
 
hi

NW1
L MD 150 // Machinesnelheid
L 20 // Lengte die we afleggen
/D // Delen door
L 60 // omzetting naar s
*D
L 1000 // omzetting naar ms
*D
T #triggertime // triggertime

NW2

A I 0.2
= L 24.0
CALL "TON" , DB5
IN:=L24.0
PT:=#triggertime
Q :=Q2.0
ET:=
NOP 0


THIS WORKS,

THANK YOU ALL FOR THE GREAT HELP ON THIS SUBJECT
 
Your code is wrong, it only works at 20m/min for 20 metres of distance because 20/20=1 - i.e. it doesn't matter if you divide distance by speed or speed by distance if the result happens to be unity !
Speed=Distance/Time so Time=Distance/Speed
 
Last edited:
Hey

I was too fast indeed concluding that it worked. deviding distance by the speed gives us the time indeed, thanks for correcting my fault.

So I wrote this (not tested yet):

NW1
L 20
L MD 150
/D L 60000
*D
T #triggertime

NW2
A I 0.2
= L 24.0
CALL "TON" , DB5
IN:=L24.0
PT:=#triggertime
Q :=Q2.0
ET:=
 
Too fast again :) - when using double integer arithmetic, you need to ensure that your divisions result in numbers as large as possible, hence you should do the multiplication first, and then the division (just as Ken suggested back in post #2)

Code:
L L#20 //distance in m
L L#60000 //conversion for time in milliseconds
*D
L MD150 //speed in m/min (why use a double ?)
/D
T #triggertime
 
but

Isn't this the same result as what I wrote ?

Why u wanna multiply first en then divide ?

NW1
L 20
L MD 150
/D
L 60000
*D
T #triggertime




When I write a scale of an analogue input I always use the devider first, like this:

L #Input
ITD
DTR
L 27648.0
/R
L #range
*R
L #offset
+R
T #scaled


So you shouldn't write this in this way either ?
 

Similar Topics

Hi all, I've tried to calculate a Preset Timer Value for a CPU318-2 using this code; TIME1 till 5 are local integers TIME6 was S5TIME //...
Replies
5
Views
3,267
Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
957
Good morning, I have a question. I don't know much about ST yet I would like to calculate the average number of products per hour. how do I do...
Replies
22
Views
2,942
Can someone help me with this? I'm no good at SCL - virtually everything I've done so far has been ladder logic. The return value from the...
Replies
13
Views
1,101
I want to calculate the energy consumed from instantaneous power. Can this be done using the TOT block with timebase set to Hour?
Replies
2
Views
684
Back
Top Bottom