What is the PLC taking the opposite value command? -Solutions - Huaqiang Electronic Network

1206 red anti-stick

What is the opposite value command for PLC? For example, after a real number operation, I want to get the negative value (like 2.0e+01 becomes -2.0e+01). Is there a direct command for this? Well, of course, you can just multiply by -1, but I'm curious if there's a specific instruction designed for this purpose.

The real number in PLCs is typically represented as a 32-bit IEEE floating-point value. The sign of the number is stored in the sign bit of the mantissa. To invert the sign, you don't need to do any complex math—just flip that sign bit. This is exactly what the NEGR instruction does.

The NEGR (Negate Real) instruction is used to invert the sign of a 32-bit IEEE floating-point number stored in Accumulator 1. It directly manipulates the sign bit of the number, which effectively changes its sign without altering the magnitude. This makes it a very efficient and straightforward way to negate a real number in PLC programming.

Here’s an example of how to use the NEGR instruction:

  • LID8 – Loads a real number into Accumulator 1 (for instance, ID8 = 1.5E+02).
  • NEGR – Inverts the sign of the floating-point number in Accumulator 1 (result becomes -1.5E+02).
  • TMD10 – Transfers the result from Accumulator 1 to the double word MD10 (so MD10 now holds -1.5E+02).

This approach is both clean and efficient, especially when working with real numbers in PLC applications. It avoids unnecessary calculations and ensures that the sign is flipped directly at the bit level, making it ideal for control systems where precision and speed are important.

PCB Assembly

Prototype Pcb Fabrication,Custom Printed Circuit Board,Multilayer PCB board,flexible pcb prototype

Dongguan Jinglin Communication Technology Co., Ltd. , https://www.jlpcba.com