Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

REAL_TO_DWORD FPU overflow

c77asper
2021-01-28
2021-02-01
  • c77asper - 2021-01-28

    Hi all,
    I am trying to use REAL_TO_DWORD in a codesys project, but when the data from the modbus slave is setup wrong (byte order), the PLC is stopping and say: FPU overflow.
    How to handle this?

     
  • dFx

    dFx - 2021-02-01

    Real to dword tries to PUT the real value inside a dword value, meaning it is trying to get the same values on your two variables.
    So, if the real value is outside the dword value range, this will produce an error.

    Online help states :

    If the operand value for a type conversion operator is outside of the value range of the target data type, then the result output depends on the processor type and is therefore undefined. This is the case, for example, when a negative operand value is converted from LREAL to the target data type UINT.
    Information can be lost when converting from larger data types to smaller data types.

    Back to your issue, as your cpu stop may not be configurable easily, I would try using a union datatype instead. Union will use the bits to read the value AS a dword or AS a real. This will prevent your cpu stopping, but you will need to change how you send your value with the master.

    bit sequence : 00000001 00000000 11111111 11011001
    REAL value   : 1,700378E-40
    DWORD value  : 121343
    

    You may prefer just checking the real value before converting it.

    DWORD 0 4294967295

    So you would check if your real is in between these two constants, and then convert it if true.

    Edit: Added some better formating

     

    Last edit: dFx 2021-02-01

Log in to post a comment.