Sign in to follow this  
Followers 0
sbaum

Move Digit into DWORD with Function Block

7 posts in this topic

I am trying to create a Double Word (BCDL if it matters) from individual digits within a Function Block. In normal ladder, I use the MOVD instruction and move the digits into the proper spots with the High and Low Words of the Double Word and all works well. as I am referencing a specific memory area. However I need to do this within a Function Block. I can write the digits to 2 separate Variables, but how do I compile them into 1 DWORD Variable. Ideally the MOVD instruction could write to a double Word... Now I realize I can specify a physical address for the Variables within the Function Block & Create a DWORD Variable pointing to the same addresses, but that is defeating the entire purpose of my Function Block! BTW the PLC is a CP1H Any ideas?

Share this post


Link to post
Share on other sites
Not sure what is the problem specific to the FB usage, but consolidating two INTs into DINT is simple: multiply the MSW by 65536, then add the LSW to the result. Edited by Sergei Troizky

Share this post


Link to post
Share on other sites
You may want to test your method... And I am dealing with a Double Signed BCD But it still won't work in the FB like in normal ladder. I'll use INT for example. Multiplying the MSW by a given value results in a DINT Variable. Take that DINT Variable and add using a Long instruction requires a DINT Variable for the addend. But my LSW is only a INT. The Function Block will not accept that. So that's not a solution.

Share this post


Link to post
Share on other sites
If I understand correctly, the problem is you can not access the upper word within a function block. This is due to having no numbered addresses to write to. In dealing with BCD you'll have to multiply your MSW by 10,000 then add the LSW. Before doing the math you can use MOV to move your WORD to DWORD. This way your math instructions will be happy. If there is another method of accessing the upper word, I am unaware of it.

Share this post


Link to post
Share on other sites
There's the answer I needed. I didn't realize the MOV instruction works with both data types. All the Math instructions don't. Thanks!

Share this post


Link to post
Share on other sites
As an alternate you could: MOV INT1 into the DWORD SHIFT LEFT 16 MOV INT2 into the DWORD

Share this post


Link to post
Share on other sites
Thanks That's the sort of Instruction I was looking for and didn't lay my eyes on. Makes a clean solution.

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