Jump to content

Uint32 convert to real


AndrewTRSI

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

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

Important Information

This site uses cookies. By clicking I accept, you agree to their use.