Converting Between REAL and TIME Data Types in SIMATIC PCS 7 CFC
In SIMATIC PCS 7 CFC, there is no single monolithic elementary block to convert directly between REAL (floating-point seconds) and TIME (IEC millisecond time duration). In STEP 7, data type TIME is represented internally as a 32-bit signed integer of milliseconds (e.g. T#1s = 1000 ms). To convert TIME to REAL (in seconds), pass the TIME variable through SCL or elementary CFC blocks: convert TIME to DINT (TIME_TO_DINT), cast to REAL (DINT_TO_REAL), and divide by 1000.0 via block DIV_R. Conversely, to convert REAL (seconds) to TIME, multiply by 1000.0 via MUL_R, convert to DINT via R_TO_DI, and cast to TIME via DI_TO_T. In APL, timing blocks (such as TimerP) utilize REAL seconds natively.
Table of Contents
- Executive Summary
- Data Representation in STEP 7: REAL Floating-Point vs IEC TIME
- The Millisecond Scaling Factor (1000.0)
- Conversion Implementations: CFC Block Cascades vs SCL Function
- Data Type Conversion and Parameter Mapping Matrix
- Step-by-Step Implementation Procedure
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Executive Summary
Automation engineers implementing custom timing algorithms, countdown displays, or batch phase durations in SIMATIC PCS 7 frequently encounter data type mismatches between mathematical calculation blocks (which process 32-bit IEEE 754 floating-point REAL values) and system timers (which demand the standard IEC TIME data type). While operators and CFC setpoint blocks parameterize durations in human-readable floating-point seconds (e.g. 12.5 seconds), STEP 7 timers and standard library functions operate strictly on IEC TIME, formatted as a 32-bit signed integer counting milliseconds. Because standard PCS 7 libraries do not supply a dedicated REAL_TO_TIME block, engineers must implement conversion cascades in CFC or author custom SCL conversion functions. This technical guide explains the internal binary formats and details the conversion procedures.
Data Representation in STEP 7: REAL Floating-Point vs IEC TIME
Understanding the internal data formats is essential to prevent scaling errors:
REAL(IEEE 754): 32-bit floating-point format comprising 1 sign bit, 8 exponent bits, and 23 mantissa bits. In PCS 7 process control, REAL variables typically represent engineering units (e.g. seconds, hours, bar, °C).TIME(IEC 61131-3): Stored in S7 memory as a 32-bit signed integer (DINT) quantifying time in milliseconds. For example,T#2sis stored as+2000,T#1mis stored as+60000, andT#1dis stored as+86400000.
The Millisecond Scaling Factor (1000.0)
Because TIME counts in milliseconds while process REAL tags typically represent seconds, converting between the two requires a mathematical scaling factor of 1,000.0:
Seconds (REAL) = DINT_TO_REAL(TIME_TO_DINT(Time_Val)) / 1000.0Time (TIME) = DINT_TO_TIME(REAL_TO_DINT(Seconds_REAL * 1000.0))
Conversion Implementations: CFC Block Cascades vs SCL Function
Engineers can choose between two primary approaches:
- CFC Block Cascade: Interconnects standard elementary math blocks from the CFC Library:
MUL_R->R_TO_DI->DI_TO_T. - Custom SCL Function (
FC_RealToTime): A lightweight custom function that executes the conversion in a single line of SCL code, minimizing chart clutter and CPU instruction cycles.
Data Type Conversion and Parameter Mapping Matrix
The following table compares conversion approaches and mathematical transformations in PCS 7:
REAL (Seconds)1000.0, cast to DINTTIME1.5 (Seconds)T#1s_500ms (1500 ms)REAL (Minutes)60000.0, cast to DINTTIME2.0 (Minutes)T#2m (120000 ms)TIME (IEC Duration)DINT, divide by 1000.0REAL (Seconds)T#5s (5000 ms)5.0 (Seconds)TIME (IEC Duration)DINT, divide by 60000.0REAL (Minutes)T#3m (180000 ms)3.0 (Minutes)REAL (Seconds)TimerPREAL (Seconds)10.0 (Seconds)Step-by-Step Implementation Procedure
Method 1: Cascading Elementary Blocks in CFC
- Open the CFC chart in SIMATIC Manager.
- In the CFC catalog, expand Libraries > CFC Library > Blocks > MATH.
- Drag block
MUL_R(Multiply Real) onto the chart. Connect the floating-point second value to inputIN1, and setIN2 = 1000.0. - Expand the CONVERT family in the catalog. Drag block
R_TO_DI(Real to Double Integer) onto the chart. - Connect
MUL_R.OUTtoR_TO_DI.IN. - Drag block
DI_TO_T(Double Integer to Time) onto the chart. - Connect
R_TO_DI.OUTtoDI_TO_T.IN. - Connect
DI_TO_T.OUTdirectly to theTIMEparameter of the target timer or block.
Method 2: Authoring a Clean SCL Conversion Function
- In SIMATIC Manager, insert an SCL Source file into the S7 Program
Sourcesfolder. - Enter the following SCL code:
scl FUNCTION FC_RealToTime : TIME VAR_INPUT rSeconds : REAL; END_VAR BEGIN FC_RealToTime := DINT_TO_TIME(REAL_TO_DINT(rSeconds * 1000.0)); END_FUNCTION - Compile the SCL source to generate the function in the block container.
- Drag
FC_RealToTimeonto your CFC chart for compact, single-block conversion.
Verification
To verify that time conversion operates accurately:
- CFC Test Mode: Switch the CFC editor to Test Mode (Debug > Test Mode).
- Fractional Value Test: Inject
rSeconds = 2.75. Confirm that the output evaluates exactly toT#2s_750ms. - Zero / Limit Test: Inject
rSeconds = 0.0. Confirm output isT#0ms. Inject negative numbers; confirm behavior conforms to your plant safety specifications.
Limitations and Operational Precautions
- Negative Time Limit: STEP 7
TIMEis signed; negative values are technically valid (-T#24d_20h...) but cause undefined behavior in standard timers. Clamp inputs to>= 0.0before conversion. - Maximum Range Overflow: Data type
TIMEhas a maximum limit ofT#24d_20h_31m_23s_647ms(approx. 2,147,483.647 seconds). Passing a REAL larger than this causes DINT overflow. - APL Standard Alignment: In modern PCS 7, avoid legacy S5 timers; use APL
TimerPwhich operates entirely in floating-point REAL seconds.
Engineer FAQ
Why doesn't Siemens provide a standard REAL_TO_TIME block in the CFC library?
Because conversion requires contextual engineering assumptions: some applications define REAL as seconds, while others define it as minutes, hours, or milliseconds.
Can S7-300 or S7-400 timers accept REAL directly?
No. System functions (SFBs such as TON / SFB4, TOF / SFB5) strictly require data type TIME conforming to IEC 61131-3.
Does R_TO_DI round or truncate during conversion?
R_TO_DI performs standard IEEE round-to-nearest-even on the fractional part before outputting the double integer.
Technical References
- Siemens AG: SIMATIC S7-SCL for S7-300/400 Manual (Doc No. A5E00709304)
- Siemens Industry Online Support Entry ID 5581793: SCL Programming Guidelines for S7-300 and S7-400
- IEC 61131-3: Programmable Controllers - Programming Languages and Standard Data Types
Related Articles
- https://industrialautomation.net/search?query=cfc+convert+real+to+time+parameter
- https://industrialautomation.net/search?query=scl+dint_to_time+real_to_dint+function
- https://industrialautomation.net/search?query=pcs7+timerp+analog+time+faceplate
Related Tags
- https://industrialautomation.net/search?query=simatic-pcs7
- https://industrialautomation.net/search?query=cfc-editor
- https://industrialautomation.net/search?query=data-types
- https://industrialautomation.net/search?query=scl