Convert S5time

I'm afraid your restricted with S5Time, if you wanted to have a smaller increment to change over a larger number, you would have to create your own timer by counting timed pulses.
 
PeterW said:
I'm afraid your restricted with S5Time, if you wanted to have a smaller increment to change over a larger number, you would have to create your own timer by counting timed pulses.
I am not sure I understand.
But I can see another pitfall:
There is a problem with a possible setpoint range of 1-600 seconds.
If you adjust the setpoint to 1 second or 2 seconds, and the timebase is in seconds, then you have a horrible accuracy.
If you then want to improve this by chosing a 0.1 seconds timebase, you then limit yourself to max 99 seconds. You cant win.
In general, if you want to use S5Timers, you must really understand how they work and their limitations.

I prefer to use the IEC timers.
That solves the problem with the HMI anyway, as both the setpoint and the actual value is specified in milliseconds.
I feel that the S5 Timers are best used if you have some old S5 code that you want to reuse.
 
OK. Now I created FC when I wrote following code. My test is OK. Can I write this code more simply ?

NETWORK_1
L #INPUT
L W#16#999
<=I
JCN J001
L #INPUT
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 1.000000e-002 // time base 1s
*R
T #RET_VAL // Note that it is a REAL to hold a large value.
J001: NOP 0

NETWORK_2
L #INPUT
L W#16#999
>I
JCN J002
L #INPUT
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 1.000000e-001 // time base 10s
*R
T #RET_VAL // Note that it is a REAL to hold a large value.
J002: NOP 0

NETWORK_3
L #INPUT
L W#16#1999
>I
JCN J003
L #INPUT
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 #RET_VAL // Note that it is a REAL to hold a large value.
J003: NOP 0

NETWORK_4
L #INPUT
L W#16#2999
>I
JCN J004
L #INPUT
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 1.000000e+001 // time base 1000s
*R
T #RET_VAL // Note that it is a REAL to hold a large value.
J004: NOP 0
 
Could try this


time.JPG
 
Pavel,
have look at S5T_TIM (if I remember the name corectly) function which you can find in Step7 Standard Library. It converts S5Time values into Time values.
 
PeterW,

Im tried your code and anywhere is fault, output is uncorrect.
e.g
your code returned S5T#20s0ms = 6.710886e+008
my primary code returned S5T#20s0ms = 20.0
 
PeterW,

Im tried your code and anywhere is fault, output is uncorrect.
e.g
your code returned S5T#20s0ms = 6.710886e+008
my primary code returned S5T#20s0ms = 20.0

I've not got a test PLC to try it

If I look at what is expected, perhaps you could check against reality. BTW 20mS should return a real of 2.0000000-02.

the s5time format would be in hex 0002 or in binary 0000 0000 0000 0010.

INPUT = IN TYPE WORD
OUTPUT = OUT TYPE REAL
T_INT = TEMP TYPE INT
T_REAL = TEMP TYPE REAL

L #INPUT // Isolate timebase and place in temp store

ACCU 1 = 0000 0000 0000 0010 (0002)

SRW 12

ACCU 1 = 0000 0000 0000 0000 (0000)

T #T_Int
L #INPUT // Remove timebase

ACCU 1 = 0010 0000 0010 0000 (0002)

SLW 4

ACCU 1 = 0000 0010 0000 0000 (0020)

SRW 4

ACCU 1 = 0000 0000 0010 0000 (0002)

BTI

ACCU 1 = 2
// convert to REAL
ITD

ACCU 1 = 2

DTR

ACCU 1 = 2.0000000+0e

T #T_Real // Save REAL in Temp store
L #T_Int // Recover timebase and do a variable jump

ACCU 1 = 0

JL Err // timebase > 3
JU TB0 // timebase = 0 <===
JU TB1 // timebase = 1
JU TB2 // timebase = 2
JU TB3 // timebase = 3
Err: NOP 0
BEU // can put error code here

** Should be processing this one******
TB0: L 1.000000e-002 // timebase 0.01 secs
JU Mult
**************************************

TB1: L 1.000000e-001 // timebase 0.1 secs
JU Mult
TB2: L 1.000000e+000 // timebase 1 sec
JU Mult
TB3: L 1.000000e+001 // timebase 10 secs
JU Mult
Mult: L #T_Real // Multiply and transfer

ACCU 1 = 2.0000000+0e, ACCU 2 = 1.000000e-002

*R

ACCU 1 = 2.0000000-2e

T #OUTPUT // Output REAL
 
jacekd said:
Yes, I've checked it's FC33.
The TIME format is in fact DINT number of miliseconds. You can convert it into REAL, divide by 1000. And it's done.
End of story.

this seems the work free option though.
 
I agree with PeterW I use this method with any timer I need an operator to have the ability to set using fixed units (ie. seconds) rather than try to manipulate the S5_TIME format using scripts and PLC code. With a little extra creativity you can even have it 'scale' itself based on the value entered and count in higher base units.

Timing.jpg

I just move a "0" into this integer to reset the timer. Costs me 1 Edge-Bit and 1 Integer to do it this way. It's not as compact as an S5 timer, but my technicians love it. It's easier for them to understand than converting an S5 time from an HMI variable using scripts, code, or other witchcraft.

Another thing I do in an FB or FC in which I declare several edge bits is place a "*" in the comment field as I use them, that way I don't accidentally use one twice. If I define them as an array I'll make the comment the number of the highest used bit.

Hope this is helpful,
Chris
 

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
320
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
537
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
697
Back
Top Bottom