paulusB

Split long word for average function in function block

11 posts in this topic

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

Share this post


Link to post
Share on other sites

Figured it out. You have to work with arrays and move them (as discribed in the help :-( )

2020-05-04_13-56-36.png

1 person likes this

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Because the total amounts can become big and real then les accurate

Share this post


Link to post
Share on other sites

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...?

Share this post


Link to post
Share on other sites

Those are 32-bit real number commands.  I think only NJ/NX have 64-bit floating point.

Share this post


Link to post
Share on other sites

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

2 people like this

Share this post


Link to post
Share on other sites

CJ2 has long real so does the CP1L.

Share this post


Link to post
Share on other sites

I totally missed the "D" instructions. Thanks

Share this post


Link to post
Share on other sites

My bad... I am way behind on my knowledge of the legacy platforms, pretty much a Sysmac guy now...

Share this post


Link to post
Share on other sites

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