learn · South Africa
Scaling Analog Signals: Raw Counts, Units and Resolution
Practise scaling analog signals with raw-count and 4–20 mA examples, validity checks and resolution maths, plus South African instrumentation course tips.

Scaling analog signals converts a supplied numeric representation into meaningful units. The arithmetic is usually a linear map, but the result is trustworthy only when the input range, engineering range, data type and quality state are known. A correct formula applied to a diagnostic code still produces a misleading number.
This tutorial works through a fictional zero-to-five-thousand-millimetre level range. It distinguishes current in milliamps, a module's raw representation and the engineering value. It then tests validation, integer division, inverse conversion and the difference between count spacing and measurement accuracy.
For South African PLC and instrumentation learners, the practical objective is a reviewable scaling record: the configured range, expected endpoint values, intermediate calculations and behaviour when data is invalid. The examples are software calculations, not measurements from a real tank or evidence of instrument calibration.
Identify every representation in the signal chain
Begin by naming what each value represents. A transmitter's current, the integer received from an input module and the level shown on an HMI are different quantities. Do not use the word “raw” for all three without stating the units or encoding.
| Representation | Example meaning |
|---|---|
| Process quantity | The level the learning example intends to represent |
| Transmitter signal | A configured current range, such as 4–20 mA |
| Module value | The number and status supplied by a specific configured channel |
| Engineering value | The calculated result, such as millimetres |
| Display value | A formatted presentation of that calculated result |
Changing display decimals affects presentation. Changing the transmitter range affects the relationship between process quantity and signal. Changing the input channel's range can affect the module representation. Those changes need different investigations.
The analogue signal types guide provides the surrounding signal context. For this lesson, write the source representation and configuration alongside every test value before applying the scaling equation.
Use a documented raw range, not a brand-wide guess
The official Siemens S7-1200 current-input representation table shows zero corresponding to 4 mA and 27648 corresponding to 20 mA in its documented 4–20 mA column. The same table gives a different meaning to zero in the 0–20 mA column. The configured range is therefore part of the interpretation.
The table also distinguishes ordinary range values from diagnostic or exceptional representations. It identifies 32767 for a documented wire-break condition, as well as using that number in its overflow representation. A numeric code alone should not be turned into a unique physical diagnosis without its context.
For the worked arithmetic, assume a nominal raw interval from zero to 27648 and a fictional engineering interval from zero to 5000 mm. These are the explicit inputs to the example. They are not a claim that every Siemens channel or every PLC brand uses the same raw interval.
When implementing a real project, record the exact module, channel configuration, data format and applicable diagnostic information. If a value arrives already scaled in engineering units, applying the raw-count formula again would scale it twice.
Calculate the linear map from named endpoints
For a linear relationship, subtract the lower raw endpoint, divide by the raw span, multiply by the engineering span and add the lower engineering endpoint.
Fraction = (Raw - RawLow) / (RawHigh - RawLow)
EngineeringValue = EngineeringLow
+ Fraction * (EngineeringHigh - EngineeringLow)
The endpoint names are useful evidence. They show the intended mapping more clearly than unexplained multiplier and offset constants. A constant implementation can be valid, but its derivation and units should remain available for review.
For this example, RawLow is zero, RawHigh is 27648, EngineeringLow is zero and EngineeringHigh is 5000 mm. A raw value of 13824 gives a fraction of one half, so the result is 2500 mm.
| Supplied raw value | Fraction of nominal span | Expected level mm |
|---|---|---|
| 0 | 0 | 0 |
| 6912 | 0.25 | 1250 |
| 13824 | 0.50 | 2500 |
| 20736 | 0.75 | 3750 |
| 27648 | 1 | 5000 |
These five points check both endpoints and intermediate values. A formula that passes only one point may still have a wrong offset or span. Preserve the complete table in the learning project.

Convert milliamps separately when current is the input
If the supplied value is current in milliamps rather than raw counts, use current endpoints in the formula. For the fictional 4–20 mA to 0–5000 mm relationship, subtract four and divide by sixteen before multiplying by five thousand.
At 4 mA the fraction is zero. At 8 mA it is one quarter. At 12 mA it is one half. At 16 mA it is three quarters, and at 20 mA it is one. The corresponding levels are 0, 1250, 2500, 3750 and 5000 mm.
Do not subtract four from a raw-count value whose configured lower endpoint already represents 4 mA. That would mix units and apply the live-zero offset in the wrong representation. Name the input CurrentMilliamp or RawCount so the formula's inputs are clear.
Also distinguish an engineering range with negative values from an electrically bipolar signal. A configured 4–20 mA signal can represent an engineering interval from minus one hundred to plus one hundred units. Its midpoint of 12 mA then represents zero engineering units; the current itself has not become negative.
For the linear model, the relationship must actually be linear in the quantity being represented. A nonlinear sensor transfer, geometric tank-volume calculation or already compensated value may require a different operation. The endpoint equation is not permission to assume linearity for every measurement.
Validate before returning a usable value
The learning scaler uses the following explicit policy. All configured endpoints must be finite, RawHigh must exceed RawLow and EngineeringHigh must exceed EngineeringLow. This particular model accepts increasing ranges only. Reversed engineering ranges would require a deliberately revised contract.
Check configuration first. Then require a true supplied QualityGood flag. Then require a finite raw value inside the configured nominal raw range, including both endpoints. Only after those checks calculate the engineering value, and verify that the arithmetic result remains finite.
Return CurrentValid true with the calculated value on success. On failure, return CurrentValid false and a reason such as InvalidConfiguration, BadQuality, InvalidRaw or OutsideNominalRange. In the independent model, the current numeric value is absent when invalid; a native implementation may use a placeholder accompanied by a validity flag.
Keep LastGoodValue separately if historical context is useful. Update it only on successful calculations. A retained last good value is not a current valid measurement and should not be displayed as though it were fresh.
The structured-text tutorial demonstrates complete validity assignments and guarded calculations. Avoid a fault flag that is set on failure but never cleared after recovery, or a success flag that stays true after the input becomes invalid.

Replay invalid data and recovery explicitly
Use the main zero-to-27648 raw range and zero-to-5000 mm engineering range. Start with no last good value. The supplied quality flag is part of each row; the example does not infer that flag from a physical wiring test.
| Row | Raw | Quality good | Current result | Last good mm |
|---|---|---|---|---|
| 1 | 0 | Yes | Valid, 0 mm | 0 |
| 2 | 13824 | Yes | Valid, 2500 mm | 2500 |
| 3 | 0 | No | Invalid: bad quality | 2500 |
| 4 | 32767 | Yes | Invalid: outside nominal range | 2500 |
| 5 | 27648 | Yes | Valid, 5000 mm | 5000 |
| 6 | -1 | Yes | Invalid: outside nominal range | 5000 |
| 7 | 6912 | Yes | Valid, 1250 mm | 1250 |
Row one is a valid zero reading. Row three has the same numeric raw value but invalid supplied quality, so the result is different. Row four rejects an out-of-range number rather than extrapolating it into a plausible-looking level.
The nominal-range policy is deliberately strict for this exercise. A real system may have documented under-range and over-range measurements that remain meaningful, with a separate quality classification. Implement that policy explicitly if required; do not silently expand the exercise's acceptance range.
A low value is not, by itself, proof of a broken wire. A diagnostic investigation needs the configured module behaviour and other available evidence. This lesson's OutsideNominalRange reason describes a failed acceptance check, not a unique physical cause.
Prevent integer division from destroying the fraction
Suppose division is performed using integer arithmetic that truncates toward zero. With raw value 13824 and span 27648, the integer quotient is zero. Multiplying that zero by 5000 cannot recover the half-scale fraction that was discarded.
For non-negative integer raw values below 27648, the quotient of Raw divided by 27648 is zero under that arithmetic rule. The problem is not limited to values below half scale. At the upper endpoint the quotient becomes one, producing an abrupt jump if the calculation is written that way.
Convert operands to an appropriate real or wider numeric type before the operation that would lose information. Also consider subtraction and multiplication, not only division. Converting the result of an already overflowing integer subtraction does not undo the overflow.
For example, the mathematical difference between 30000 and minus 30000 is 60000. That difference exceeds the positive range of a signed sixteen-bit integer. Convert or widen the operands before subtracting when their original type cannot represent the intermediate result.
There is no universal arithmetic ordering that solves every range and precision problem. Fixed-point arithmetic can be useful when its scale, intermediate range and rounding rule are designed deliberately. Floating-point arithmetic also needs finite-value checks and appropriate tolerance in verification.

Keep rounding and unit conversion in the right place
Preserve suitable calculation precision internally, then format the display for its purpose. Showing more decimal places does not create new measurement information, but rounding too early can change later calculations or comparisons.
As a simple unit check, the difference between 3.421875 bar and 3.42 bar is 0.001875 bar. Since one bar is one hundred kilopascals, that difference is 0.1875 kPa. It is not eighteen kilopascals. Write the conversion factor into the calculation to make such errors visible.
For the fictional level range, decide separately whether the HMI shows whole millimetres, one decimal place or another presentation. Record the underlying value as well as the displayed value when testing a threshold near a formatting boundary.
A display can show 2500 mm while an internal value is slightly above or below 2500. If an alarm comparison uses the internal value, its result need not match a reader's interpretation of the rounded text. The display and alarm policy should make that relationship understandable.
The alarm-priority and detection lesson explores threshold and hysteresis behaviour. A scaling change should trigger review of downstream thresholds expressed in the affected engineering units.
Distinguish raw count spacing from instrument resolution
For the assumed linear map, one raw-count increment corresponds mathematically to 5000 divided by 27648, approximately 0.180845 mm. This is the engineering spacing associated with adjacent integer representations under the stated map.
It is not proof that the complete measuring system resolves every change of that size. The module's conversion characteristics, signal behaviour, noise and configuration matter. Nor does a nominal endpoint of 27648 identify an ADC bit depth by itself.
The JCGM vocabulary entry for resolution concerns a detectable change in indication and notes influences such as noise. Its measurement-accuracy entry addresses agreement with the quantity being measured. Those are different concepts from merely printing additional digits.
In an ideal numerical quantisation exercise, rounding a continuous raw value to the nearest integer introduces at most half a count of rounding difference. Under this map that is approximately 0.090422 mm. That limited arithmetic bound excludes sensor error, noise, drift, calibration uncertainty and all other contributions.
Label the calculation as a quantisation example. It should not be presented as the accuracy specification of a transmitter, PLC input module or completed installation.

Check the inverse map and its rounding error
The inverse relationship converts an engineering target into a raw value for the same assumed linear mapping. Subtract EngineeringLow, divide by the engineering span, multiply by the raw span and add RawLow.
For a target of 3000 mm, the fraction is 0.6. Multiplying by 27648 gives a continuous raw value of 16588.8. If the learning model requires an integer and rounds to the nearest count, it selects 16589.
Scaling 16589 back to engineering units gives approximately 3000.036169 mm. The difference from the requested 3000 mm is approximately 0.036169 mm, which lies inside the ideal half-count bound described above.
This inverse check is useful for exposing inconsistent endpoints or a rounding rule applied at the wrong stage. It does not establish that a physical analogue output produces the requested current or that an actuator reaches the corresponding position.
Test both inverse endpoints and an interior target. If the engineering span is zero, the inverse is undefined. If a target lies outside the accepted range, report the policy decision rather than silently treating extrapolation as a validated command.
Use a second range to expose hidden offset assumptions
A formula that works for zero-based ranges can still fail when a lower endpoint is non-zero. Use a separate fictional mapping from raw zero through 10000 to engineering 100 through 600 units.
Raw zero must produce 100. Raw 2500 must produce 225. Raw 5000 must produce 350, and raw 10000 must produce 600. Omitting EngineeringLow would make all four results too small by one hundred units.
Now use a raw interval from 2000 through 10000 with the same engineering interval. Raw 2000 produces 100 and raw 6000 produces 350. Omitting RawLow from the numerator produces a different error that a zero-based test would not reveal.
Keep these small variations in a regression record. They test the general formula rather than only one convenient set of endpoints. The expected values and the main nominal range were independently checked in software; native code still needs its own type and runtime verification.
The instrument-calibration training guide provides the next distinction: verifying an arithmetic transformation and evaluating a measuring instrument are related but separate activities.
Build a scaling investigation from evidence
When a displayed value looks wrong, collect the raw value, quality information, configured channel range, transmitter range, scaling parameters and displayed units. Record when the observation was made and whether the value was current or retained.
Check the mapping at its lower endpoint, upper endpoint and at least one interior point. Then inspect arithmetic types and where rounding occurs. Investigate configuration and data quality before changing constants simply to make one observed number look plausible.
If several consumers use the result, identify them before revising the mapping. Trends, alarms, reports and downstream calculations may depend on its units and range. A local display correction does not automatically update those other interpretations.
The PLC troubleshooting guide helps organise those observations. Preserve the original parameters and evidence so the reason for a change remains reviewable.

Practise scaling in a South African training programme
When comparing instrumentation and PLC courses in Johannesburg, Pretoria, Durban, Cape Town or another South African location, ask whether learners identify the configured signal representation before writing the formula. Request an assessment containing a valid zero, bad quality, an invalid span and a non-zero endpoint.
Confirm the actual venue, equipment, software access and individual feedback included in the quotation. For online delivery, ask how observations are retained and how an instructor reviews an incorrect result. The instrumentation courses guide can help structure that comparison.
For related software practice, explore the instrumentation simulator learning page. Check the supported exercise and representation rather than assuming a particular native module, diagnostic register or floating-point inspector is available.
The structured-text learning material is a relevant companion for implementing guarded calculations. The formulas here are not a promise that every native controller declaration runs unchanged in a browser environment.
Does raw zero mean a broken 4–20 mA loop?
Not universally. In the documented mapping used for this example, raw zero corresponds to 4 mA. Interpret the number using the configured range and diagnostic context. A valid zero engineering reading and invalid data must remain distinguishable.
Why does my scaled value remain zero until full scale?
Check whether integer division discarded the fractional ratio before multiplication. Under truncating non-negative integer division, every numerator smaller than the denominator produces zero. Verify the operand types before changing the scale constants.
Does adding decimal places improve resolution?
It changes the display, not the information acquired by the measuring system. Preserve suitable internal precision, but distinguish numerical formatting, raw representation spacing and actual measurement capability.
Can I clamp every invalid value to the nearest endpoint?
That can hide diagnostic or quality information. Decide the acceptance and display policy explicitly, and retain an invalid-state indication when the value is not usable. The learning model rejects values outside its nominal range.
What should I keep in a scaling portfolio?
Keep the range definitions, five-point table, invalid-data recovery trace, inverse calculation and non-zero-offset tests. Label supplied values as simulated and record the native documentation used. Explain what the results prove about the arithmetic and what remains untested about the measurement system.