1. Problem Definition: Weekly Output Scheduling on S7-1200
A home or building automation system running on a Siemens SIMATIC S7-1200 CPU 1217C must activate physical outputs on a weekly cadence. Some loads (lighting, irrigation pumps, signage, HVAC setback relays) need daily on/off windows at fixed clock times; other loads only run once per week (cleaning cycle, generator exercise, test routines). A typical requirement looks like:
- Output Q0.0 (lobby lights) — daily 11:00 → 12:00, every day of the week.
- Output Q0.1 (irrigation pump) — Mondays 09:00 → 10:00 only.
- Output Q0.2 (backwash valve) — Wednesdays 03:00 → 03:15 only.
- Output Q0.3 (signage) — daily 17:00 → 23:30.
The logic must be parameterised at runtime from a WinCC HMI so the end user can change the active days, start time, and stop time without reloading the PLC program.
Two specific problems must be solved in TIA Portal V15:
- Build a reusable weekly scheduler block that evaluates the real-time clock (RTC) of the CPU 1217C and asserts an output for the configured day/time window.
- Expose the schedule parameters to a WinCC runtime so an operator can edit the active days, on-time, and off-time from the panel and persist the changes through a power cycle.
The cleanest engineering path is the Siemens Library of General Functions (LGF), shipped as a free global library for TIA Portal and explicitly maintained for S7-1200/S7-1500. The LGF contains a pre-built weekly timer switch block that handles the day-of-week mask, time-of-day window, and edge detection — exactly the function required.
2. Prerequisites
| Item | Requirement |
|---|---|
| Engineering software | Siemens TIA Portal V15 (or V15.1) with STEP 7 Basic |
| PLC | SIMATIC S7-1200 CPU 1217C, firmware ≥ V4.2 (recommended V4.4 for full LGF V15.1 compatibility) |
| LGF version | Library of General Functions V15.0 or V15.1 (Siemens support article ID 109750448) |
| HMI | SIMATIC Comfort Panel, WinCC Runtime Advanced, or WinCC Professional — matching the PLC project version |
| Real-time clock | CPU 1217C internal RTC or external NTP sync via CP 1243-1 |
| Storage medium | Removable SIMATIC SD card recommended for non-volatile persistence of schedule DB |
.al13 (V13), .al14 (V14), .al15 (V15), .al15_1 (V15.1).3. Solution Architecture
The scheduler sits between the HMI tag interface and the PLC outputs. The HMI writes the schedule entries into a global data block (DB). On each PLC scan, the LGF weekly timer block reads the configured day mask and on/off time, compares them to the CPU's RTC, and sets a per-slot boolean. The boolean drives the physical output directly via an assignment or via a separate logic stage (interlocks, manual override, etc.).
4. Installing the Library of General Functions (LGF) in TIA Portal V15
- Download the LGF V15.1 global library from the Siemens support page 109750448. The archive is named
109750448_LGF_V15_1.zip(or the V15.0 equivalent). - Extract the archive locally. The extracted folder contains
LGF_V15_1.al15_1(or the matching version file). - In TIA Portal V15, open the target S7-1200 project.
- From the menu, choose Options → Global libraries → Open.
- Browse to the extracted
.al15_1file and open it. - If you downloaded the V14 SP1 library by mistake, V15 will prompt to upgrade; click Upgrade. The V14 SP1 master copy folder is converted in place.
- After upgrade, expand the library tree: LGF_V15_1 → Types → Timer. The weekly scheduler block (LGF_TimerSwitch) lives here.
- Drag the timer block from the library types into your project's Program blocks folder. The LGF adds its own data types and auxiliary FBs automatically; these are placed in the System blocks → LGF subtree.
5. Using LGF_TimerSwitch for Weekly Time Slots
The LGF weekly timer block (LGF_TimerSwitch) provides a fully parameterised weekly time switch. The instance is called once per scheduled output. The minimum interface looks like:
| Input | Type | Description |
|---|---|---|
enable |
BOOL | Master enable for this schedule entry. Tie to the HMI "Enabled" checkbox. |
dayMask |
BYTE | Bit mask of active days. Bit 0 = Mon, Bit 1 = Tue … Bit 6 = Sun. Bit 7 reserved (0). Example: 2#01010101 = Mon, Wed, Fri, Sun. |
onTime |
TOD | Time of day the output asserts, format TOD#11:00:00. |
offTime |
TOD | Time of day the output releases, format TOD#12:00:00. |
currentDT |
DTL | Current PLC date/time, supplied by RD_SYS_T. |
| Output | Type | Description |
|---|---|---|
active |
BOOL | TRUE while the scheduler asserts the output for the current minute. |
error |
BOOL | Configuration or time error flag. |
status |
WORD | Error/status word, see LGF manual for codes. |
Edge behaviour: onTime == offTime is treated as "always OFF" by most LGF revisions. If offTime < onTime (crosses midnight), the block holds the output from onTime through 23:59:59 and from 00:00:00 through offTime. Verify the exact behaviour in the LGF version you are using — it is documented in the LGF help page 109750448.
6. Building the Schedule Data Block
Place the per-slot configuration in a global DB so the HMI can read and write it. A typed structure keeps OB1 readable and lets the HMI use a single symbol for the whole array.
// DB "SchedData" — mark Retain = true on the DB properties
TYPE UDT_SchedSlot
STRUCT
enable : BOOL; // HMI checkbox
reserved : BOOL; // pad to byte boundary
dayMask : BYTE; // bit 0=Mon … bit 6=Sun
onTime : TOD; // TOD#11:00:00
offTime : TOD; // TOD#12:00:00
END_STRUCT;
END_TYPE
DATA_BLOCK SchedData
STRUCT
slot : ARRAY[0..31] OF UDT_SchedSlot; // 32 schedule entries
END_STRUCT
BEGIN
END_DATA_BLOCK
In the DB properties, set the Retain attribute. On the CPU 1217C, the retain area is limited to 10 kB for the data block region; a 32-slot UDT of 8 bytes each is 256 bytes, well within budget.
7. Mapping Schedule Slots to PLC Outputs
Drop one LGF_TimerSwitch instance per schedule slot into OB1. With 32 slots, use a small loop in SCL or manual call instances. An SCL approach:
// Inside OB1 or FB "Scheduler" — SCL
#rtc := RD_SYS_T(RET_VAL := #err); // current DTL
FOR #i := 0 TO 31 DO
#timer[#i](enable := "SchedData".slot[#i].enable,
dayMask := "SchedData".slot[#i].dayMask,
onTime := "SchedData".slot[#i].onTime,
offTime := "SchedData".slot[#i].offTime,
currentDT:= #rtc,
active => #active[#i],
error => #errArr[#i],
status => #statArr[#i]);
END_FOR;
// Optional override
"Outputs".lobby := #active[0] OR "Overrides".lobbyManual;
"Outputs".irrig := #active[1] AND NOT "Faults".pumpFault;
Always add an Override word for each critical output so maintenance can force the output on from the HMI without disturbing the schedule DB.
8. Exposing the Schedule to WinCC HMI
- In the TIA Portal project tree, open HMI Tags and create a tag array that mirrors the UDT_SchedSlot structure:
HMI_SchedSlots[0..31]with the same fields (enable, dayMask, onTime, offTime). - Set the PLC tag's access method to Symbolic with S7-1200. Symbolic access is preferred on S7-1200 firmware ≥ V4.2 — the data block must be marked as optimisable. The LGF blocks are compatible with optimised blocks in V15.1.
- Configure the HMI connection in Devices & Networks with the standard S7-1200 protocol. The HMI default poll rate of 1 s is fine for minute-resolution schedules.
- For Comfort Panels, also enable the Area pointer — Date/Time under connection properties. The panel will then synchronise its clock from the PLC, avoiding drift between operator edits and the active schedule.
9. HMI Screen Design for Schedule Editing
For each output that has a schedule, build a screen with:
- Seven checkboxes (Mon … Sun) bound to the bits of the HMI tag's
dayMaskBYTE. A script on the HMI converts "checkbox X clicked" → "set/clear bit X of dayMask". - Two I/O fields, format
HH:mm, bound toonTimeandoffTime. - One "Enabled" checkbox bound to
enable. - One "Status" output field bound to the
activeBOOL of the LGF instance for that slot.
Use the WinCC "Date/Time Picker" or a custom keypad for time entry. Validation: clamp onTime and offTime to 0 … 86 399 999 ms in TOD scale, then reformat to HH:mm:ss for the operator.
For a more compact UI, the seven day bits can be displayed as seven round buttons in a row, lighting green when active. This pattern matches typical building-automation dashboards.
10. Runtime Verification and Diagnostics
-
Clock check: Add a watch table in TIA Portal online mode showing
SchedDataand the LGFactive[]array. Set the PLC time one minute before an expected on-time using Online & Diagnostics → Set time. Watch theactivebit assert exactly on the minute. -
Day mask test: With
dayMask = 16#7F(all seven days), the block should fire every day. Reduce to a single day, force the CPU date to that weekday, and verify only that day's output asserts. -
Cross-midnight test: Set
onTime = 23:00,offTime = 02:00. Verify the output is TRUE from 23:00 to 23:59 and from 00:00 to 02:00, and FALSE from 02:00 to 23:00. -
HMI round-trip: From the panel, change a day checkbox. Watch the corresponding bit of
SchedData.slot[i].dayMask update over the S7-1200/Comfort panel connection. Confirm retention by power-cycling the PLC and checking the schedule is still active. -
Override test: Force
Overrides.lobbyManual = 1 from the HMI. Confirm the output follows the override regardless of the schedule.
11. Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| Library will not open in V15 | Wrong LGF version (V13/V14 vs V15) | Re-download matching version; for V14 SP1, accept the upgrade prompt |
status = 16#8001 on LGF instance |
Invalid day mask (e.g. bit 7 set) | Mask the dayMask byte with 16#7F before writing |
| Output never asserts |
enable = FALSE or RTC out of range |
Check enable in watch table; force CPU time |
| Output asserts but on wrong day | Day-of-week bit order is reversed (Sun=0 vs Mon=0) | Confirm LGF documentation for your version; in V15.1 Mon=bit 0 |
| HMI edits not visible in PLC | DB not optimised, or wrong access method | Switch HMI tags to symbolic access on the connection |
| Schedule lost after power cycle | DB not retain, or no SD card fitted | Set Retain = true on the DB; verify SD card seated |
| Time drifts by minutes per week | CPU RTC not synchronised | Enable NTP via CP 1243-1 or wire CP 1242-7 to a time source |
| Slot fires one minute late | OB1 cycle > 60 s; LGF uses edge on minute | Reduce cycle time; verify cycle time in PLC diagnostics |
| Cross-midnight schedule only fires one side | Library version < V15.1 | Upgrade LGF to V15.1 or later |
| Status word reports "Time invalid" | CPU RTC defaulted to 01.01.1994 | Set PLC date/time in Online & Diagnostics |
12. Performance, Memory and Scaling
Each LGF_TimerSwitch instance on the S7-1217C consumes roughly 200 bytes of work memory and around 50 µs of OB1 execution time. 32 instances therefore add about 6.4 kB of work memory and 1.6 ms of scan time — negligible on a CPU 1217C (150 kB work memory, 0.04 ms/kInst typical). If you need hundreds of schedules, switch to a different scheduler architecture: store all slots in a single DB array, loop in OB1, and call a single FB instance that processes the array internally. This drops memory to a few hundred bytes total and gives a deterministic scan-time impact proportional to the number of slots.
For redundant scheduling with logging, route each active transition through a logging FB that writes timestamped events to the SD card. The S7-1200 supports the standard "DataLog" instructions for this purpose (refer to the S7-1200 programmable controller system manual at 109751325).
For 24-hour day-of-year and astronomical schedules (sunrise/sunset), the basic LGF timer switch is not sufficient. Combine the LGF weekly timer with a DTL/TimeOfDay conversion FB and a sunrise/sunset table that the PLC reads at startup. The LGF distribution contains helper FBs for DTL math, but the actual sunrise calculation must be supplied by the user or by a custom library (for example, the open-source "AstronomicalClock" example project shipped with the S7-1200 application examples).
FAQ
Which LGF version is the right one for TIA Portal V15?
Use LGF V15.0 if you are on TIA Portal V15 without the V15.1 update, or LGF V15.1 if you have installed the TIA Portal V15.1 update. A V14 SP1 library will open in V15 with the upgrade prompt but cannot be opened in V13. The official LGF landing page is Siemens support article 109750448.
Why does the LGF_TimerSwitch ignore my schedule on day 7 (Sunday)?
Day-of-week is encoded as a 7-bit mask with bit 0 = Monday and bit 6 = Sunday. Bit 7 of the dayMask BYTE is reserved and must be cleared. If your HMI is sending 16#FF the LGF may treat the high bit as an error flag and refuse to assert. Mask the byte to 16#7F on write.
Can the end user edit the schedule from a WinCC panel without reloading the PLC?
Yes. Bind HMI tags to the symbolic members of the SchedData DB and mark the DB as retain. HMI writes are committed to the PLC working memory and are picked up by the LGF_TimerSwitch instances on the next OB1 cycle. The CPU 1217C needs firmware ≥ V4.2 for symbolic HMI access on optimised data blocks.
How many weekly schedules can a CPU 1217C handle?
With 32 schedule entries, memory and scan-time impact are negligible. The LGF library has been used with hundreds of instances on S7-1200 CPUs, but the OB1 cycle time and watch-dog settings should be reviewed when exceeding 200 entries. For installations with thousands of schedules, move to an S7-1500.
Does the schedule survive a power cycle without an SD card?
Only if the SchedData DB is marked as retain. The S7-1217C retain area is backed by an internal super-capacitor with a typical hold-up of around 6 weeks. For long-term retention or projects that will be deployed for years, fit a 24 MB or 256 MB SIMATIC memory card and configure the CPU to retain DBs on the card.