QUESTION:
How can I enter a variable of the "S5TIME" type so as to provide
values for a timer in the SIMATIC controller?
ANSWER:
More informationen regarding the subject S5 timer and using
scripts can be found in the following entries:
- "Representing a S5TIME variable with ProTool/Pro", Entry-ID
9123496
- "Entering S5 timer values directly in ProTool/Pro ", Entry-ID
947095.
The "S5TIME" data type consists of a base time and a time value
in the range 0 to 999 (see Entry ID 56243). In Protool /Pro you
enter the values in hours, minutes, seconds and milliseconds. This
input then has to be converted, so the value can be used as an
"S5TIME" for a timer in the controller.
The project attached contains a script, which reads in hour,
minute, second and millisecond as input parameters. The feedback
value of the function is a data word of the "S5TIME" type.
You should use this script as follows.
- You define yourself 4 variables (e.g. "HH", "MM", "SS" and
"MS").
- You link these variables with 4 input fields in which you can
enter values for hours, minutes, seconds and milliseconds.
- You define a variable of the "WORD" type (e.g. "S5T"). This is
the "S5TIME" value required for the timer in the controller.
- Now you define a button that activates the script. You transfer
the variables defined to the function parameters (with the feedback
value written in "S5T").
The script checks the value entered and modifies the base time
accordingly. The value is limited to the maximum possible value of
9990s or 2h46m30s.
How the script works:
The value entered is first converted into milliseconds. Then it
is limited to 9990s.
The system then checks what base time is to be used. This is
written in Bit 12 and 13 of the result word.
The time value is then determined in the script. This value is
stored in bit 0-11 of the BCD coded result word.
Source text of script:
Dim Total Time, Result
Dim Point1, Point2, Point3
Total time = Millisecond + 1000*Second + 60000*Minute +
3600000*Hour
If Total time > 9990000 Then Total time = 9990000
If Total time > 999000 Then
Result = 12288
Point1 = Fix(Total time/1000000)
Total time = Total time - Point1*1000000
Point2 = Fix(Total time/100000)
Total time = Total time - Point2*100000
Point3 = Fix(Total time/10000)
Total time = Total time - Point3*10000
ElseIf Total time > 99900 Then
Result = 8192
Point1 = Fix(Total time/100000)
Total time = Total time - Point1*100000
Point2 = Fix(Total time/10000)
Total time = Total time - Point2*10000
Point3 = Fix(Total time/1000)
Total time = Total time - Point3*1000
ElseIf Total time > 9990 Then
Result = 4096
Point1 = Fix(Total time/10000)
Total time = Total time - Point1*10000
Point2 = Fix(Total time/1000)
Total time = Total time - Point2*1000
Point3 = Fix(Total time/100)
Total time = Total time - Point3*100
Else
Result = 0
Point1 = Fix(Total time/1000)
Total time = Total time - Point1*1000
Point2 = Fix(Total time/100)
Total time = Total time - Point2*100
Point3 = Fix(Total time/10)
Total time = Total time - Point3*10
End If
Result = Result + Point1*256
Result = Result + Point2*16
Result = Result + Point3
S5Time = Result
Downloading the script:
The download includes the script described above. Copy the "
pro___0l.exe" file to a separate directory and then start the file
with a double click.
pro___0l.exe ( 39 KB )
Important:
The sample programs are selected solutions to queries about
complex tasks developed by Customer Support. We must also point out
that it is not possible in the current state of the technology to
exclude all errors in software programs under all conditions of
use. The sample programs were prepared according to the best of our
knowledge. However, we cannot accept any liability beyond the
standard guarantee for Class C software in accordance with our
General Terms of Sale for Software Products for Automation and
Drive Technology".
Keywords:
Object-oriented programming, Time conversion, Timer values
|