Jump to content

Uint32 convert to real


Recommended Posts

Trying to convert the HSC counter from a Uint32 to a real number so I can do math on the counter valve. 

Tried to use Int to real no good, tried to multiply be 1 no good, tried Formula no good, tried all math no good.

Please let me know how to convert a Uint32 to real number.

 

- Andrew

Link to comment
Share on other sites

  • MVP 2021

I did a little experimenting and learned the INT to Real block is looking for a INT16 data types as inputs.  Unfortunately this is not documented in the Help.

If you really want to do your math in REAL land you'll need to convert your UINT32 into two INT16s by dividing it by 10,000 and effectively creating a high word and a low word.  You can convert these to REALs and then combine them back together.

I realize this is a hack, but sometimes you have to work within the constraints of the product's functions.

You could also do your math directly on the UNIT32 using implied decimals.  What is the formula you're trying to implement?

Joe T.

Link to comment
Share on other sites

Thanks for your help.  A lot is not in the help. I'm using an encoder to calculate distance. This is not a fast moving.  1 P = .00124 inches. 

I'm not sure I understand dividing by 10,000 . 4,294,967,295/10,000

Daniel just answer me. He said use  Store Unsigned to signed this will work for what I'm doing.

 

Thanks for your help...

 

 

Thanks

- Andrew

Link to comment
Share on other sites

  • MVP 2021

I didn't realize an INT32 would work as the input to the INT to REAL block.  When you click on the little pencil to create a tag it defaults to an INT16, which is one way UniLogic is telling you what data types the block will accept.

Hope that works for you.  A limitation of the REAL data type is it can only handle 7 digits of precision, so as long as your counts don't go over 9,999,999 you'll be OK.

 

Joe T.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...