Analog Signal Processing: From Raw Reading to Engineering Value
4-20mA Signals: The Industrial Standard
The 4-20 mA current loop is the dominant analog signal standard in industrial automation. A transmitter varies its current output between 4 mA and 20 mA proportionally to the measured process variable.
Why 4 mA is the zero point, not 0 mA:
- Wire break detection: if the current drops to 0 mA, the PLC knows the wire is broken. A reading of 0 mA is always a fault.
- Power over the loop: the 4 mA minimum powers the transmitter in a 2-wire configuration
- Noise immunity: current signals are far less affected by cable length and electromagnetic interference than voltage signals
Common 4-20 mA applications include pressure transmitters (0-10 bar), temperature transmitters (0-200 degrees C), level transmitters (0-100% full), and flow meters (0-500 liters/min).
A 2-wire transmitter connects in series: +24V DC to the transmitter positive, transmitter negative to PLC analog input positive, PLC input negative to 0V DC.
0-10V Signals: When to Use Them
The 0-10V voltage signal is simpler to wire but has important limitations:
- No wire break detection: 0V could mean zero measurement or a broken wire
- Cable length sensitivity: voltage drops over long runs cause measurement errors
- Noise susceptibility: nearby motors and VFDs can corrupt the signal
Use 4-20 mA for cable runs over 50 meters, noisy environments, and when wire break detection is needed. Use 0-10V for short cables in clean environments and budget-constrained non-critical applications. VFD speed references commonly accept either standard.
Linear Scaling: Raw Value to Engineering Unit
Analog input modules convert the electrical signal into a raw integer. The program must scale this to engineering units using the linear scaling formula:
EngValue = EngLow + ((RawValue - RawLow) / (RawHigh - RawLow)) * (EngHigh - EngLow)
FUNCTION ScaleLinear : REAL
VAR_INPUT
nRawValue : INT;
rEngLow : REAL;
rEngHigh : REAL;
nRawLow : INT;
nRawHigh : INT;
END_VAR
IF nRawHigh <> nRawLow THEN
ScaleLinear := rEngLow +
(INT_TO_REAL(nRawValue - nRawLow) /
INT_TO_REAL(nRawHigh - nRawLow)) *
(rEngHigh - rEngLow);
ELSE
ScaleLinear := 0.0;
END_IF;
END_FUNCTION
Example: a pressure transmitter (0-10 bar, 4-20 mA) with Siemens raw range 0-27648. If the raw value reads 13824, the scaled pressure is 5.0 bar (exactly midpoint).
Digital Filtering: Smoothing Noisy Readings
Raw analog readings fluctuate due to electrical noise and vibration. The exponential filter is the most common smoothing method in PLC programs:
FUNCTION_BLOCK FB_ExponentialFilter
VAR_INPUT
rInput : REAL;
rAlpha : REAL; // 0.0 to 1.0
END_VAR
VAR_OUTPUT
rFiltered : REAL;
END_VAR
VAR
bFirstScan : BOOL := TRUE;
END_VAR
IF bFirstScan THEN
rFiltered := rInput;
bFirstScan := FALSE;
ELSE
rFiltered := rFiltered + rAlpha * (rInput - rFiltered);
END_IF;
END_FUNCTION_BLOCK
The alpha parameter controls filter strength: 0.1 for very smooth slow response (display values), 0.3 for moderate smoothing (process control), 0.5 for light smoothing (fast loops), and 1.0 for no filtering (debugging).
A moving average filter is also useful when you need a specific window of samples, storing values in a circular buffer array and computing the average across the window.
Detecting Analog Sensor Faults
A robust program must detect sensor failures. Common fault conditions:
Under-range (wire break): for 4-20 mA, a raw value below the minimum threshold indicates a broken wire.
bSensorFault := nRawValue < -1000;
Over-range: a raw value above maximum indicates a wiring fault.
bSensorFault := bSensorFault OR (nRawValue > 28500);
Rate-of-change: a sudden large jump may indicate a loose connection.
rChangeRate := ABS(rCurrentValue - rPreviousValue);
IF rChangeRate > rMaxAllowedChange THEN bSensorSuspect := TRUE; END_IF;
rPreviousValue := rCurrentValue;
When a fault is detected: freeze the last good value for short-duration faults, switch to a backup sensor if available, go to a safe state if no backup exists, and alert the operator via HMI alarm.
Practical Example: Reading and Calibrating a PT100 Temperature Sensor
A PT100 RTD monitors a filling machine's product tank. Requirements: 0-150 degrees C range, alarm at 120 (high) and 5 (low), fault detection with safe shutdown.
VAR
nTempRaw : INT;
rTempScaled : REAL;
fbTempFilter : FB_ExponentialFilter;
rTempFiltered : REAL;
bTempHighAlarm : BOOL;
bTempLowAlarm : BOOL;
bTempFault : BOOL;
bHeaterEnable : BOOL;
rTempPrevious : REAL;
END_VAR
// Step 1: Scale raw to engineering units
rTempScaled := ScaleLinear(nTempRaw, 0.0, 150.0, 0, 27648);
// Step 2: Detect sensor faults
bTempFault := (nTempRaw < -500) OR (nTempRaw > 28500);
IF NOT bTempFault THEN
bTempFault := ABS(rTempScaled - rTempPrevious) > 20.0;
END_IF;
rTempPrevious := rTempScaled;
// Step 3: Filter only if sensor is healthy
IF NOT bTempFault THEN
fbTempFilter(rInput := rTempScaled, rAlpha := 0.2);
rTempFiltered := fbTempFilter.rFiltered;
END_IF;
// Step 4: Check alarm limits
bTempHighAlarm := rTempFiltered > 120.0;
bTempLowAlarm := rTempFiltered < 5.0;
// Step 5: Safe action on fault or high alarm
IF bTempFault OR bTempHighAlarm THEN
bHeaterEnable := FALSE;
END_IF;
This demonstrates the complete analog processing chain: scaling, fault detection, filtering, alarm checking, and safe response. Every industrial analog channel should follow this pattern.
Summary
Industrial analog signals use either 4-20 mA current loops (preferred for noise immunity and wire break detection) or 0-10V voltage signals (simpler but less robust). Raw values must be linearly scaled to engineering units. Digital filters smooth noisy readings for stable control and display. Fault detection checks for under-range, over-range, and excessive rate-of-change, with safe response actions when problems are found. The PT100 example illustrates the complete processing chain that every analog channel in a professional PLC program should implement.