How to Scale 4-20mA Signal in PLC: Simple Guide
To scale a
4-20mA signal in a PLC, first read the raw input value (usually 0-32767 or 0-4095). Then use the formula ScaledValue = ((RawValue - RawMin) / (RawMax - RawMin)) * (EngMax - EngMin) + EngMin to convert it to the engineering units you want.Syntax
The scaling formula in PLC code typically looks like this:
ScaledValue = ((RawValue - RawMin) / (RawMax - RawMin)) * (EngMax - EngMin) + EngMin
Where:
- RawValue is the PLC input reading (e.g., 0-32767)
- RawMin is the minimum raw input (e.g., 6553 for 4mA)
- RawMax is the maximum raw input (e.g., 32767 for 20mA)
- EngMin is the engineering unit minimum (e.g., 0°C)
- EngMax is the engineering unit maximum (e.g., 100°C)
structured_text
ScaledValue := ((RawValue - RawMin) / (RawMax - RawMin)) * (EngMax - EngMin) + EngMin;
Example
This example shows how to scale a 4-20mA input from a temperature sensor that reads 0-100°C. Assume the PLC analog input raw range is 0-32767, where 4mA = 6553 and 20mA = 32767.
structured_text
VAR RawValue : INT; (* Raw analog input from PLC *) ScaledTemp : REAL; (* Temperature in °C *) RawMin : INT := 6553; (* Corresponds to 4mA *) RawMax : INT := 32767; (* Corresponds to 20mA *) EngMin : REAL := 0.0; (* 0°C *) EngMax : REAL := 100.0; (* 100°C *) END_VAR (* Example raw input *) RawValue := 19610; (* Example raw reading *) (* Scaling calculation *) ScaledTemp := ((REAL(RawValue) - REAL(RawMin)) / (REAL(RawMax) - REAL(RawMin))) * (EngMax - EngMin) + EngMin; (* Output scaled temperature *)
Output
ScaledTemp = 50.0
Common Pitfalls
- Not converting integer raw values to real/float before division causes integer division errors.
- Using wrong raw min/max values leads to incorrect scaling.
- Forgetting to subtract
RawMinshifts the scale incorrectly. - Mixing units or not matching engineering units with sensor specs causes confusion.
structured_text
(* Wrong: integer division and no subtraction of RawMin *) ScaledValue := (RawValue / RawMax) * (EngMax - EngMin) + EngMin; (* Correct: convert to REAL and subtract RawMin *) ScaledValue := ((REAL(RawValue) - REAL(RawMin)) / (REAL(RawMax) - REAL(RawMin))) * (EngMax - EngMin) + EngMin;
Quick Reference
Remember these key points when scaling 4-20mA signals in PLCs:
- 4mA usually corresponds to the minimum raw input value.
- 20mA usually corresponds to the maximum raw input value.
- Always convert integers to real numbers before division.
- Use the linear scaling formula to convert raw input to engineering units.
Key Takeaways
Use the linear scaling formula to convert raw PLC input to engineering units.
Always convert integer raw values to real before division to avoid errors.
Identify correct raw min and max values that correspond to 4mA and 20mA.
Subtract raw minimum before scaling to align the zero point correctly.
Match engineering unit range to your sensor's measurement range.