Floating-Point Math on a Micro PLC: PID, Analog Scaling and When You Actually Need It

Let me start with a number: 214-219. That is the page range in the V6.2.2 manual where the floating-point blocks live. You would think the vendor buried them there becuase nobody uses them. Wrong. They buried them there because integer math is fine for ninety percent of jobs — and the last ten percent is where the real machines live.

A Micro-PLC doing SIN, COS, TAN, LN, EXP, SQRT, real-number compares and real-number moves. Ten years ago that sentence would have been a joke. Today it ships in a 35mm DIN-rail module that costs less than a decent oscilloscope probe.

When Integer Math Lies to You

Here is the trap. Scaling a 0-10V analog input with integer math works — until you divide. 6V into a 0-1000 range: integer division drops the remainder, and suddenly your level reading drifts by a unit every scan. Over a shift, the drift compounds. Over a week, your tank overflows becuase the PLC thought the level was fine.

Floating point fixes that. One scaling block, real numbers end to end, and the rounding noise disappears. That is not a luxury. That is what keeps your pumps dry and your customers calm.

Concrete Case: PID Temperature Control with Real Math

Set up a PID loop on a PR-18: analog input reads a PT100 through a 0-10V transmitter, the PID block computes with real-number gains, the output drives a PWM channel for the heater. The floating-point engine keeps the integral term stable. On integer-only hardware, that same loop needs manual gain scheduling and still oscillates at low error.

I watched a commissioning engineer chase a 0.4-degree oscillation for two days on an integer PID. Swapped the CPU for the floating-point model, tuned it in an hour. The hardware cost difference was laughable. The engineering time difference was not.

The Blocks You Will Actually Use

Be honest: you will use ADD-R, SUB-R, MUL-R, DIV-R, and SQRT. Maybe ROUND and TRUNC when handing values to the HMI. The trig functions are there for the genuinely weird projects — flow calculations, tank volume from level, conveyor angle compensation. When that oddball request lands, you do not want to explain that your PLC cannot do cosine.

And the string conversions matter more than they sound. Real-to-string, integer-to-ASCII — that is how you build readable alarm messages and data logs without a HMI scripting language.

What It Costs

Nothing extra, once you pick the right CPU. The floating-point blocks are part of the standard library in the current manual revision, and the software is free. The only real cost is the habit change: stop thinking in integers, start thinking in engineering units.

Scaling Done Right

Scaling is where floating point earns its keep, and it is also where most scaling bugs live. The classic error: scaling the raw value with integer math and losing the remainder at every division. The classic fix: do the math in real numbers and convert once, at the boundary, where the HMI or SCADA expects an integer. One scaling block, real numbers end to end, and the rounding noise disappears.

Write the scaling constants down where the next engineer can find them. A 4-20mA transmitter reading 0-10 bar: the formula, the raw range, the engineering range — all of it belongs in a comment on the scaling block. The value "looks right" for months until it does not, and the person debugging it will need the constants, not the memory of the person who chose them.

Test the boundaries at commissioning: minimum, maximum, and the middle point. A scaling block that is correct at 50% but wrong at 0% will pass a casual glance and fail a real process. Three test points, five minutes, and the scaling is done.

The Integer-Only Fallacy

There is a school of thought that says a Micro PLC should stay integer-only because that is what small controllers do. It is a defensible position from a cost standpoint and an indefensible one from an engineering standpoint the moment your process involves division, ratios, or anything resembling real units. The floating-point hardware costs nothing extra on this platform; the capability is in the block library, not a premium tier.

The real cost of integer-only thinking shows up in maintenance: the workarounds — scaled integers, shifted decimals, hand-rolled fixed-point math — are exactly the code that nobody understands six months later. Floating point reads like the process: temperature in degrees, level in meters, flow in liters per minute. Readable code is maintainable code, and maintainable code is what keeps a service contract profitable.

Use integers where they are the right tool — counters, flags, index values. Use floats where the process lives. The platform gives you both; the discipline is choosing per signal, not per religion.

Real Numbers in the HMI

The HMI and SCADA screens should show engineering units, not raw integers — and the scaling lives on the PLC side. Do the conversion once, in one scaling block, and the displays read degrees, bars, and liters per minute everywhere. The alternative — scaling in every screen, every tag, every report — is a formula-typo waiting to happen. One conversion point per signal, documented in the block comment, and the whole system speaks the operator's language.

That is the shift. The hardware already made it. Your programming style is the last piece of the upgrade.