1. Overview
A weekly timer switch on a Siemens SIMATIC S7-300 CPU 315-2DP drives a discrete load (for example a ventilation fan, irrigation valve, or lighting contactor) on pre-determined days of the week at a specific time. Two engineering paths exist:
- Hardware-scheduled Time-of-Day interrupt (OB10) – the CPU itself raises an event at the configured time and execution frequency, so no polling in OB1 is required.
- Software polling with SFC1 READ_CLK – the user program reads the CPU clock inside OB1 and compares the result against a target day/time using standard comparators.
For a robust weekly schedule the recommended approach is to combine both techniques: use OB10 as the weekly trigger and SFC1 inside OB10 to read the clock for logging, display, or fallback logic. The clock itself is set with SFC0 SET_CLK and can be re-synchronised from an OP177B HMI or a higher-level SCADA node.
6ES7315-2AG10-0AB0 and 6ES7315-2AH14-0AB0). The SFC and OB functions referenced here are part of the standard S7-300 instruction set and are available across the full 315-2DP family. Always cross-check the Siemens Industry Online Support manuals for your exact MLFB and firmware (FW) version before commissioning.2. Prerequisites
- CPU: SIMATIC S7-300 CPU 315-2DP (any FW release that supports OB10..OB17 Time-of-Day interrupts – this is standard from FW V2.x upwards).
- Engineering software: STEP 7 V5.5 / V5.6 (classic) or STEP 7 Professional (TIA Portal V13 or later with the S7-300 add-on) – the example below uses STEP 7 V5.x notation because the 315-2DP is a classic S7-300.
- Backup battery installed in the PS or CPU slot so the real-time clock (RTC) is retained through power cycles. Without the battery, the RTC is volatile and the weekly schedule will drift or stop after each power-off.
- HMI (optional): SIMATIC OP177B (6AV6642-0BA01-1AX1 or later) on MPI/PROFIBUS for time-of-day display and manual override.
- Load wiring: 24 V actuator / contactor fed from a digital output module (SM 322), fused to the actuator nameplate rating.
3. CPU 315-2DP Hardware and Clock Architecture
The 315-2DP integrates a buffered real-time clock (RTC) and an integrated DP master interface for PROFIBUS. Key points relevant to time-based control:
| Feature | Value / Note |
|---|---|
| OB10..OB17 Time-of-Day interrupts | 8 independent OBs, each configurable for start, period, and priority |
| Clock resolution | 1 s for Time-of-Day interrupt scheduling; ms resolution returned by SFC1 |
| Clock synchronisation sources | PROFIBUS master (slave-to-master clock sync per DP-V1), NTP via CP, MPI, or HMI |
| Backup | RTC backed by PS 307 / 305 backup battery (typical > 1 year retention) |
| Relevant SFCs | SFC0 SET_CLK, SFC1 READ_CLK, SFC28 SET_TINT, SFC29 CAN_TINT, SFC30 ACT_TINT, SFC31 QRY_TINT |
For the official instruction set, refer to the SIMATIC S7-300 CPU 31xC and CPU 31x: System Manual and the STEP 7 – System and Standard Functions reference manual.
4. Method A – Time-of-Day Interrupt OB10 (Recommended)
OB10..OB17 are event-driven OBs the CPU executes when the internal clock reaches a programmed instant. A typical weekly vent schedule uses OB10 with the period field set to Weekly and the start date set to the first valid execution.
4.1 Configure OB10 in HW Config (STEP 7 V5.x)
- Open the S7 project in SIMATIC Manager and open HW Config.
- Double-click the CPU 315-2DP in the rack. The CPU properties dialog opens.
- Switch to the Time-of-Day Interrupts tab.
- Select OB10 and tick Active.
- Enter the Start date (DD.MM.YYYY) and Start time (HH:MM:SS). Example:
06:00:00on01.01.2025. - Set Execution = Weekly.
- Optionally enter a Phase offset (in seconds, < period). Leave at 0 for a fixed wall-clock time.
- Set OB10 Priority (default 2; raise above OB1 = 1 if the actuator must pre-empt cyclic execution).
- Click OK, then Save and Compile, and download the hardware configuration to the CPU.
OB_WeeklyVent, and download.4.2 OB10 Sample Program (STL)
OB10 fires once per week at the configured time. The body is intentionally short; real-time latency is irrelevant as long as OB1 remains within its watchdog.
ORGANIZATION_BLOCK OB 10
TITLE = 'Weekly Ventilation Start'
VERSION : 0.1
VAR_TEMP
info : ARRAY[0..19] OF BYTE; // OB start info
cd : INT; // day-of-week counter
sclk : DATE_AND_TIME; // 8-byte DT buffer
END_VAR
BEGIN
// --- Read CPU clock for logging / HMI display ---
CALL SFC 1 ( RET_VAL := MW100, CD := sclk );
// --- Set DO bit to start vent ---
SET;
S A 0.0; // Q0.0 = vent start command (latched)
// --- Optional: clear run-time bit if other logic depends on it ---
CLR;
= M 10.0; // example marker reset
// OB10 should NOT clear the OB10 enable – leave period as-is
END_ORGANIZATION_BLOCK
To stop the vent on a second weekly event, configure a second Time-of-Day interrupt (for example OB11) at the desired off-time and reset the same output:
BEGIN
CALL SFC 1 ( RET_VAL := MW102, CD := sclk );
CLR;
R A 0.0; // stop vent
END_ORGANIZATION_BLOCK
4.3 SFC28 / SFC30 – Re-arm the Weekly OB at Runtime
The configured period is permanent, but a runtime program can change the next execution instant and re-arm the interrupt:
// Re-arm OB10 to fire next Monday 06:00:00
CALL SFC 28 (
OB_NO := 10,
SDT := P#DB20.DBX0.0 BYTE 8, // DT: 25.01.2026 06:00:00
PERIOD := W#16#0401, // = weekly (see table below)
RET_VAL := MW110 );
CALL SFC 30 (
OB_NO := 10,
RET_VAL := MW112 );
| PERIOD W#16# | Meaning |
|---|---|
| 0001 | Once (single execution) |
| 0101 | Every minute |
| 0201 | Hourly |
| 0301 | Daily |
| 0401 | Weekly |
| 0501 | Monthly |
| 0601 | End of month |
| 0701 | Yearly |
Period codes are taken from the Siemens S7-300/400 Standard and System Functions reference manual (Section on SFC28 SET_TINT).
5. Method B – SFC1 READ_CLK + Comparators in OB1
If you need more than a single weekly time-stamp (for example multiple start/stop windows per day, or a different schedule per weekday), poll the clock in OB1 and execute comparators. The trade-off is higher OB1 scan time and the need for edge-detection flags to avoid re-triggering the actuator on every scan.
5.1 DT (Date and Time) Buffer Format
SFC1 writes an 8-byte BCD-encoded buffer of type DATE_AND_TIME:
| Byte | Content | Range (BCD) |
|---|---|---|
| 0 | Year (century) | 19 (1900) .. 20 (2000) .. 89 (2089) |
| 1 | Year (year within century) | 00..99 |
| 2 | Month | 01..12 |
| 3 | Day | 01..31 |
| 4 | Hour | 00..23 |
| 5 | Minute | 00..59 |
| 6 | Second | 00..59 |
| 7 | ms (bits 0..11) and weekday (bits 12..15, 1=Sun..7=Sat) | 000..999 / 0..F |
5.2 Polling Logic (STL)
// In OB1, cycle ~50 ms is fine for a 1-minute window
CALL SFC 1 ( RET_VAL := MW120, CD := DB10.DBD0 );
// Compare hour == 6 AND minute == 0 AND weekday == 2 (Monday)
L DB10.DBB4; // hour
L 6;
==I ;
= M 20.0;
L DB10.DBB5; // minute
L 0;
==I ;
= M 20.1;
L DB10.DBB7; // weekday nibble
L B#16#20; // 2 = Monday
==B ;
= M 20.2;
U M 20.0;
U M 20.1;
U M 20.2;
UN M 20.3; // one-shot edge flag
= M 20.4;
U M 20.4;
S A 0.0; // start vent
S M 20.3; // latch edge flag for the day
// Reset edge flag at midnight Sunday to re-arm next week
L DB10.DBB5;
L 0;
==I ;
U( ;
L DB10.DBB4;
L 0;
==I ;
) ;
R M 20.3; // re-arm for next Monday
6. Setting the Clock with SFC0 SET_CLK
If the CPU battery has been removed or the clock has drifted, set the time from STEP 7 (PLC → Set Time of Day), from the OP177B (System → Date/Time) or from the user program:
// DB20 contains 8 bytes BCD-formatted date/time (DT)
CALL SFC 0 (
PDT := P#DB20.DBX0.0 BYTE 8,
RET_VAL := MW130 );
Return value 0000 = no error. Non-zero codes are documented in the S7-300/400 Standard Functions reference (Section SFC0).
7. OP177B Integration
The OP177B can be wired to the CPU 315-2DP over MPI (default) or PROFIBUS. Recommended screen objects:
-
Date/Time field pointing to
DB10.DBD0(DT) – displays the current CPU clock. - Set Time function button – writes operator-entered date/time back via SFC0.
-
Status indicator on
Q0.0and a "Manual override" button that triggers a discrete input to setM20.5for forced start. -
Schedule display – read
OB10.START_DATE/OB10.START_TIMEfrom the OB start info if you want to show the next execution on the HMI.
For WinCC flexible / TIA WinCC engineering tips on the OP177B, see the SIMATIC OP 177B Operating Instructions.
8. Commissioning and Verification
- With the project online, open PLC → Operating Mode and confirm the CPU is in RUN.
- Open PLC → Diagnostics → Time-of-Day Interrupts. Verify OB10 shows the next execution date/time and the status is Active.
- Open Monitor/Modify on OB10 and force a one-off test: temporarily set the period to "Once" with a start time 2 minutes ahead, download, and confirm the vent starts and the OB10 diagnostic date advances.
- Restore the period to Weekly and download again.
- Power-cycle the rack. After restart, the OP177B should show the time-of-day retained. If the time is reset to
01.01.1994 00:00:00, the backup battery is missing or discharged – replace it. - Log into STEP 7 PLC → Variable Status Table and add
DB10.DBD0andQ0.0. Confirm the DT updates each second and the output latches on the weekly event.
9. Troubleshooting Matrix
| Symptom | Likely Cause | Action |
|---|---|---|
| OB10 does not fire at the configured time | OB10 not active in HW Config or not downloaded | Open CPU properties → Time-of-Day Interrupts tab, tick Active, re-download HW Config |
| OB10 fires once, then stops | Period set to "Once" (W#16#0001) by SFC28 | Re-issue SFC28 with PERIOD = W#16#0401 and SFC30 ACT_TINT |
| Clock resets on every power cycle | Backup battery missing / discharged | Replace PS 307 backup battery; verify voltage in PLC diagnostics |
| SFC1 returns DT = 1994-01-01 00:00:00 | CPU is in cold restart with no battery, or SFC0 has not been called | Set clock from STEP 7 or OP177B, or call SFC0 in OB100 |
| Time drifts several seconds per day | Crystal ageing, no PROFIBUS sync, high temperature | Activate slave-to-master clock synchronisation on the DP master, or add an NTP-capable CP (e.g. CP 343-1) to slave-sync from a higher-level time master |
| OP177B shows "Communication Error" | MPI/PROFIBUS address mismatch, bus terminator missing | Set OP177B MPI address to match the panel slot; check terminating resistors at first/last node |
| OB85 / SF LED on CPU when OB10 missing | OB10 is enabled in HW Config but does not exist in the program | Insert OB10 source into the S7 program and download |
| Vent starts but never stops | OB11 (off-event) not configured or output not reset | Configure OB11 with off-time, add CLR + R A 0.0 in OB11 body |
10. Field-Proven Cautions
- Time zones / DST: The 315-2DP clock has no DST awareness. Schedule offsets to UTC and convert for display, or disable DST on all networked nodes.
- Watchdog: The default 1500 ms cyclic watchdog applies to OB1 only; OB10 should finish in < 100 ms to leave headroom.
- Clock master election: When several S7-300 stations exist on the same PROFIBUS segment, designate one clock master in HW Config (CPU → Diagnostics/Clock tab) to prevent multiple masters fighting for the bus.
- SF LED on cold start: A cold start with a dead battery logs a "Time error" diagnostic. Clear it with PLC → Clear/Reset Diagnostic Buffer after the battery is replaced.
- Re-traceability: If the application is safety-relevant (for example a fume hood), do not use OB10 alone. Add a runtime watchdog (for example an S7-300F) or an external safety relay to verify the actuator is in the expected state.
11. FAQ
What is the difference between OB10..OB17 on a CPU 315-2DP?
All eight OBs are identical in functionality. Each one can be configured with an independent start date, start time, and period (once/minute/hourly/daily/weekly/monthly/yearly). Use multiple OBs when you need different weekly start times for different actuators.
How do I make a weekly timer that runs Monday to Friday at 06:00 but not on weekends?
Configure OB10 for daily execution (period = W#16#0301) and inside the OB10 body use SFC1 READ_CLK to read the weekday from byte 7 of the DT buffer. If the weekday is Saturday (1) or Sunday (7) at the moment OB10 fires, return without starting the actuator.
Why does my CPU clock lose time after a power cycle?
The S7-300 RTC requires a backup battery. If the battery is missing, the clock is volatile and resets to 01.01.1994 00:00:00. Replace the battery in the PS 307 or in the CPU slot and re-set the clock with SFC0, STEP 7, or the OP177B.
Can I use OB10 together with SFC1?
Yes – this is the recommended pattern. OB10 is the scheduler; SFC1 inside the OB10 body reads the current date/time for logging, HMI display, or conditional branching (e.g. weekday filter). The combination keeps OB1 lean while giving you full visibility.
Does the OP177B synchronise the CPU clock automatically?
No automatic sync. The OP177B has its own battery-backed clock. If you want the panel to set the CPU clock on demand, configure a Set Time function button that writes a DT value and triggers SFC0 SET_CLK in the CPU program.