Sign in to follow this  
Followers 0
VAU_RMA

Convert WORD to DWORD

5 posts in this topic

Hi. I want to convert a WORD variable to a DWORD variable. I have tried to use "signed binary multipy" instruction like this: *(420) WORD &1 DWORD This works fine except with the last bit. When the last bit is active, the result (DWORD) activates ALL the bits in the 16 highest bits as well as the highest bit in the 16 lowest bits. WORD: 0111 1111 1111 1111 DWORD: 0000 0000 0000 0000 0111 1111 1111 1111 WORD: 1111 1111 1111 1111 DWORD: 1111 1111 1111 1111 1111 1111 1111 1111 (I want this value to be: 0000 0000 0000 0000 1111 1111 1111 1111) Why do I get this result? Does anyone have any other way of converting a WORD varibale to a DWORD variable? Any move / transfere instructions that may work her?

Share this post


Link to post
Share on other sites
Why are you trying to convert to a DWORD. The easiest way if you insist on going down this path would be to simple MOV the WORD value to a memory location where the next word is always &0000. Ie move to D100 and D101 should always have &0000 in it. (always move &0 into D101 to make sure if you are worried about something else writing of D101) I am perplexed as to what the difficulty is. I think that you might need to do a bit more reading on understanding the basic memory structure of the PLC.

Share this post


Link to post
Share on other sites
I need to do this because this is inside a function block. It is done because I have two words that need to be combined into one DWORD *U WORD1 &1 DWORD1 *U WORD2 &1 DWORD2 NSLL DWORD2 #0010 + DOWRD1 DOWRD2 DWORD3 i.e: WORD1 = 0000 0000 1111 1111 WORD2 = 0101 0101 0101 0101 DWORD3 = 0101 0101 0101 0101 0000 0000 1111 1111 I could have done it as you describe (moving the word to the right position) if I used variables with defined memory area (AT), but that is not desired. I have found the problem though; I used the signed version of the instruction, but should have used the unsigned. Edited by VAU_RMA

Share this post


Link to post
Share on other sites
Try using unsigned multiply instead. *U(422)

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
Sign in to follow this  
Followers 0