Converting an integer to a timer value in Step7

M

Thread Starter

Martin van Malten

Hi all, I just found this homepage when I was looking for answer to my problem, or rather challenge, I am facing right now:

I want to be able to change a timer value in an S7-315 PLC, using a TP270 Touch Panel (Siemens).
I'm pretty new to Siemens and all I could find so far is entering a word or bit or whatever, and the TP writes it in a DB. Now a timer needs a value in this format: S5T#aaSbbMS.
How can I convert an integer to this format?
Thanks in advance.
 
D

Dobrowolski, Jacek

Hi Martin,

You have two ways (I know of):

1) store your value as TIME type and convert it with the FC40 TIM_S5TI
(you can find it in the IEC Function Blocks),
2) find description of the S5TIME type and convert your value into it
(and have fun).

Regards,
Jacek Dobrowolski, Ms. Sc. E. E.
Software Engineer
 
Martin,

There are several different ways of handling this.

Firstly, the S5Timer format you refer to is really a hangover in S7 from S5 PLCs. It was deliberately included in order to provide compatibility and familiarity for existing S5 users when S7 was launched. Since the basic concept of the S5Timer goes back 20 years or more, it is an entirely proprietary format which uses the top nibble of the word to identify one of 3 time-bases, and the remaining 3 nibbles to identify the magnitude of the timer in BCD format. The overall duration is then the product of both the time-base and the magnitude.

The S7 system was designed to comply with the then emerging IEC61131-3 programming standard from the outset. This meant that a new data type named TIME was included, plus 3 standardised Function Blocks, all in accordance with IEC1131. You'll find them in the STEP7 Standard Library \ System Function Blocks. They are SFBs 3, 4 and 5.

The IEC TIME data type is actually a 32-bit variable, which effectively holds a time value as a number of milliseconds. Double Integer arithmetic can be used to perform manipulations of a TIME variable under certain conditions if your require.

You will also find a library folder named IEC Function Blocks. In here are two FCs, 33 and 40, which are used to convert between S5TIME and IEC TIME data types.

If your plan is to enter a time (nb: not TIME) value via your HMI, then you can use different approaches according to the range and resolution you require. If you define an HMI tag as a TIME data type it goes straight to the PLC as a TIME variable with anything from 1mS up to 24 days+ as the duration. Alternatively, an INTEGER HMI tag holding a number of seconds can be multipled in the PLC by 1000 to give mS, and then used as a 32-bit TIME variable etc.

It's not so much "can I do it?", more a case of "which of these 6 ways is best suited to me?"

Good luck

Regards

Ken Muir
 
S

Syed Aftab Ahmed

<p>Itz very simple:
<pre>
1) The value you entered from input screen, Multiply it by 60 [ Mul_I ]

2) Then convert it from Integer to the BCD form [ I_BCD ]

3) Add a constant value of 8120 to this BCD value [ L #Time1
L 8120
+I
T #Time2
]
</pre>
<p>I think now your life is so simple.

<p>For more Information contact

<p>Syed Aftab Ahmed<br>
ITPS<br>
Siemens Engg. Company<br>
Lahore<br>
Pakistan<br>
[email protected]
 
D

Daniel Chartier

Hello Martin;

Since your TP270 does not accept directly S5Time values, you have to use a conversion function available on your cPU.

In the Standard Library/IEC function blocks (in the Lad/STL/FDB editor catalog) you will find a FC40 ("TIM_S5T") that converts a Time value to S5Time format. A Time value is a double-integer that represents a millisecond value.

So, in your TP270, place an input box where the operator can enter a decimal value for your timer (in minutes, for example); multiply this value by 60,000 (convert from minutes to milliseconds) and use the result as an input to FC40; the output value of FC40 is a S5Time value that you can use as a TV input for a timer.

You can use M-addresses for these operations (MD140, MW200....)and you can use DB addresses (DB11.DBD22); make sure your DB addresses are formated (DINT, S5Time...) correctly for your purposes.

Hope this helps,
Daniel Chartier
 
A

Andrew Hawdon

Hi

The HMI should support S5Time format which is the data type used by S7 Timers. This being the case once you configure the field the HMI will convert the value you enter, 30.2 50 etc into the S5time format to give you 30.2 seconds, 50 seconds etc.

Andrew
 
D

Dobrowolski, Jacek

Hi Andrew,

This was your wishful thinking and better idea would be sent it to Siemens
AD.

Regards,

Jacek Dobrowolski, Ms. Sc. E. E.
Software Engineer
 
the easiest way:<pre>
L 10 // value in seconds (INT)
ITB // &#1074; BCD
L 2#10000000000000 // base in seconds
OW
T DB1.DBW 0 // = s5t#10s (S5TIME)</pre>
 
Top