Overview
A common machine-builder requirement is to provide an operator with a small, fixed number of preset speeds for a motor or servo axis. The classic implementation pattern uses three Boolean inputs (for example I0.0, I0.1, I0.2) on a Siemens S7-1200 CPU to select between three RPM setpoints such as 100, 1000 and 2000. This article documents the three field-proven delivery paths the controller can use to push those setpoints to the drive, the cleanest TIA Portal ladder and SCL implementations, and the verification steps required before handing the machine over to production.
The exact same code pattern applies whether the downstream actuator is a frequency inverter such as the SINAMICS V20, a servo drive such as the SINAMICS V90, or a third-party drive connected over PROFINET, PROFIBUS, or a simple ±10 V analog interface. The PLC side is unchanged; only the fieldbus or analog block configuration differs.
Prerequisites
- SIMATIC S7-1200 CPU (firmware 4.4 or later recommended for full SCL/optimized block support). Reference the SIMATIC S7-1200 Programmable Controller System Manual.
- STEP 7 (TIA Portal) V16 or later. See the STEP 7 Professional V17 system documentation.
- Servo drive that supports one of: digital preset selection inputs, ±10 V analog setpoint, or PROFINET IRT/RT with the PROFIdrive profile (for example SINAMICS V90 PN, part number 6SL3210-5FE... series).
- Three panel-mount pushbuttons rated for the cabinet environment (typically 24 V DC, 10 mA).
- For analog implementations: shielded twisted pair cable and a 24 V stable supply.
Three Field-Proven Delivery Paths
There are three industry-standard mechanisms for transferring a speed setpoint from the PLC to a drive. Pick the one that matches the drive catalog and the wiring infrastructure already on the machine.
Path A — Drive Onboard Digital Preset Inputs
Many modern drives expose 4 to 8 opto-isolated digital inputs that map directly to internal parameter sets. The PLC simply wires three outputs to three of those drive terminals; the drive performs the speed switchover autonomously in <10 ms. This is the lowest-latency, lowest-network-load path.
On the SINAMICS V90 PN the function is parameterized via p1001 through p1015 (fixed setpoints) and selected through p1020 through p1023 (binary selection inputs). On the SINAMICS V20 the equivalent parameters are P0701–P0704 for input function and P1001–P1003 for fixed frequency values. Refer to the SINAMICS V90 Operating Instructions and the SINAMICS V20 Parameter List.
Path B — Analog ±10 V Setpoint
Most legacy and many current drives accept a bipolar ±10 V (or unipolar 0–10 V) reference. The PLC outputs a proportional voltage via an SM 1232 analog output module (for example 6ES7232-4HD32-0XB0, 4 AO, ±10 V, 12-bit) and the drive scales the voltage to RPM via its own ramp parameters. The PLC uses only one Boolean per direction (enable/run) plus the analog wire for the speed value.
Configure the SM 1232 output range to 0–10 V (mode 1 in TIA Portal hardware catalog) so that 0 V maps to 0 RPM and 10 V maps to the maximum motor speed. Drive scaling is done in the drive (for example p2900 on V90 PN sets the reference speed for 100 %).
Path C — PROFINET / PROFIBUS with PROFIdrive Profile
The cleanest modern approach uses PROFINET cyclic communication. The drive receives a 16-bit control word (STW1) and a 16-bit speed setpoint (NSOLL) every 1–4 ms. The S7-1200 writes the RPM value into a tag linked to the PROFINET device's NSOLL slot. Refer to the SINAMICS V90 PN Function Manual for the exact telegram layout (standard telegram 1: STW1 + NSOLL + ZSW1 + NIST).
PLC Data Architecture
Regardless of the delivery path, the PLC logic is identical. Define a single global data block (DB) with the following tags so that HMI, motion, and safety all read the same source of truth.
| Tag | Type | Initial value | Purpose |
|---|---|---|---|
i_SpeedSelector |
INT | 0 | 0 = stop, 1 = low, 2 = mid, 3 = high |
r_SpeedSetpoint_rpm |
REAL | 0.0 | Resolved RPM after selector decode |
r_SpeedSetpoint_norm |
REAL | 0.0 | 0.0–1.0 normalized for analog / PROFINET |
r_RampAccel |
REAL | 500.0 | Acceleration in RPM/s |
r_RampDecel |
REAL | 500.0 | Deceleration in RPM/s |
b_DriveEnable |
BOOL | FALSE | Master enable to drive |
b_FaultAck |
BOOL | FALSE | Fault acknowledgement pulse |
Method 1 — Pure Ladder Logic (FBD/LAD) Decode
This is the most beginner-friendly implementation and mirrors the way the question is typically written in an educational ladder context. Three input bits are mutually exclusive (priority encoder style, where the highest-numbered button wins, matching common HMI ergonomics).
Network 1: Speed selector priority encoder
I0.0 I0.1 I0.2
| | |
+--[ ]+--[ ]+--[ ]----+ // button 100
|
[MOVE 3 -> i_SpeedSelector]
Network 2:
I0.0 I0.1
| |
+--[ ]+--[ ]+--[NOT I0.2]--+ // button 10
|
[MOVE 2 -> i_SpeedSelector]
Network 3:
I0.0
| [NOT I0.1] [NOT I0.2]
+--[ ]+--[ ]--------[ ]--------+ // button 1
|
[MOVE 1 -> i_SpeedSelector]
Network 4: No button pressed -> stop
[NOT I0.0] [NOT I0.1] [NOT I0.2]
+--[ ]-------[ ]--------[ ]--------+
|
[MOVE 0 -> i_SpeedSelector]
Each network is a 3-input AND plus a MOVE box. The priority order (100 wins over 10 wins over 1) is enforced by the inverted contacts in networks 2 and 3. This pattern compiles to roughly 12 Boolean operations in the S7-1200 — well within any CPU's scan budget.
Method 2 — SCL CASE Block (Recommended)
A single SCL block is easier to maintain, easier to extend to 7 or 15 presets, and is what TIA Portal V16+ generates by default when you drop in a CASE construct. Place this in OB1 or a cyclic OB:
// FB_SpeedSelect — resolved RPM from three buttons
#i_SpeedSelector := 0;
IF "I0.2" THEN
#i_SpeedSelector := 3; // 100 button pressed
ELSIF "I0.1" THEN
#i_SpeedSelector := 2; // 10 button pressed
ELSIF "I0.0" THEN
#i_SpeedSelector := 1; // 1 button pressed
END_IF;
CASE #i_SpeedSelector OF
0: #r_SpeedSetpoint_rpm := 0.0;
1: #r_SpeedSetpoint_rpm := 100.0;
2: #r_SpeedSetpoint_rpm := 1000.0;
3: #r_SpeedSetpoint_rpm := 2000.0;
END_CASE;
I0.3, you only extend the IF/ELSIF chain and add one CASE branch. No network rewiring required.Method 3 — BCD-to-Integer Decode (Legacy S7-200 Style)
If the buttons are wired as a binary-coded group into a single byte input (for example through an IB0 byte where bits 0, 1 and 2 each represent the 1, 10 and 100 selector), the PLC can interpret the byte directly as a BCD value. This is the historical way the question's poster originally framed it:
// I0.0 = 1, I0.1 = 10, I0.2 = 100, all fed into IB0
// mask and shift to build a 1..3 selector
#i_SpeedSelector := ("IB0" AND 16#07); // isolate lower 3 bits
The risk of Method 3 is that two simultaneous button presses produce the bit pattern 011 which decodes to 3 (= high speed) and could be hazardous. For machinery subject to ISO 13849-1 PL d or higher, prefer the mutually-exclusive contact logic of Methods 1 or 2, or add a debounce/interlock in the HMI.
Wiring the Three Buttons
| Button | PLC input | SM 1221 terminal | Function |
|---|---|---|---|
| S1 (1) | I0.0 | Terminal 6 | Low speed preset |
| S2 (10) | I0.1 | Terminal 7 | Medium speed preset |
| S3 (100) | I0.2 | Terminal 8 | High speed preset |
| S4 (E-Stop) | I0.3 | Terminal 9 | Safety stop, hardwired through safety relay |
Wire each pushbutton as a normally-open contact between the 24 V DC source and the S7-1200 digital input. Use the internal 24 V sensor supply from the CPU (terminals L+ and M) for short cable runs (<10 m); for longer runs, use a regulated external 24 V supply referenced to the same ground as the CPU. Reference the S7-1200 System Manual, Section 5.3 Wiring.
Delivering the Setpoint to the Drive
Analog Output Implementation (SM 1232)
Scale the resolved RPM into the 0–27648 raw count range of the SM 1232 and write the output word each scan:
// Convert RPM to normalized 0..1 then to raw count
IF #r_MaxSpeed_rpm > 0.0 THEN
#r_SpeedSetpoint_norm := LIMIT(0.0, #r_SpeedSetpoint_rpm / #r_MaxSpeed_rpm, 1.0);
ELSE
#r_SpeedSetpoint_norm := 0.0;
END_IF;
#i_AO_raw := REAL_TO_INT(#r_SpeedSetpoint_norm * 27648.0);
"QW0" := #i_AO_raw;
PROFINET / PROFIdrive Implementation
For a SINAMICS V90 PN, standard telegram 1 is mapped automatically when you drag the drive from the TIA Portal device catalog into the project and assign it to the S7-1200 PROFINET interface. The relevant tags appear in the device's I/O mapping:
| Direction | Tag | Address | Meaning |
|---|---|---|---|
| Input | ZSW1 | IW64 | Status word from drive |
| Input | NIST | IW66 | Actual speed (signed, normalized) |
| Output | STW1 | QW64 | Control word to drive |
| Output | NSOLL | QW66 | Speed setpoint (signed, normalized) |
The standard control word bits that must be set in sequence to enable the drive are:
| Bit | Name | Required for enable |
|---|---|---|
| 0 | ON/OFF1 | 1 |
| 1 | OFF2 (coast stop) | 1 |
| 2 | OFF3 (quick stop) | 1 |
| 3 | Enable operation | 1 |
| 7 | Acknowledge fault | 0→1 edge on fault |
Drive Onboard Preset Implementation
Set p1020 = 722.0, p1021 = 722.1, p1022 = 722.2 on the V90 PN (mapping the drive's internal DI0/DI1/DI2 to fixed setpoint selectors 0/1/2). Then assign the actual RPM values to p1001 = 100.0, p1002 = 1000.0, p1003 = 2000.0. The PLC just drives three outputs to the drive's DI terminals; the drive handles the switching in <5 ms with hardware-level debouncing.
Adding Acceleration and Deceleration Ramps
A direct step change from 0 to 2000 RPM will fault most drives (F30002 overvoltage, F07900 motor overload, or torque limiter trips). Implement a software ramp on the PLC side or rely on the drive's ramp parameters. Software ramp in SCL:
// FB_Ramp — linear ramp of r_SpeedSetpoint_rpm
#dt := TIME_TO_REAL(#cycleTime) / 1000.0; // seconds per scan
IF #r_Target_rpm > #r_Actual_rpm THEN
#r_Actual_rpm := MIN(#r_Target_rpm, #r_Actual_rpm + #r_RampAccel * #dt);
ELSIF #r_Target_rpm < #r_Actual_rpm THEN
#r_Actual_rpm := MAX(#r_Target_rpm, #r_Actual_rpm - #r_RampDecel * #dt);
END_IF;
Call FB_Ramp from a cyclic OB (for example OB30 at 100 ms). Set r_RampAccel = 2000.0 RPM/s for a 1-second 0-to-2000 ramp — a typical safe value for a small servo axis.
HMI Display and Operator Feedback
On a TP700 Comfort or KTP700 panel, drop a numeric output field bound to r_SpeedSetpoint_rpm and three indicator lamps bound to i_SpeedSelector = 1, 2, 3. Add an "Acknowledge fault" button wired to b_FaultAck for operator recovery.
| HMI element | Tag | Behavior |
|---|---|---|
| Numeric display | r_SpeedSetpoint_rpm |
Format "9999 rpm" |
| Lamp "Low" | i_SpeedSelector == 1 |
Green when selected |
| Lamp "Med" | i_SpeedSelector == 2 |
Yellow when selected |
| Lamp "High" | i_SpeedSelector == 3 |
Red when selected |
| Lamp "Stopped" | i_SpeedSelector == 0 |
Grey when stopped |
| Fault banner | b_DriveFault |
Visible on any drive fault |
Safety Integration
Route the cabinet E-Stop through a safety relay (for example SIRIUS 3SK1) whose output cuts both the drive STO input and the controller's b_DriveEnable coil. In the PLC, add a normally-closed contact of the safety OK tag in series with every MOVE that loads a non-zero setpoint:
IF NOT "Safety_OK" THEN
#r_SpeedSetpoint_rpm := 0.0;
#b_DriveEnable := FALSE;
END_IF;
For applications that must meet ISO 13849-1 PL d or higher, use a failsafe CPU (S7-1200 FC) and run the enable logic in a failsafe DB, see the SIMATIC Safety - Configuring and Programming manual.
Verification Procedure
- Compile the SCL block with no errors. TIA Portal should report "0 errors, 0 warnings" in the Info pane.
- Download to the S7-1200 in STOP mode, then perform a warm restart.
- Go online in TIA Portal and force
I0.0 = TRUE. The watch table should showr_SpeedSetpoint_rpm = 100.0. - Force
I0.1 = TRUE; expect 1000.0. ForceI0.2 = TRUE; expect 2000.0. - Force all three simultaneously; verify the priority encoder selects the highest (2000 RPM).
- Drop all forces. Set
b_DriveEnable = TRUE. Confirm the drive enables and the actual RPM follows the setpoint within ±2 %. - Press the cabinet E-Stop. Confirm the drive STO triggers within 20 ms and the S7-1200 reports
Safety_OK = FALSE. - Release E-Stop, pulse
b_FaultAck, and confirm the drive clears its fault and is ready to enable again. - Record all six RPM values from the drive's actual-speed feedback into a commissioning log.
Troubleshooting Matrix
| Symptom | Likely cause | Corrective action |
|---|---|---|
| No response to any button | 24 V missing at SM 1221 input terminals; sensor supply fuse blown | Check L+/M terminals, measure 24 V DC, replace fuse if open |
| Always reads 0 RPM | Selector priority logic inverted; inputs mapped to wrong process image | Open the watch table and inspect I0.0..I0.2; verify device configuration in TIA Portal |
| Drive runs at full speed at enable | Default analog value is 10 V (V20/V90 factory default) | Set p2900 reference speed and p1120/p1121 ramp times on the drive before first enable |
| Drive faults F30002 (DC link overvoltage) | Ramp-down too aggressive for inertia | Increase r_RampDecel or drive parameter p1121; add braking resistor |
| Drive faults F07900 (motor overload) | Preset 2000 RPM exceeds motor nameplate speed | Confirm motor nameplate max RPM; derate r_SpeedSetpoint_rpm accordingly |
| PROFINET: drive not reachable | Device name mismatch or wrong IP | Assign the device name from TIA Portal (Online → Accessible nodes → Assign PROFINET device name) |
| PROFINET: NSOLL has no effect | STW1 bit 3 not set, drive still in "ready to power on" state | Sequence ON/OFF1 (bit 0), OFF2 (bit 1), OFF3 (bit 2), Enable (bit 3) in order |
| HMI shows stale value | HMI acquisition cycle too slow or pointer tag wrong | Set acquisition mode to "Cyclic continuous", 500 ms, on the HMI tag |
Extending to More Presets
If the machine later requires 7 fixed speeds, switch the three-button approach to a 3-bit binary selector on inputs I0.0..I0.2 and expand the CASE statement:
#i_SpeedSelector := "IB0" AND 16#07; // 0..7 from three inputs
CASE #i_SpeedSelector OF
0: #r_SpeedSetpoint_rpm := 0.0;
1: #r_SpeedSetpoint_rpm := 100.0;
2: #r_SpeedSetpoint_rpm := 250.0;
3: #r_SpeedSetpoint_rpm := 500.0;
4: #r_SpeedSetpoint_rpm := 1000.0;
5: #r_SpeedSetpoint_rpm := 1500.0;
6: #r_SpeedSetpoint_rpm := 2000.0;
7: #r_SpeedSetpoint_rpm := 3000.0;
END_CASE;
For applications needing 15 or 31 presets, use a rotary selector switch (4-bit BCD) wired to a 4-input byte. The same CASE architecture handles arbitrary combinations.
FAQ
What is the simplest way to drive three preset motor speeds from an S7-1200?
Use three digital inputs (I0.0, I0.1, I0.2) wired to three pushbuttons, decode them in a priority encoder or a single SCL CASE block to produce an INT selector (0, 1, 2, or 3), and map the selector to the corresponding RPM setpoint. The simplest drive interface is the drive's onboard fixed-setpoint inputs (configured via parameters p1001–p1015 on a SINAMICS V90 PN).
Should I use analog ±10 V or PROFINET to send the setpoint?
PROFINET with PROFIdrive (standard telegram 1) is the modern, deterministic choice and is recommended for any new build. Analog ±10 V via an SM 1232 AO module remains valid for retrofitting legacy drives that lack a fieldbus option, but it requires shielded wiring and is susceptible to drift over long cable runs.
How do I stop the motor when the operator releases all three buttons?
Add a "no button pressed" branch in the priority encoder (i_SpeedSelector := 0) that forces the RPM setpoint to 0.0 and clears the drive enable bit. For safety-classified machinery, also break the enable through a hardwired E-Stop loop so that a PLC scan stall cannot leave the motor running.
How do I prevent a step change from 0 to 2000 RPM from faulting the drive?
Insert a software ramp on the PLC side (linear acceleration of 1000–3000 RPM/s is typical for small servos), or configure the drive's internal ramp parameters (p1120 acceleration, p1121 deceleration on a SINAMICS V90 PN). A 1-second ramp from 0 to 2000 RPM is a safe starting point for a 400 W class servo.
Can I use a single PROFINET telegram for both control and setpoint?
Yes. Standard telegram 1 on the SINAMICS V90 PN contains both the 16-bit control word (STW1, output from PLC) and the 16-bit speed setpoint (NSOLL, output from PLC) in the same cyclic frame. Set p922 = 1 on the drive and TIA Portal will auto-map STW1 to QW64 and NSOLL to QW66 on the S7-1200 PROFINET device image.