Calculate S7 Preset Timer Value

Join Date
Aug 2005
Location
Hasselt
Posts
60
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

// Convert Time --> INT


L "VW_T".Zeit[21]
T #TIME1


L "VW_T".Zeit[2]
T #TIME2


L "VW_T".Zeit[3]
T #TIME4


L #TIME1
L #TIME2
+I
T #TIME3
L #TIME4
+I
T #TIME5


So far so good... (I guess)

T #TIME6
T "VW_T".Zeit[107] //is S5TIME and will be used as the Timer Preset Value)


Loading this last part in PLCSim works as it should. When I load it into a CPU 318-2, the CPU stop's!!!

My only guess is that I might have to do the following, but I'm not sure what would be the difference.

L #TIME5
T #TIME6
T "VW_T".Zeit[107] //is S5TIME and will be used as the Timer Preset Value)


Anyone that can help me?

thx in advance
HG
 
You don't say what format these are in. (EDIT: Sorry you did at the start, the rest holds true)

The S5Time format contains bits to specify the time range and the time itself is in BCD.

you would need to remove the range bits and convert to INT before doing maths and then reconvert to BCD after, ensuring the value is between 0-999.

I would imagine the maths you are doing gives a non BCD result.
 
@Peter, I don't have Step7 available at present to check, but I seem to remember that it is also possible to program the S5 Timers by passing them a time in ms (or 10ms units?) in #Time format. I assume the editor must then convert this to normal S5Time BCD format when the programme is compiled.

If I'm correct then it would be possible to do what Heino wants by calculating the values as INTs and then converting the result to #Time format - note not S5Time.

Actually, thinking about it, in STL it might well work using the #Time data directly, because of the missing type checking.

@Heino, what was in the diagnostic buffer when the CPU went into STOP?
 
@Heino
S5Time is definitely a BCD-Formated Value.

From now on, you have two simple ways to get a Solution:
1:
You could use the Function FC40, which can be found in the Standard-Library under IEC-Funktion Blocks
You must calculate your Time-Values to msec.
This Variable you could put on the FC40, and the Result is a correct formatted S5-Time Value.

2.
You Calculate the Time in msec for use with the SFB4.

Regards,
Manuel
 
thx for ur help guys,

@RMA, didn't check at the time because machine had run ASAP and forgot to look afterwards,

@MSB, I will try to do it with FC40.

Thx for ur help
 
Heino Geerdens said:
// Convert Time --> INT


L "VW_T".Zeit[21]
T #TIME1


L "VW_T".Zeit[2]
T #TIME2


L "VW_T".Zeit[3]
T #TIME4


L #TIME1
L #TIME2
+I
T #TIME3
L #TIME4
+I
T #TIME5

ITB // Integer to BCD
L W#16#0000 // Load time base. 0000=10ms, 1000=100ms, 2000=1s, 3000=10s
AW // Add time value and time base to create timer preset

T #TIME6
T "VW_T".Zeit[107] //is S5TIME and will be used as the Timer Preset Value)

Try what has been added to create the same structure as S5#Time.
Note that it always needs a time base/resolution.
W#16#0000 is 10ms time base
W#16#1000 is 100ms time base
W#16#2000 is 1sec time base
W#16#3000 is 10sec time base.

This means when selecting 100ms time base you can have timer preset values from 100ms to 1m39s900ms.

Now most of you would say:
But you can do

L S5T#1H23M25S225MS
SD T1

And assume the timer will run that time for the exact preset time. This however is not true. When using S5T#, the time base is selected automatically and the value is rounded to the next lower number with that time base.

For more info needed: Open LAD/STL/FBD-editor > Help on STL > Find: enter 'timer' > Select: Location of a timer in memory.......
 

Similar Topics

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
1,061
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,981
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,117
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
700
Hi everyone, I have to calculate the length in millimeters of a glass that enters a transport (I don't know the speed yet) through a barrier...
Replies
15
Views
3,473
Back
Top Bottom