AndrewTRSI Posted March 12, 2022 Report Posted March 12, 2022 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
MVP 2023 Joe Tauser Posted March 13, 2022 MVP 2023 Report Posted March 13, 2022 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. 1 1
AndrewTRSI Posted March 13, 2022 Author Report Posted March 13, 2022 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/2 Thanks - Andrew
AndrewTRSI Posted March 13, 2022 Author Report Posted March 13, 2022 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
MVP 2023 Joe Tauser Posted March 13, 2022 MVP 2023 Report Posted March 13, 2022 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. 1
MVP 2023 Flex727 Posted March 13, 2022 MVP 2023 Report Posted March 13, 2022 15 hours ago, Joe Tauser said: You could also do your math directly on the UNIT32 using implied decimals. @AndrewTRSI, you're better off following this advice. If you're doing PLC programming, understanding this concept will improve your skills. 2
Marco Mendoza Posted December 2, 2022 Report Posted December 2, 2022 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👌
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now