S7-300 PID Voltage Control with Digital Potentiometer Actuator

David Krause16 min read
Application NotePID ControlSiemens
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

System Overview

This reference covers a closed-loop voltage regulation retrofit for an existing multi-transformer DC bus originally trimmed by an operator turning a panel potentiometer. The objective is to keep the bus voltage inside a defined band (35-41 V DC in the source application) by replacing the manual pot with a current- or voltage-controlled digital potentiometer driven from a Siemens SIMATIC S7-300 CPU 315-2 DP PID loop. The same architecture applies to any slow electrical process: DC link voltage, generator field voltage, electrolyzer voltage, or static exciter field.

The control loop has three sections:

  • Process measurement: A DC voltage transducer (for example 0-50 V input, 4-20 mA output) drops the bus voltage into a range accepted by an S7-300 SM331 analog input module.
  • Controller: The S7-300 CPU executes the standard continuous PID block (FB41 CONT_C from the STEP 7 Standard Library) with the measured value as PV and an operator-entered or recipe-driven value as SP.
  • Final element: An analog output module (SM332) drives a 4-20 mA-to-resistance converter (digital potentiometer) that replaces the operator's hand pot. The wiper of the digital pot is wired into the existing control circuit (saturable reactor, motorised variac, or static exciter) so the PID output controls the same point the operator used to.
DC Bus 32-41 V 4 x Lincoln XFMR V Transducer 0-50 V to 4-20 mA SM331 AI PIW 0-27648 CPU 315-2 DP FB41 CONT_C SM332 AO PQW 4-20 mA DGP00 4-20 mA to ohm Digital Pot wiper to field ctl Sat Reactor / Field control input SP_Int / LMN_Per PV feedback (process path)

Hardware Selection

CPU and rack

The CPU 315-2 DP referenced in the source is a classic S7-300 processor. Common catalog variants include the 6ES7315-2AF03-0AB0 or later 6ES7315-2AH14-0AB0, each delivering 128 KB / 256 KB of work memory, a PROFIBUS DP master/slave interface, and 24 V DC power. The DP suffix is irrelevant to the PID function but is useful if the cell is integrated into a larger PROFIBUS or PROFINET line. For more details, refer to the S7-300 product page on the Siemens S7-300 product page and the documentation index on the Siemens Industry Online Support portal.

Analog input module

For a single voltage loop, an 8-channel SM331 is the typical choice. Use a 4-wire current input channel configured for 4..20 mA in HW Config. Two common part numbers:

Catalog Resolution Channels Notes
6ES7331-1KF02-0AB0 13 bit 8 AI Cost-effective; ~1.2 mV LSB on 0-10 V
6ES7331-7NF10-0AB0 16 bit 8 AI Recommended for narrow-band control (35-41 V on 50 V span)
6ES7331-7KF02-0AB0 13 bit 8 AI, 24 V variant Diagnostic interrupts, hot-swap capable

The 16-bit module reduces the LSB to roughly 0.76 mV on a +/-10 V range, which is finer than the 13-bit alternative and reduces quantization-induced jitter that would otherwise force a wider dead-band.

Analog output module

The SM332 family supplies the 4-20 mA drive to the digital potentiometer. Use a 4-20 mA current output (not voltage) when the digital potentiometer is loop-powered:

Catalog Resolution Channels Use
6ES7332-5HF00-0AB0 12 bit 8 AO Current output, 4-20 mA, common
6ES7332-7ND02-0AB0 16 bit 8 AO High accuracy, current and voltage
6ES7332-5HD01-0AB0 12 bit 4 AO Voltage output 0-10 V if actuator accepts it

With a 4-20 mA output the 16-bit module resolves to roughly 0.244 uA per LSB, which is well below any noise floor the actuator will see.

Digital-to-potentiometer converter

Two commercial units are typically used in this kind of retrofit:

  1. Edisa DGP00 - 4-20 mA input, 100 ohm / 1 kohm / 10 kohm wiper output. The Edisa DGP00 product page lists it as a DIN-rail mounted, loop-powered solid-state substitute for a manual pot.
  2. APCs ATP168 Analog-to-Potentiometer - documented in the APCs ATP168 reference design as a voltage- or current-driven resistance output.

When sizing, three parameters must be matched:

  • Input signal range (4-20 mA vs 0-10 V) must match the SM332 output configuration.
  • Wiper resistance range must match the existing manual pot (typically 1 kohm, 5 kohm, or 10 kohm linear).
  • End-to-end resistance must be at least an order of magnitude higher than the load it controls, so the converter does not have to dissipate significant power.

Power supply

A 6ES7307-1EA01-0AA0 (PS 307, 5 A) covers the CPU and a single AI/AO pair. If the digital potentiometer is loop-powered from the 4-20 mA output, no separate supply is required for the actuator.

Signal Conditioning for the 32-41 V Bus

If a 4-20 mA transducer is not already installed on the DC bus, the input can be derived from a passive resistor divider. Given a 0-50 V bus, a 4:1 divider (for example three 100 kohm in series with a 33 kohm to ground) presents 10 V at the top of the divider when the bus is at 50 V and 8.2 V at 41 V. The scaling line is then:

  • 0 V bus = 0 V divider = 0 mA (4 mA offset if 4-20 mA transducer is used)
  • 35 V bus = 7.0 V divider
  • 41 V bus = 8.2 V divider
  • 50 V bus = 10 V divider

A 1 Mohm total divider draws 50 uA at 50 V, which is negligible compared to the bus capacity, but the divider must be referenced to a clean analog ground at the SM331. Use 0.1 percent or better metal-film resistors if you intend to derive the engineering range from the divider alone; a typical 1 percent divider will introduce 0.25 V of error at the 41 V setpoint.

For a 4-20 mA transducer the engineering scale is:

PV_engineering (V) = (AI_raw - 0) * (V_max - V_min) / 27648 + V_min

where AI_raw is the value returned by the S7-300 analog input driver (0-27648 integer, signed 16-bit word), and V_min / V_max are the engineering zero and full scale of the transducer. For a 0-50 V transducer the formula simplifies to:

PV_engineering (V) = AI_raw * 50.0 / 27648.0

For a 0-10 V analog output, the manipulated value scaling to PQW is:

LMN_PER = LMN (%) * 27648.0 / 100.0

Analog I/O Wiring

For 4-wire current input on SM331:

Transducer (+) --- Channel n+ (Pin 2 of the AI front connector)
Transducer (-) --- Channel n- (Pin 3)
Transducer V+ --- 24 V DC (separate supply)
Transducer V- --- 24 V return

For 4-20 mA current output on SM332 to a loop-powered DGP00:

SM332 AQ0+ --- DGP00 IN+
DGP00 IN- --- SM332 AQ0-
(Loop is completed through the converter internal shunt)
Critical wiring notes:
  • Use shielded, twisted-pair cable for both AI and AO. Ground the shield at the cabinet end only; never at both ends, or ground-loop currents will inject 50/60 Hz noise into PV.
  • Run the AI/AO cables in a separate conduit from the field wiring of the saturable reactor; the dV/dt on the field is hundreds of volts per microsecond and will couple capacitively into the analog loop if they share a tray.
  • Maintain at least 200 mm separation from any VFD or thyristor-stack cabling.
SM331 AI ch0 4-wire, +/-20 mA terminals 2/3/4/5 V Transducer 0-50 V in / 4-20 mA out loop-powered or 4-wire 24 V DC supply galvanically isolated SM332 AO ch0 current output 4-20 mA terminals 14/16 DGP00 / ATP168 4-20 mA in / ohm out DIN-rail mount Field control pot wiper to existing ckt manual/auto switch

PID Implementation with FB41 CONT_C

The S7-300/400 firmware library (STEP 7 V5.x) provides the FB41 "CONT_C" continuous PID controller. It is the standard block for slow electrical control and is referenced in the Siemens Industry Online Support documentation library. For a general overview of PID theory and architecture, see the National Instruments PID theory primer, the Wikipedia PID controller entry, and the DigiKey "How to Control Output Voltage using a PID" tutorial. A TIA Portal target can use the equivalent PID_Compact block in the PID_Compact library.

FB41 inputs and outputs

Parameter Direction Purpose Typical initial value
SP_INT IN Setpoint in engineering units (REAL) 38.0 V (mid-band)
PV_IN IN Process variable in engineering units AI scaled value
PV_PER IN Peripheral (raw) process value (0-27648) Optional, link to PIW directly
MAN IN Manual manipulated value 0.0
MAN_ON IN Manual mode enable (BOOL) FALSE
GAIN IN Proportional gain 0.8
TI IN Integral time (s) 20.0
TD IN Derivative time (s) 0.0 (no D action initially)
TM_LAG IN Derivative lag (s) 0.0
DEADB_W IN Dead-band width (engineering units) 0.1
LMN_LLM / LMN_HLM IN Manipulated value low/high limit 0.0 / 100.0 (%)
PV_FAC / PV_OFF IN PV scaling and offset 1.0 / 0.0
LMN OUT Continuous manipulated value (REAL, %) Wired to AO scaling
LMN_PER OUT Peripheral manipulated value (0-27648) Wired to PQW directly
CYCLE STAT Sample time (s) 0.1 s typical

For voltage control of a slow thermal/electrical process, a 100-250 ms scan is appropriate. Faster than 50 ms is rarely useful because the field response is dominated by L/R time constants on the order of hundreds of milliseconds.

Sample ST code for FB41 instance

// Voltage PID - FB41 instance
DATA_BLOCK "DB_VoltPID"
    "CONT_C"    // FB41 instance body
BEGIN
    SP_INT   := 38.0;          // Setpoint 38 V
    PV_IN    := "DI_Voltage".EngVal;
    PV_PER   := 0;
    MAN      := 0.0;
    MAN_ON   := FALSE;
    GAIN     := 0.8;
    TI       := 20.0;
    TD       := 0.0;
    TM_LAG   := 0.0;
    DEADB_W  := 0.1;
    LMN_LLM  := 0.0;
    LMN_HLM  := 100.0;
    PV_FAC   := 1.0;
    PV_OFF   := 0.0;
END_DATA_BLOCK

// In OB35 (cyclic interrupt 100 ms)
CALL "CONT_C", "DB_VoltPID"
    SP_INT   := "DB_VoltPID".SP_INT
    PV_IN    := "DI_Voltage".EngVal
    MAN      := 0.0
    MAN_ON   := FALSE
    GAIN     := "DB_VoltPID".GAIN
    TI       := "DB_VoltPID".TI
    TD       := "DB_VoltPID".TD
    LMN_PER  := "PQW_VoltageOut";

LMN_PER is preferred for the SM332 because the controller writes the manipulated value directly to the analog output peripheral (0-27648) and avoids a second engineering-to-raw conversion.

Dead-band and limits

For a 35-41 V control band the engineering span is 6 V. The dead-band should be set to 0.05-0.1 V (1-2 percent of span) to suppress noise-driven cycling when the bus is steady. Manipulated value limits clamp the output to the physical range of the digital potentiometer; for a 4-20 mA actuator, LMN_LLM = 0 percent and LMN_HLM = 100 percent ensure the loop never commands outside the converter's input range.

PID Tuning

Use this three-step procedure for the FB41 voltage loop:

  1. Manual step test. Set MAN_ON = TRUE and drive MAN from 0 percent to 100 percent in 5 percent steps. Log PV. The process curve identifies the process gain Kp_process (engineering units per percent LMN) and the dominant lag tau_p.
  2. P-only critical gain. Switch to automatic with TI = very large, TD = 0. Increase GAIN until the loop oscillates continuously. Critical gain Kc and period Pc give Ziegler-Nichols starting values: GAIN_start = 0.5 * Kc TI_start = 0.8 * Pc TD_start = 0
  3. Fine tune. Step the setpoint 1 V up and 1 V down. Adjust GAIN for fast rise without overshoot greater than 5 percent, then reduce TI by 20 percent at a time until the loop returns to setpoint in 2-3 cycles with no oscillation. Add a small TD only if the saturable reactor shows mechanical/electrical lag.

For voltage control, the system is normally overdamped by the L/R time constant of the field winding, so P-only is often sufficient and the integral term handles offset. If a saturable reactor is in the loop, the magnetising curve introduces nonlinearity; a derivative term on PV helps anticipate the field response. Tuning-time formulas useful in this step are:

Closed-loop bandwidth (rad/s) ~ sqrt(Kp * Kc) / tau_p Expected overshoot (%) ~ exp(-PI * zeta / sqrt(1 - zeta^2)) * 100

where zeta is the damping ratio you read off the step response. Targets for a 6 V span are zeta between 0.7 and 1.0, overshoot between 2 percent and 6 percent, and settling time under 3 s for a 1 V setpoint step.

Anti-Windup and Bumpless Transfer

FB41 integrates an internal anti-windup that holds the integrator when LMN is at LMN_LLM or LMN_HLM. To preserve anti-windup, do not clamp LMN downstream of the block; instead, set LMN_LLM and LMN_HLM to the physical range of the actuator (for example 0 percent and 100 percent).

Bumpless transfer from manual to automatic is critical when the operator is still commissioning. The integrator must be pre-loaded so LMN at the moment of switching equals the manual MAN value. With FB41 the procedure is:

  1. Run the block in manual mode for at least 5 cycles so I_ITVAL settles to MAN.
  2. Click "Update" in the PID control panel (or write 1 to the COM_RST input) so the integrator takes the MAN value as its initial state.
  3. Switch MAN_ON from TRUE to FALSE. The transition is bumpless only if SP_INT and MAN are within 50 percent of each other; outside that range the block ramps the output smoothly.
Anti-windup trap: If the saturable reactor is already at saturation when the loop starts, the integrator will wind up to 100 percent the first time the bus exceeds setpoint. Always pre-load the integrator from MAN before the first AUTO transition.

Safety Considerations

  • The DC bus is at 32-41 V, which is below the 50 V SELV threshold but can deliver hundreds of amps through 4 parallel Lincoln transformers. The current loop is a burn and arc-flash hazard; the control wiring must be physically segregated from the power cabling.
  • Wire the digital potentiometer in parallel with the existing manual pot, with a manual/auto selector switch. This allows the operator to override the PID in case of a sensor failure or PID instability.
  • Add a hardwired interlock that opens the field contactor if the measured bus voltage exceeds 43 V (1 V above the operator's manual limit) for more than 5 s. This backstop runs in the PLC's discrete I/O and does not depend on the PID path.
  • Configure a watchdog on the analog output: if FB41 is no longer called in OB35 for more than 1 s, force the SM332 to 0 percent (4 mA) using the analog output default. The digital potentiometer should be configured to "fail to mid-scale" or "fail to 0 percent" based on the actuator's safe state.
  • Fuse the 4-20 mA loop and the transducer supply independently of the PLC supply so that a short on the field side does not crash the SIMATIC rack.
  • Enable SM331 diagnostic interrupts in HW Config. A wire break on the AI raises a diagnostic OB (OB82) which can drop LMN_PER to 0 percent and trip the interlock within one scan.

HMI Integration

Display on the HMI (WinCC flexible or TIA Portal Panel) the following fields:

  • Setpoint (operator entry, 30-43 V, clamped in HMI).
  • Process value (live, decimal).
  • Manipulated value (0-100 percent).
  • Loop mode (AUTO / MANUAL).
  • Controller deviation (SP - PV).
  • I_ITVAL and PV_FAC for diagnostics.
  • Alarm history for PV_HI, PV_LO, AI break, watchdog timeout.

Allow the operator to switch to MANUAL and drive LMN from a slider; this is the primary commissioning tool and the primary fallback when the bus is unstable. Display the GAIN, TI, and TD as live fields and write them back to the instance DB so that tuning changes do not require an online download.

Commissioning Checklist

  1. Verify the polarity and scaling of the voltage transducer on the bench with a calibrated source.
  2. With the field contactor OPEN, force the SM332 to 0 percent, 50 percent, and 100 percent and confirm the digital potentiometer wiper moves to the expected resistance. For a 1 kohm pot, 0 percent should read near 0 ohm wiper-to-end, 50 percent near 500 ohm, 100 percent near 1 kohm.
  3. Engage the field with a 5 percent LMN step and observe PV; confirm the polarity (raising LMN should raise PV, otherwise swap the wiring at the digital pot or invert GAIN).
  4. Run the P-only step test, record Kc, and compute initial GAIN/TI.
  5. Switch to AUTO and walk the setpoint through 35 V, 38 V, 41 V; observe the response. Acceptable overshoot is 1-2 percent on a 6 V span.
  6. Force a perturbation: bump the load current or step a parallel transformer on/offline. The loop should recover in 2-4 cycles without ringing.
  7. Trip the watchdog: pull the analog input transducer. The PLC should drop LMN to 0 percent (4 mA) within the watchdog time and the interlock should open the field contactor.
  8. Hand back to OPERATOR AUTO with a written record of the final GAIN, TI, TD, and dead-band values.

Troubleshooting Matrix

Symptom Likely cause Action
PV reads 0 even though bus is live Transducer open / wrong polarity / wrong AI range Check wiring and HW Config; verify AI diagnostic LEDs
PV swings full scale 0/100 Wiring reversed on the transducer Reverse the AI leads
Loop oscillates continuously at high frequency Derivative action on a noisy PV Increase TM_LAG, lower TD, or filter PV with a first-order lag
Loop oscillates at low frequency (period several seconds) GAIN too high, TI too short Cut GAIN by 30 percent, double TI
Slow approach to SP with no oscillation GAIN too low, TI too long Double GAIN, halve TI
Manipulated value pegs at 0 or 100 and PV does not recover Anti-windup clamp; SP is out of range Verify setpoint is inside the actuator's physical control range
Bus voltage is unstable even with PID running The 4 transformers are interacting / out of phase Lower GAIN; consider sequencing the four converters with a single PID
Output of digital pot drifts with temperature Resistor drift in the converter Verify manufacturer spec; install in a temperature-stable enclosure
PLC stops updating PQW after a download OB35 not downloaded or wrong priority Confirm OB35 is in the active S7 program and is being called
PV reads correct value in MANUAL but loop diverges in AUTO GAIN sign reversed Invert GAIN (multiply by -1) and re-test

Frequently Asked Questions

Which PID block should I use in S7-300 for voltage control?

Use FB41 CONT_C from the STEP 7 Standard Library for STEP 7 V5.x projects, or PID_Compact in TIA Portal. Both provide continuous (analog) output, anti-windup, and bumpless transfer, and they are the documented Siemens blocks for slow electrical regulation. Avoid PULSEGEN (FB43) for this application because the final element is an analog resistance, not a switched valve.

How do I scale a 4-20 mA voltage transducer to engineering units in S7-300?

Use FC105 (SCALE) or compute directly with the formula PV = (AI_raw / 27648.0) * (V_max - V_min) + V_min. For a 0-50 V transducer mapped 4-20 mA, V_min = 0 and V_max = 50. The FC106 (UNSCALE) function reverses the conversion for the manipulated value going to the SM332 output.

Can I use a 0-10 V analog output to drive a digital potentiometer?

Yes, if the converter accepts 0-10 V. Configure the SM332 channel for voltage output and re-scale LMN_PER from the 0-20 mA range to 0-10 V (27648 corresponds to 10 V). Note that loop-powered 4-20 mA converters are simpler to wire and offer a single fault mode (open loop = 4 mA = 0 percent) that the PLC can detect.

What happens if the analog input loses its signal?

An SM331 input configured for 4-20 mA will underrange to 0 mA and the PIW will read 0 (or a negative value). With diagnostic interrupts enabled, OB82 fires and your program can force LMN_PER to 0 percent and trip the field contactor. Test this scenario on the bench by pulling the transducer; the interlock should engage within one OB35 cycle.

How do I handle bumpless transfer from MANUAL to AUTO with FB41?

Run the controller in MANUAL with MAN at the current output for at least 5 sample periods, then write 1 to COM_RST to load the integrator from MAN, then flip MAN_ON from TRUE to FALSE. With SP_INT within 50 percent of the last MAN, the transition is bumpless; outside that range the controller ramps LMN at the rate set by the integral action.

Why is my loop stable in P-only but unstable when I add integral action?

The integrator reduces phase margin. If P-only is at GAIN = 0.4 * Kc and adding any TI causes oscillation, your TI is too short. Double TI and re-test; the loop should add integral action with no instability. If the bus has a long dead time (several seconds), you may need a Smith predictor or a PI with TI equal to the dead time.

Back to blog