Convert S5time

Join Date
Jul 2006
Location
mimon
Posts
32
Hi,
I don`t know, how can I convert S5time format. I read timer value to Scada system via OPC from S7-300 such us decimal value. I can need this value convert back to S5Time or convert to second value.

e.g. decimal 5376 = S5T#50s0ms




thanks
 
s5time is coded as follows:

nibble0=units
nibble1=tens
nibble3=hundreds
nibble4 is the time base as follows:
0=0.01 secs
1=0.1 secs
2=1 secs
3=10 secs
 
There are many ways to do it.

If all you need is to see the actual value of the timer, then there are two "outputs" on each timer for that purpose, BI and BCD.
BI is the remaining time in INT format.
BCD is the remaining time in BCD format.
Use the BI value to display the remaining time on your HMI with no need for further programming or conversion, except for putting the right decimal point maybe.

edit:
If you are using german language in STEP7, then BI and BCD are called DUAL and DEZ.
callup the help for the S5Timers in STEP7 to get further explanation.
 
It is problem, because I don`t read directly output timer value [Time remaining], but a read input [preset time value]



JesperMP said:
There are many ways to do it.

If all you need is to see the actual value of the timer, then there are two "outputs" on each timer for that purpose, BI and BCD.
BI is the remaining time in INT format.
BCD is the remaining time in BCD format.
Use the BI value to display the remaining time on your HMI with no need for further programming or conversion, except for putting the right decimal point maybe.

edit:
If you are using german language in STEP7, then BI and BCD are called DUAL and DEZ.
callup the help for the S5Timers in STEP7 to get further explanation.
 
You have to add some code in the S7 program to convert from an integer to an S5Time.
In the HMI program, you should limit the input value to 0-999.
And you should add a decimal point to match what is setup in the program.

 //About the timebase: 
//W#16#0xxx=0.01s timebase
//W#16#1xxx=0.1s timebase
//W#16#2xxx=1s timebase
//W#16#3xxx=10s timebase

A I 0.0 // enables the timer
L MW 100 // from the HMI program
ITB // converts from Integer to BCD
L W#16#FFF // these two lines limits the value to 0-999
AW
L W#16#1000 // these two lines adds the time base
OW
SD T 5



Again, there are other ways to do it. This is just one of them.
 
Im sorry, I don't understand. When I add same code in the S7, then I need conver format S5Time to Integer or float. This converted value must be represet S5Time in decimal value.

e.g
S5T#1m20s0ms = 80,000 s
 
S5T#1m20s0ms = 80,000 s

actually in the UK 1 minute 20 seconds = 80 seconds.

S5Time as stated consists of a time base and value maximum of 999 BCD.

Below is taken from help.
Format of the Data Type S5TIME (Time Duration)



When you enter time duration using the S5TIME data type, your entries are stored in binary coded decimal format. The following figure shows the content of the time address with a time value of 127 and a time base of 1 s.



s5time.JPG




When working with S5TIME, you enter a time value in the range of 0 to 999 and you indicate a time base (see the following table). The time base indicates the interval at which a timer decrements the time value by one unit until it reaches 0.


Time base for S5TIME

You can pre­load a time value using either of the following syntax formats:

  • L1) W#16#wxyz
    • Where w = time base (that is, the time interval or resolution)
    • Where xyz = the time value in binary coded decimal format

  • L1) S5T#aH_bbM_ccS_dddMS
    • Where a = hours, bb = minutes, cc = seconds, and dd = milliseconds
    • The time base is selected automatically and the value is rounded to the next lower number with that time base.
The maximum time value that you can enter is 9,990 seconds, or 2H_46M_30S.





1) = L only to be specified in STL programming
 
When I add same code in the S7, then I need conver format S5Time to Integer or float.
Why ?
You said that you need to read the timer setpoint from the HMI program.
I assume that you also want to be able to change the setpoint from the HMI program.
In any way, in my example the address MW100 represents the address that the HMI must access.

So..
In the HMI it is represented in integer format.
In the S7 program you have to convert from integer to S5Time format.

If you do not need to change the setpoint from the HMI (why wouldnt you ?), then you could change the code slightly so that you have the setpoint in S5Time format in an address, and you then convert the value in that address to integer format and put it in another address for the HMI to look at.

This converted value must be represet S5Time in decimal value.
e.g S5T#1m20s0ms = 80,000 s
Dont get confused by STEP7 because it displays 1m20s0ms. If you strip the timebase and look at the remaining value in BCD format it will display as "800".

Maybe you can describe EXACTLY what it is you want to achieve.
There are many ways to manipulate S5Timers.
It is better to know what yu want to do than for us to throw in several suggestions, only to get back from you that it is not what you have in mind.
 
I read value from PLC in S5Time format [preset time value] e.g. S5T#1m20s0ms ] via OPC to HMI. Because my HMI doesn't know format S5Time, diplay this value in decimal format e.g value 6144. Then I have to each value convert back to time format [e.g 80s] through scriptcode.

Is better, when I will read from PLC to HMI convertion value, which is convert in PLC from ST5Time to decimal format, but in second unit.
From HMI to PLC I don`t need change any value.
 
I presume your preset is in a dataword or flagword then.

The S5time format of S5T#1m20s0ms is something that is translated by the program to make it simple to see what the value is.

In reality the value is 6144 in integer, if you convert this to HEX (try it with your PC calculator, enter it as DEC then change to HEX) it reads 1800. Which is a time base of 1 and a preset of 800. Therefore 800*0.1 = 80 seconds.

You would need to mask off the '1' as previously shown, say for example your time preset was stored in MW100, then:

L MW100
L W#16#FFF
AW // This will remove the timebase of 1
BTI // Then convert what is left from BCD to INT.

You should have 800, which you can place the decimal point yourself wityh the HMI
 
PeterW said:
L MW100
L W#16#FFF
AW // This will remove the timebase of 1
BTI // Then convert what is left from BCD to INT.

You should have 800, which you can place the decimal point yourself wityh the HMI

I aggree with PeterW.

With a little more effort, you can get it milliseconds so that the HMI can use the same display format for any timer. If you need to display in seconds you can specify that a decimal point must be inserted (x.yyy seconds).

 
//from timer with 10 seconds timebase to milliseconds for the HMI.
L MW100
L W#16#FFF
AW // This will remove the timebase
BTI // Then convert what is left from BCD to INT.
ITD // Convert to double because the value may be large.
L L#10000 // 10 sec = 10000 millisec
*D
T MD110 // Note that it is a DINT to hold a large value.

//from timer with 0.01 seconds timebase to milliseconds for the HMI.
L MW102
L W#16#FFF
AW // This will remove the timebase
BTI // Then convert what is left from BCD to INT.
ITD // Convert to double because the value may be large.
L L#10 // 0.01 sec = 10 millisec
*D
T MD114 // Note that it is a DINT to hold a large value.


And so forth.

Maybe you prefer to display in floating point format. Then you do not have to worry about where to put the decimal point:

 
//from timer with 10 seconds timebase to x.y seconds for the HMI.
L MW104
L W#16#FFF
AW // This will remove the timebase
BTI // Then convert what is left from BCD to INT.
ITD // Convert to DOUBLE
DTR // Convert to REAL
L 10.0 // 10 sec (modify to suit each timers timebase)
*R
T MD118 // Note that it is a REAL to hold a large value.


You get the idea.

I think we have covered all possibilities now :)
 
OK, "seconds" timebase is a bit special because you do not have to use a multiplier. So you can simplify like this:

//from timer with 1 seconds timebase to x.y seconds for the HMI.
L MW108
L W#16#FFF
AW // This will remove the timebase
BTI // Then convert what is left from BCD to INT.
ITD // Convert to DOUBLE
DTR // Convert to REAL
T MD122 // Note that it is a REAL to hold a large value
 

Similar Topics

Hello all, I'm currently working on a servo motor linear positioning system (ball screw). I'm all set up regarding communication between my HMI...
Replies
1
Views
92
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
8
Views
322
Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,406
Hello, could someone kindly convert the attached RSP files that are currently used for SLC 5 PLC into PDF please
Replies
6
Views
539
I'm trying to convert an RS Logix 500 fille when I open the 500 file and try to "save as" a .slc file, it does not allow it. It says " SLC library...
Replies
7
Views
698
Back
Top Bottom