How to Read a Cyclic OB Interval in a PCS 7 SCL Function Block
In PCS 7, expose a REAL input on the block with the system attribute S7_sampletime := 'true', then compile the CFC chart with the Update sampling time option enabled. CFC writes the cycle time of the cyclic interrupt OB containing the block to that input; when the block runs in a run-time group, the group scan rate is also included. The value is in seconds, so a 100 ms task interval is represented as 0.1.
Table of Contents
- Define a sample-time input in the block interface
- Enable the CFC sampling-time update
- Interpret the value and example
- Handle an arbitrary supported cyclic OB
- Verification
- Limitations and Operational Precautions
- Verification
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Define a sample-time input in the block interface
Add a block input for the interval and mark it with S7_sampletime := 'true'. A conventional name is SampleTime; the system attribute—not the identifier—marks it for CFC's sampling-time update. A declaration matching the pattern in the discussion is:
SampleTime { S7_visible := 'false'; S7_sampletime := 'true' } : REAL := 1.0;
Here S7_visible := 'false' hides the parameter from the CFC chart display; omit or change that attribute if engineers should see or set the value. The initializer 1.0 is a default. It is not proof that CFC replaced it with the installed OB interval.
Enable the CFC sampling-time update
Siemens' CFC for S7 manual documents an Update sampling time option in the compilation dialog. When selected, CFC checks which cyclic interrupt OB contains the block and writes that OB's cycle time to parameters marked S7_sampletime = true. If the block is installed in a run-time group, the group scan rate is also considered.
- Place the block in the intended cyclic interrupt OB and, if applicable, in the intended run-time group.
- Compile the chart/program in CFC and select Update sampling time in the compile options.
- Review the compilation log and confirm the block's input is assigned the expected value.
- Transfer the compiled program using the site-approved download procedure, then verify the value in the CPU or CFC test view as appropriate.
The interval is supplied during CFC compilation. SCL does not dynamically query the currently executing OB's cycle time at runtime through this attribute.
Interpret the value and example
The system attribute supplies the OB interval in seconds as a REAL. For example, if the configured cyclic interrupt OB has a 100 ms cycle and no additional run-time group division changes its effective execution rate, the assigned value is 0.1 seconds. Use the configured OB interval and relevant run-time group scan rate for the actual project; do not rely on an OB's commonly used default or a name such as OB35 as evidence of its cycle time.
The function block can use SampleTime in its own algorithm—for example, to scale a per-call increment into elapsed time—but that logic must be designed for the block's actual execution frequency and the project's timing requirements.
Handle an arbitrary supported cyclic OB
The CFC manual describes checking the cyclic interrupt OB in which the block is installed, so the approach is not limited to OB35. It supplies the compiled OB cycle value for the block's placement, subject to any run-time group scan rate. Confirm that the intended organization block is configured as the expected cyclic interrupt and that the CFC chart's run sequence places the block there. Recompile with sampling-time update when the relevant OB or run-time group settings change.
Verification
After compiling, inspect the block input and compile log to confirm that SampleTime reflects the configured execution interval. Verify both the OB period and the run-time group scan rate; compare the effective call interval with the value being consumed by the FB. During approved runtime testing, confirm that any time-based calculation uses that interval consistently. A correct declaration alone does not update the input when the compile option is omitted.
Limitations and Operational Precautions
The source ticket does not state the PCS 7/CFC release. The cited Siemens CFC for S7 manual documents the S7_sampletime behavior and compile option, but exact dialog labels can vary by version. The attribute is a compile-time parameterization mechanism, not a runtime API for discovering the calling OB. Its value is only meaningful if the block's execution arrangement and the FB's timing calculation agree. Changes to cyclic OB configuration or download behavior should follow the project's normal review and commissioning controls.
Verification
Check that the input declaration has the intended system attribute, the block is placed in the correct cyclic OB/run-time group, and Update sampling time was selected during compilation. Confirm the resulting REAL value in seconds and recompile after timing configuration changes. Test any interval-based logic against the actual compiled value and intended scan rate.
Engineer FAQ
Can one SCL function block work in different cyclic OBs? Yes, if the block is compiled in CFC with its S7_sampletime input and the update option; CFC assigns a value based on the OB in which each instance runs.
Is SampleTime a required parameter name? No. The system attribute determines the update behavior; the input name is chosen by the block designer.
What data type should hold the interval? The cited PCS 7 examples use a REAL sampling-time input, expressed in seconds.
Does the attribute update the value at runtime automatically? The documented mechanism updates the parameter during CFC compilation when Update sampling time is selected; it is not a runtime query.
What does a 100 ms interval look like? It is represented as 0.1 seconds, provided the compiled configuration has a 100 ms effective scan for that block.
Does OB35 always mean 100 ms? No. Use the interval configured in the project and account for the run-time group scan rate.
What happens if Update sampling time is not selected? The documented CFC update will not be applied by that compilation; a default or previously assigned value may remain.
Are run-time groups included? Siemens' CFC manual says the run-time group scan rate is taken into account when calculating the sampling time.
Will moving the block to another OB refresh its input automatically? Recompile with Update sampling time enabled to assign the sampling value based on the new placement.
How can I confirm the assigned interval? Inspect the block input after compilation and compare it with the configured OB period and run-time group scan rate.
Technical References
- Siemens, SIMATIC CFC for S7, A5E00345244-01, “Update sampling time” option, §3.11.1: CFC checks the cyclic interrupt OB, writes its cycle time to the
S7_sampletimeinput and accounts for run-time group scan rate: https://cache.industry.siemens.com/dl/files/430/21401430/att_36978/v1/CFC_For_S7_e.pdf - Siemens, CFC for S7, A5E00083002-02, “Update Sampling Time” option, §3.11: corroborating explanation of compile-time sampling-time updates: https://cache.industry.siemens.com/dl/files/062/1139062/att_29131/v1/Cfcs7_e.pdf
Related Articles
CFC cyclic OB and run-time group sampling