Scale an analog output
The Core Idea
Analog output scaling converts a command in useful units, such as requested valve opening in percent, into the signal an output device accepts. It translates the requested action rather than measuring what the device actually did.
What you will learn
Convert a requested 0–100% valve opening to a 4–20 mA output command.
Check the 0%, 50%, and 100% endpoints in Ladder and Structured Text.
Tell the commanded output apart from the measured process value.
Why it matters
A correct internal command still needs the correct output signal. Keeping commands separate from measurements makes that conversion easier to check.
The problem
A valve drive accepts 4–20 mA: 4 mA requests 0% open, and 20 mA requests 100% open. COMMAND_PCT is the requested opening in %. DRIVE_MA is the current in mA that the programmable logic controller (PLC) commands to its analog output. FLOW_LPM is a separate flow sensor reading in L/min. Flow may change after the valve moves, but the current calculation must use COMMAND_PCT, not FLOW_LPM.
The human-machine interface (HMI) shows Requested opening, Valve drive current, and a Measured flow (simulated) input you can adjust to stand in for a separate sensor. This is a command scaler, not a valve or flow process model: the display does not claim that valve travel or flow has been measured from the output current. This example assumes COMMAND_PCT is already within 0–100%; HMI analog setpoints and operator limits handles operator limits separately.
You need the input scaling idea from Scale a 4–20 mA signal. Here the direction is reversed: a useful engineering command becomes an electrical output.
Predict
If COMMAND_PCT is 0% while FLOW_LPM reads 30 L/min, what current should DRIVE_MA command? What should it command at 50% and 100%? Should changing the measured flow alone change the commanded current?
Try it
Change Requested opening from 0% to 50% to 100%. Watch Valve drive current change from 4 mA to 12 mA to 20 mA. Hold the requested opening at 50% and change Measured flow (simulated) from 30 L/min to 70 L/min: the command stays at 12 mA. This simulator does not model the fluid response to valve movement.
Check your prediction
At 0%, the output is 4 mA, not 0 mA. At 50%, it is 12 mA; at 100%, it is 20 mA. A different flow reading alone does not change the output command.
Look closer
Pause and step one scan at 50% requested opening. Follow SPAN_MA_X100 (% × mA), then SPAN_MA (mA above live zero), then DRIVE_MA (mA). The first two math blocks select half of the 16 mA span. The final block adds 4 mA. The FLOW_LPM reading in L/min never enters those blocks.
The same three assignments in Structured Text are:
SPAN_MA_X100 := COMMAND_PCT * 16.0;
SPAN_MA := SPAN_MA_X100 / 100.0;
DRIVE_MA := 4.0 + SPAN_MA;Whether you read the Ladder blocks or these Structured Text assignments, test the same endpoints and midpoint. Both implementations are checked against the same cases.
Change it
The guided program calculates the 16 mA span correctly but omits the 4 mA live zero in its final block. At 0%, it incorrectly commands 0 mA. Change just that final addition, then compare 0%, 50%, and 100% again. Run the checks to confirm the repair.
Check yourself
Build the full Ladder output scale from an empty challenge program. A correct result sends 4 mA at 0%, 12 mA at 50%, and 20 mA at 100%. Hidden checks also use 25% and 75%, and change measured flow independently. Retry as often as you need.
Hint 1: Find the spanHow many mA lie between the low and high output currents?
Hint 2: Find the offsetScale the requested 0–100% across the 16 mA span, then add the low output current.
Hint 3: Build the three blocksMultiply COMMAND_PCT by 16 into SPAN_MA_X100, divide by 100 into SPAN_MA, then add 4 into DRIVE_MA.
Show a worked solution
Use a multiply block for SPAN_MA_X100 = COMMAND_PCT × 16, a divide block for SPAN_MA = SPAN_MA_X100 ÷ 100, and an add block for DRIVE_MA = SPAN_MA + 4. Keep the calculations in this order so each scan writes the intermediates before the final output. At 0%, the span contribution is 0 mA and the output is 4 mA. At 100%, the contribution is 16 mA and the output is 20 mA. The Structured Text assignments in Look closer express the same steps.
What happened and why
The 0–100% request selects a position within the output current span. The PLC then adds the 4 mA live zero. This gives a nonzero current for the 0% command. DRIVE_MA is a command to an output channel; it does not prove the valve reached that opening. FLOW_LPM is a measured process value from a separate input and can differ from the command for many reasons.
Show the math
DRIVE_MA = 4 mA + (COMMAND_PCT ÷ 100%) × 16 mA
At 50%, the span contribution is 8 mA, so the commanded output is 12 mA. At 25%, it is 4 mA above live zero, so the command is 8 mA.
Common mistakes
Omitting live zero: 0% produces 0 mA and every current is 4 mA low. Add 4 mA after scaling the 16 mA span.
Using 20 mA as the span: 100% produces 24 mA after the offset. The span from 4 mA to 20 mA is 16 mA.
Using measured flow as the command: current changes when the flow sensor changes, even with a fixed requested opening. Scale
COMMAND_PCT; keepFLOW_LPMas an independent reading.
Platform notes
Analog output modules vary in the value they expect from the program. Some take an engineering current, while others take a configured raw output count. Configure and verify the real channel range before using this scale on hardware. This lesson models the current command in mA; it does not model wiring faults, valve position feedback, or a measured process response.
Enable JavaScript to run the embedded simulator and complete the interactive exercises.