S7 Data types

coopdegrace

Member
Join Date
Mar 2009
Location
perth
Posts
34
Question for S7 users. I am new to siemens programming and need some help. I just wanted to know if it is possible convert a real data type to a S5Time data type. I basically have a real number which I want to use as an input to a timer. Thanks.
 
You can, but it's unnecessary hard work, because the data for the time in an S5 Timer is BCD coded (amongst other things).

You'll find life much easier if you use one of the IEC Timers (SFB3 - SFB5 in the System Function Blocks sub-directory of the Standard Library). They take the Time data as a number of milliseconds which will make the conversion from an incoming REAL much easier.
 
Hello coopdegrace;

There is no canned function to do this directly, but you can use a trick:

Use FC40 TIM_S5TI (From the IEC_blocks library)
Description
The function FC40 converts the data type format TIME to the format S5TIME. The value is rounded down during conversion. If the input parameter is greater than the S5TIME format allows (greater than TIME#02:46:30.000), the result S5TIME#999.3 is output and the binary result (BR) bit of the status word is set to "0".

Now, the TIME datatype is basically a 32-bit integer that contains the millesconds corresponding to your time value. So, for a REAL value of 1.5 (hours), the corresponding TIME value would be 1.5h * 3600 s/h* 1000 ms/s = 5,400,000 ms. This TIME value can be converted to a S5Time value using FC40.

Start by converting the REAL time value to ms in a register defined as a TIME variable, then use FC40 on that variable; the result (as long as it remains within the limits of a S5Time varable) will be in S5Time format.

Hope this helps,
Daniel Chartier
 
Are you sure that the starting point is a REAL ? That would be odd for a time value.
The most used time type is TIME (surprisingly !). It is simply the time in milliseconds, with the display formatted in days, hours, minutes, seconds and milliseconds.
The range is from -T#24D_20H_31M_23S_648MS to T#24D_20H_31M_23S_647MS.
This should fit almost any timer requirements.

Rather than converting the REAL value to a TIME value, and then use the library function FC40 TIM_S5TI (*), maybe you should just use an IEC timer, and start with a TIME value rather than a REAL value. In that way you get full resolution with no conversion or anything.

*: TIM_S5TI converts a TIME to an S5TIME. Can be found in the library "IEC Function Blocks"
 

Similar Topics

I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
378
I am using a Beckhoff PLC and trying to convert a REAL to 2 WORDS to send over Modbus. Does anyone know how to do this? Also how would I convert...
Replies
5
Views
788
Looking for information regarding what data types are supported in Crimson 3.1 programs. Cstring is self explanatory. Professor Google hasn't been...
Replies
1
Views
1,151
I'm currently working on a messaging system and Ive been having issues with trying to message over a REAL Data Type from one PLC to another. Has...
Replies
2
Views
1,279
I work at a cheese factory and we recently ran into a problem where in an older controller they where able to use a REAL Data type in OTU and XIC...
Replies
13
Views
2,581
Back
Top Bottom