Jump to content

Recommended Posts

Posted (edited)

I'm building a function block to sum flow and production hous and calculate average flow based on a REAL input.

For avering I use /L function.
The Result R is a LWORD

To get a more acurate result I want to convert the result to a REAL.

The first two words of the LWORD is the Quatient in DINT
The last two words of the LWORD is the Remainder in DINT

How do I read out the remainder in a function block.

A bit shift is nog working (NASR/NSRL) is only availabe to 32 bits,'.

When not in a function block and using de D channel you simply pick the 3rd channel

LWORD = D100

D100 = DINT for QuatientA
D102 = DINT for remainder.

m3_test.opt

m3_test.bak

m3_test.cxp

 

Edited by paulusB
attached function block

Posted

Why do math on integers and then convert to real?  That's not accurate.  Convert the numbers to real before doing to math so decimals are not rounded off.

Posted (edited)

Thanks for the replies. I thought 64 bit real math wasn't available in CX-programmer. But it is.

2020-05-06_21-26-15.png

Edited by paulusB
but help says only 32 bits...?
Posted

I see you are using a CJ2M PLC.  I have shown below how to use double real numbers in CXP with a CJ2M PLC.

Symbol creation:

Lrealsymbol.jpg.ddec4ccd4b34afb7dcd15133

Choose LREAL as the data type.  Be aware that this data type uses 4 consecutive 16 bit addresses.  So in this example, the variable would use D0, D1, D2 and D3.

Here are some of the double floating point instructions:

lrealmath.jpg.1967852c63d10f30f11eefdcb8

  • Like 2
Posted

CJ2 has long real so does the CP1L.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...