Set TIMER_P SAMPLE_T for a 100 ms OB35 Cycle
For a TIMER_P block placed in OB35 configured for a 100 ms cycle, SAMPLE_T should represent the task sampling interval, 0.1 s, when CFC's “Update the sampling time” compile option is enabled for the block's S7_sampletime input. The block's default SAMPLE_T is 1.0 s, so verify the compiled value instead of assuming it changed. TIME0 must be greater than SAMPLE_T; a 10 ms TIME0 with a 100 ms task violates the documented constraint and cannot produce a reliable 10 ms delay.
Table of Contents
- How SAMPLE_T relates to the cyclic interrupt
- What happens when TIME0 is shorter than SAMPLE_T
- Understand timer resolution and timing error
- Distinguish task period from OB execution duration
- Use CPU_RT information with the correct scope
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
How SAMPLE_T relates to the cyclic interrupt
In CFC, a SAMPLE_T input marked with the system attribute S7_sampletime = true can be updated during compilation. Siemens' CFC manual says the compiler determines which cyclic interrupt OB contains the block and writes that OB's cycle time to SAMPLE_T when “Update the sampling time” is enabled. It also accounts for a run-time group's scan rate. Thus, for an OB35 configured at 100 ms and with an effective scan rate of one, the expected value is 0.1 seconds, not 1 second.
The TIMER_P block documentation lists 1.0 s as the input's default. That default remains relevant if the time is not updated in compilation or if the block/library's attribute and compile settings do not enable the update. After compiling, inspect the actual value supplied to SAMPLE_T and verify the OB/run-time-group assignment.
What happens when TIME0 is shorter than SAMPLE_T
Siemens' TIMER_P documentation states that SAMPLE_T must be less than TIME0. The counter is loaded with TIME0 and periodically decremented by SAMPLE_T; Q0 changes according to MODE once the time has expired. If OB35 calls the block every 100 ms, a 10 ms TIME0 is shorter than one sampling interval, so the selected time cannot be resolved as a 10 ms action by this block/task combination. The manual's inequality is the applicable parameter constraint.
The source reply said this condition did not itself cause a CPU STOP in its case. That observation should not be generalized into a guarantee for all CPU, library and project versions. It also does not make the 10 ms setting valid. Choose a task interval and timer value consistent with the documented constraint and verify the block diagnostic/output behavior for the installed release.
Understand timer resolution and timing error
TIMER_P updates its remaining-time value on calls, so timing is quantized to the block's sampling interval. With SAMPLE_T = 0.1 s, a requested duration such as 0.35 s cannot be represented as an exact number of 0.1 s decrements; the output is acted on at a block execution, not continuously between executions. Signal phase relative to the task start also affects the observed elapsed time. If the required response time is finer than the task interval, use an appropriately faster cyclic task and evaluate the total CPU load and system timing requirements.
The manual also notes that TIMER_P accumulates REAL values and some decimal sample periods (for example, 0.1 s) cannot be represented exactly as binary REAL, which can introduce accumulation inaccuracies. Treat calculated timer values as task-based intervals, not precision clock timestamps.
Distinguish task period from OB execution duration
A cyclic interrupt OB is invoked at configured intervals; its execution time is how long the CPU takes to execute the code during a call. For S7-300/400 systems the Siemens system-functions manual lists OB35's default interval as 100 ms, while noting that the project can configure intervals within the specific CPU's supported range. A configured 100 ms interval does not mean the OB takes 100 ms to run, nor does it guarantee that any arbitrary amount of code finishes within that interval.
Siemens states that the runtime of each cyclic interrupt OB must be significantly shorter than its interval. If an OB35 invocation is still executing when the next interval arrives, OB80 is called; if OB80 is not loaded, the documented S7-300 behavior is transition to STOP. Higher-priority OBs can also interrupt lower-priority processing. Measure the actual OB load on the target CPU rather than estimating from line count.
Use CPU_RT information with the correct scope
PCS 7 CPU_RT documentation describes cycle-performance analysis that separates net OB runtime from overall runtime including higher-priority interruptions. For the documented PCS 7 V9.0 SP1 solution, CPU_RT and overload behavior have explicit prerequisites, including compatible controller firmware/system functions for some analysis features. If configured, controlled load shedding can reduce cyclic OB execution during an overload, but Siemens describes this as emergency operation that must be corrected promptly; it is not a reason to intentionally overrun OB35 or choose an invalid SAMPLE_T/TIME0 pair.
Check the specific project's CPU_RT configuration, library generation and CPU support before relying on overload behavior. Do not infer from “PCS 7 V7.0 or higher” that every older project automatically has the same active overload behavior; Siemens notes that migrated projects may not have the new CPU_RT behavior installed.
Verification
Check the OB35 cycle in the CPU configuration and confirm the Timer_P block is assigned to OB35 or the intended run-time group. Compile with CFC sampling-time updating enabled when the block's S7_sampletime attribute is true, then inspect the compiled/runtime SAMPLE_T value. For the stated 100 ms task, verify 0.1 s when the run-time-group reduction does not alter the effective scan interval. Confirm that TIME0 > SAMPLE_T, then observe PTIME and Q0 across the relevant MODE and input/reset sequence. Measure the actual response at the chosen sampling interval and inspect CPU/OB diagnostics for cycle or request errors.
Limitations and Operational Precautions
The source does not identify the CPU model, PCS 7 version, TIMER_P library release, OB35 configuration details beyond 100 ms, run-time-group reduction, or CFC compile options. The numeric sample value therefore depends on the compiled project configuration. The 2010 cyclic-OB reference applies to S7-300/400 behavior; confirm the matching CPU manual for another controller family.
Changing cyclic task assignments, timer behavior or overload settings can affect control and protection functions. Back up and test changes in a controlled environment, assess cycle loading, and follow the plant's management-of-change process before downloading to a production CPU. No lab test is claimed.
Engineer FAQ
Is SAMPLE_T automatically 1 second?
The TIMER_P block's documented default is 1.0 s. In CFC, compilation can replace it with the cyclic OB interval when the input has S7_sampletime = true and “Update the sampling time” is enabled. Verify the compiled value.
What value should SAMPLE_T have in OB35 at 100 ms?
For an effective 100 ms scan and sampling-time update, it is 0.1 s. A run-time-group reduction can change the effective scan interval, so verify the final value.
Why must TIME0 exceed SAMPLE_T?
TIMER_P decrements its remaining time by SAMPLE_T on each call, and Siemens documents that SAMPLE_T must be less than TIME0. If TIME0 is smaller than one scan, the requested duration is below the task's timing resolution.
Will TIME0 = 10 ms with a 100 ms OB35 necessarily stop the CPU?
The cited TIMER_P manual specifies the invalid timing relation but does not say this parameter pair necessarily causes CPU STOP. CPU STOP is governed by CPU/OB error conditions and project configuration; the case reply's no-STOP observation is not a universal guarantee.
Technical References
- Siemens, CFC for S7, manual A5E00083002-02, “Update Sampling Time” option, pp. 76–77: https://cache.industry.siemens.com/dl/files/062/1139062/att_29131/v1/Cfcs7_e.pdf
- Siemens, Help on CFC – Elementary Blocks, Programming and Operating Manual, 06/2023, A5E41367261-AE, section 15.2 “TIMER_P: Pulse generator,” pp. 91–92: https://cache.industry.siemens.com/dl/files/212/109825212/att_1157276/v1/s7jbib_b_en-US.pdf
- Siemens, System Software for S7-300/400 System and Standard Functions, Reference Manual, 05/2010, A5E02789976-01, section 1.5 “Cyclic Interrupt Organization Blocks,” pp. 24–25, and section 1.16 “Time Error Organization Block,” p. 50: https://cache.industry.siemens.com/dl/files/604/44240604/att_67003/v1/s7sfc_en-EN.pdf
- Siemens, Prevention of overload using CPU_RT, Entry ID 55692652, V4.0, 05/2019, PCS 7 V9.0 SP1 guidance: https://cache.industry.siemens.com/dl/files/652/55692652/att_987614/v2/55692652_CPU_RT_DOC_PCS7V90SP1_en.pdf
Related Articles
Configure CFC sample times for cyclic OBs
Diagnose S7 cyclic interrupt overload and OB80