Math (output instruction)
SQR: Square Root
Writes the square root of A.
Also called: square root, root.
SQR(number, a, real)Arguments
| Name | What it is | Accepts | Default |
|---|---|---|---|
| destination | What the instruction acts on | a register | required |
| a | Source | a number or a tag | 0 |
| real | Floating point | true or false | false |
Arguments are positional and this table is generated from the simulator's own instruction registry, so it always matches what the engine accepts.
What it does
SQR is a maths instruction with one job, and in process control it has one dominant use: flow measured across a differential pressure element. An orifice plate, a venturi or a pitot tube produces a pressure difference proportional to the square of the flow, so the flow is proportional to the square root of what the transmitter sends. A DP flow reading that has not been square rooted is wrong everywhere except at full scale, and wrong in a way that looks like a calibration problem.
Many modern transmitters do the extraction themselves, and doing it twice is its own classic fault. Check the transmitter's configuration before adding this instruction.
It also turns up wherever a distance is wanted from two axes, and anywhere a physical relationship happens to be quadratic.
A negative input has no real square root. This simulator writes 0 rather than faulting.
A rung you can run
Flow from a differential pressure transmitter
XIC(Flow_Enable)SQR(Flow_Root,DP_Raw)
MUL(Flow_Rate,Flow_Root,12)
GEQ(Flow_Rate,500)OTE(Flow_High)Turn on Flow_Enable and set DP_Raw to 2500: the root is 50 and the scaled flow is 600, so the high alarm comes on. Now set DP_Raw to 625, a quarter of the pressure, and the flow reads 300, which is half. That halving is the relationship the square root is there to undo.
Run this rung in the simulatorWhat it is called on other controllers
| Platform | Equivalent |
|---|---|
| Rockwell (Studio 5000) | SQR |
| Siemens (TIA Portal) | SQRT |
| Mitsubishi (GX Works) | A square root instruction, chosen by data type |
| CODESYS and IEC 61131-3 | SQRT |
Common mistakes
- Leaving the instruction in whole number mode. The root of 90 is about 9.49 and truncates to 9, so a scaled flow reading loses everything after the point and reads low. Switch the instruction to floating point, or scale the value up before taking the root.
- Extracting the root twice. If the transmitter is already configured for square root output, doing it again in the PLC gives a reading that is right at zero and at full scale and wrong in between, which is the hardest kind of error to spot on a trend.
Practise it
Interactive exercises that use SQR. Each one checks your ladder against a real scan.
