Jump to content

Uint32 convert to real


AndrewTRSI

Recommended Posts

  • MVP 2023

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.

  • Like 1
  • Thanks 1
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 2023

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.

 

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

I would like to say thanks also for your conversion tip.

I'm trying the DIV and MOD math blocks to create the HIGH WORD and the LOW WORD, both commands accept the UINT32 variable divided by 10000.

Then I'm using an OR block to add logically both INT16 registers into an INT32  register, in other words, the high and low word are INT16 and the final result after the OR operation is the

DOUBLE WORD (INT32) register that is suitable for the INT TO REAL command.

I compiled and rebuilt all without errors according to UNILOGIC.  It should work well based on your advice.

Very kind regards,

Marco👌

image.thumb.png.723c2d82797229f80d97a5fa48cda89f.png

 

 

 

 

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