IMDHMIControls LibraryShop main store

How-to

Why S7-1500 PWM runs through the control interface with WRREC

PLC programming Published 7 min read

Short answer

On an S7-1500, PWM has no dedicated instruction: you configure the pulse channel for PWM mode in the device configuration, then write parameter assignment record 128 to the channel's control interface with WRREC at runtime. The record's index, length and fields, including the documented pulse-output field DQA, come from the hardware manual for your exact CPU or module.

On this page
  1. Why is there no PWM instruction to call in the program?
  2. How do I set the channel to PWM mode in the device configuration?
  3. What goes into the WRREC call?
  4. How do I turn a duty cycle into the value I write?
  5. How should the program sequence the writes and handle errors?
  6. How do I verify the pulse at the physical output?
  7. Which hardware does this pattern apply to?
  8. Questions asked

PWM on an S7-1500 is not driven by an instruction block, because there is no PWM instruction to call. You configure the pulse channel for PWM mode in the device configuration, and the running program then commands it by writing parameter assignment data record 128 to the channel's control interface with WRREC. The record's index, length and field layout, including the pulse-output field DQA, are defined in the hardware manual for your exact CPU or module, not by the S7-1500 family name. The steps below follow a CPU 1511C project built in TIA Portal V16 and apply the same way to any compact S7-1500C CPU or pulse output module.

Why is there no PWM instruction to call in the program? #

Because STEP 7 treats the pulse output as configured hardware rather than a software function: the channel is parameterized in the device configuration, and when parameters are assigned from the user program they are transferred to the module with WRREC and parameter assignment data record 128.

The channel exposes a control and feedback interface, and the documentation is explicit about the split: WRREC writes to the control side, RDREC reads back from the feedback side. That pair is the entire runtime mechanism. There is no block to instantiate, no library call to license, and no hidden instruction that appears in a later firmware — the interface is the contract, and the record definition in your hardware manual is its wording. The practical consequence is that the work lives in two places: getting the device configuration right, and getting the record buffer right. An engineer who skips the first and copies the second from a different CPU ends up debugging a write that succeeds at the instruction level and does nothing at the channel.

How do I set the channel to PWM mode in the device configuration? #

Open the device configuration, select the CPU, and set the intended channel's operating mode to PWM under its Pulse Generator (PTO/PWM) entries, because nothing written at runtime works until that configuration is compiled, downloaded and running.

  1. In the device configuration, select the CPU, then the Pulse Generator (PTO/PWM) entry for the channel you intend to use.
  2. Set that channel's operating mode to PWM and its cycle time inside the range the hardware manual allows for that exact channel; the permitted range is hardware-specific, so read it rather than assume it.
  3. Set the channel's reaction to CPU STOP while you are there. That reaction, not your logic, decides the output state when the CPU leaves RUN.
  4. Compile, correct every hardware-configuration error, download, and confirm the configured hardware matches what is physically installed — in the worked context here, a CPU 1511C in TIA Portal V16.

One safety point belongs at this step: a PWM output commands real power electronics, so the CPU STOP reaction and the load's safe state are decisions that come from the machine's risk assessment. The PWM path is a control function, never a safety function.

What goes into the WRREC call? #

Three things: the ID pointing at the pulse output's hardware identifier, the record index 128 that selects parameter assignment for the PWM channel, and a RECORD buffer whose fields, types and order come from that hardware's manual.

WRREC transfers the RECORD you supply to the component addressed by the ID; for an on-board channel that component is the CPU module itself. The manual documents the record under its PWM parameter-data-records section: DQA is the documented name of the pulse-output field, and it sits beside the channel-enable and pulse-width fields, each with its data type, offset and permitted range. The record length is whatever the manual states for that record on your hardware — count bytes, not assumptions.

The index numbers this record mechanism uses are catalogued in the WRREC and RDREC data-record index reference, which is worth keeping open beside the hardware manual. If you are hunting for the right chapter, the guide to where the S7-1500 system manual lives walks straight to the documentation set.

How do I turn a duty cycle into the value I write? #

Work from the configured cycle time: at 100 Hz the period is 10 ms, so a 60% duty command means 6.0 ms of on-time per cycle, and you write that on-time in the unit and format the manual defines for the interface's pulse-width field.

These are example inputs for the arithmetic, not limits of any particular channel:

  • Cycle time: 100 Hz configured, so T = 1 / 100 Hz = 0.01 s = 10 ms per cycle.
  • Required duty: 60%, so on-time = 0.60 × 10 ms = 6.0 ms.
  • Setpoint move to 65%: 0.65 × 10 ms = 6.5 ms, an increase of 0.5 ms per cycle.
  • Average-voltage check for a resistive load on an example 24 V DC supply: 0.60 × 24 V = 14.4 V.

The manual owns the scaling. It states whether the pulse-width field takes microseconds, a percentage or counts, and it states the permitted range for your cycle time. Never port a scaling from another module, because the same duty percentage can be expressed in a different unit on different hardware, and a factor-of-1000 error passes the instruction's syntax check without complaint.

How should the program sequence the writes and handle errors? #

Issue one write per genuine setpoint change, keep the RECORD buffer stable until the instruction completes, and accept the command only when the write reports success and the diagnostics stay clear, because a finished program scan proves nothing.

  1. Gate the first write on the channel and module conditions the manual requires.
  2. Call WRREC for each change and let it finish before issuing the next write; never rewrite the buffer mid-transfer.
  3. On a failed write, read the instruction's status output and the CPU diagnostics, then check the ID, record index, length and field values against the manual. One documented failure path has nothing to do with PWM itself: record access refused because of optimized block access, walked through step by step in the WRREC record access failure with optimized block access walkthrough.
  4. Define the reject behavior before commissioning: whether PWM stays disabled on a rejected write or the output reverts to the machine's safe state.

Wrapping the whole exchange in your own function block keeps this sequence in one place, and it is exactly why the CPU 1511C sample was rebuilt around the interface rather than left as scattered calls. Keep command and status registers separate the way the PLC function block for gripper open and close control does, so the caller sees accepted state, not intended state.

How do I verify the pulse at the physical output? #

A successful write proves the interface accepted the record, not that the wire pulses: measure the output terminal, compare the measured on-time and cycle against the commanded values, and only then trust the channel.

Use an instrument fast enough for millisecond-scale pulses, and compare the measured on-time against the commanded value from the worked example rather than against the setpoint percentage. Sweep the duty range your process actually uses and confirm the output follows at both ends. Watch the diagnostics throughout: a channel that pulses while carrying an active channel diagnostic is a fault waiting for the worst shift of the year. Finally, trip the CPU to STOP once on the bench and observe the output obey the configured reaction, because that behavior is the one your risk assessment depends on and it is worth seeing before the machine sees a load.

Which hardware does this pattern apply to? #

Every pulse-capable S7-1500 compact CPU, the CPU 1511C included, and every pulse output module such as the TM Pulse 2x24V follows this configure-then-write-record pattern, while the record definition itself remains specific to each order number.

That split is the rule to carry away: the method is common across the S7-1500 family and its pulse modules, but the record's field layout, permitted values and cycle-time range are stated per hardware in the PWM chapters of each manual. A project moved from one CPU to another, or from a compact CPU to a pulse module, re-verifies its record buffer against the new hardware's documentation before its first write — same instruction, same record index, different wording.

Questions asked

Can WRREC reach a pulse channel on distributed I/O as well?

Yes. WRREC transfers its RECORD to the component addressed by the ID, and the documentation allows that component to be a module in the central rack or on distributed I/O. The instruction and the record index work the same way; only the manual that defines the record layout changes, because it belongs to the hardware you address.

What should I read first when a write to the pulse channel fails?

Read the instruction's status output and the CPU diagnostic buffer before changing any value. The usual culprits are a wrong hardware identifier, a record index or length the module does not support, and field values outside the documented range. The status codes are listed in the instruction documentation, and the record definition is in the manual for your exact hardware.

Is there a ready-made program example for the control record?

The STEP 7 documentation includes a program example for using the control data record with WRREC and RDREC, and further libraries and application examples are published separately. Take the example that matches your TIA Portal version, but verify every field of the record against the manual for your CPU or module before reusing it on your hardware.

Should I rewrite the pulse-width value every program scan?

No. Write when the setpoint changes, and let each write reach its done state before the next one starts. Every WRREC call is a record transfer with its own completion and status handling, so scan-rate rewriting only stacks pending transfers and hides which values the channel has actually accepted.

Keep reading

  • Selection guide

    S7-300 vs Q series IEC 61131-3 language support

    Both platforms meet IEC 61131-3 once you buy the right toolchain: S7-GRAPH gives the S7-300 sequential function chart with function block calls from steps, and GX Works3 gives the Q series the SFC nesting that IEC Developer V5.0 lacked. With languages equal, integrated motion decides: one QD77MS16 module synchronizes 16 axes over SSCNET III/H at a 0.222 ms cycle, while the S7-300's 4-axis FM 357-2 is discontinued. Choose Q with GX Works3 for new multi-axis machines; stay with Siemens only inside an installed S7-300 base.

    PLC programming

  • Selection guide

    Which IEC 61131-3 PLC language to use for each control task

    Match each control task to the IEC 61131-3 language whose form shows its dominant data path: ladder for discrete interlocks, structured text for calculations and data handling, function block diagram for connected signal functions, SFC for phased sequences. Instruction List is deprecated, so new code uses the other four, and the controller's supported languages set the final limit.

    PLC programming

  • How-to

    How to read Factory I/O REAL and INT tags in CODESYS Modbus TCP

    Factory I/O multiplies each Float sensor value by 100 and sends it as a 16-bit Word, and its Int tags cross as 32-bit values. In CODESYS, receive the Word, convert it to REAL, divide by 100.0, and declare each Int tag as a DInt; BOOL tags pass straight through the Modbus TCP slave mapping you already have.

    PLC programming