SCL instruction

Say if I have two 4-20 ma transmitter for flow and the system measure flow in kpph

both 0-155 inwc and 0-150 kpph

how would that be scaled in the SCL instruction and how would you make it read the correct kpph on the hmi

Inrawmax
Inrawmin

inEUmax
InEUmin
 
Before the code, one thing in your numbers deserves a check, because it changes the answer completely.

Your ranges are 0-155 inwc and 0-150 kpph. inwc is a differential pressure (inches of water column). If this is a differential-pressure flow element — orifice plate, averaging pitot, venturi — then flow is proportional to the square root of DP, not to DP. That means a linear scaling is correct at 4 mA and at 20 mA and wrong everywhere in between.

With your numbers, at 12 mA (50 percent of the signal) a linear scaling gives 75 kpph. The square-root value is 150 x sqrt(0.5) = 106 kpph. About 41 percent low, at the one point people rarely check.

So the first question is not how to scale, it is: is the transmitter linear in kpph, or is it a DP device? If it is a DP device, the instrument data sheet will say so, and the calibration certificate will show whether it was squared in the transmitter or is still raw DP. If the transmitter is already squared (some smart DP transmitters output flow directly), then treat it as linear.

Case 1 — linear (transmitter output is already proportional to kpph)

KPph := (RawInwc - 0.0) * (150.0 - 0.0) / (155.0 - 0.0) + 0.0;
(* simplifies to: KPph := RawInwc * 0.96774; *)

Note that 150/155 = 0.96774, so a linear map is almost a 1:1 pass-through here. That is exactly why this mistake survives review — the numbers look like they are already in the right ballpark.

Case 2 — square root (raw DP in inwc)

Ratio := RawInwc / 155.0; (* 0..1 *)
IF Ratio < 0.001 THEN
KPph := 0.0; (* low-flow cutoff, see below *)
ELSE
KPph := 150.0 * SQRT(Ratio);
END_IF;

Two warnings for the square-root case:

First, sqrt amplifies noise near zero. At 1 percent of DP the flow is 10 percent, so any noise on the 4-20 mA signal becomes a visible jump in the displayed flow. Add a small low-flow cutoff (the 0.001 above is only an example — pick it from your actual noise floor, not from a round number someone likes).

Second, the input must be a REAL. If your raw input is 0-32767 counts and you divide by 155 before converting to REAL, integer division will silently truncate and you will get a staircase. Do the division in floating point.

On the HMI side, the important rule is: scale once, in the PLC, and send the engineering value. Do not send raw counts to the HMI and scale again there. Double scaling is the most common reason a display reads correctly at one end and wrongly in the middle, and it is invisible in the PLC code because the PLC part looks fine. Pick one owner for the conversion — I would put it in the PLC so that every consumer of that value gets the same number.

Whatever you choose, verify at three points, not two: 4 mA, 12 mA and 20 mA. A linear-versus-square-root error is exactly zero at both ends of the range, so a two-point check will always pass. The middle is where it shows.
 
Top