Sign in to follow this  
Followers 0
Kristian

CPM2A - Problem with BCD math calculations

15 posts in this topic

Hi I am a beginner to Omron PLCs. My application is a cable cutting machine and I am using a CPM2A. I get feedback of the length of wire needed from the HMI and post it into address 35.00 (working byte) I then need to multiply the value inputted by 10000 and then divide it by the roller circumference (also multiplied by 10000) to get the actual number of revolutions needed until I switch off the feed motor. Now when I tried to use BCD multiply the answer is always wrong. All addresses are set as HR00, HR02, HR04, etc. except the Length needed inputted through the HMI. the answers for the first multiplication as shown in the picture are as follows 1 x 100 = 100 2 x 100 = 296 3 x 100 = 402 4 x 100 = 598 5 x 100 = 800 etc. PLEASE HELP! Kris

Share this post


Link to post
Share on other sites
Can you post your current CPM2A program? Also, 35.00 would be a bit address. What HMI are you using?

Share this post


Link to post
Share on other sites
I am not using 35.00, but IR035. My HMI is an NT2S-SF122B-EV2 CCM.cxp

Share this post


Link to post
Share on other sites
Have not looked at your plc program yet, but have a question. What is the data format setting for IR035 in your NT2S program? What software are you using to program the NT2S? Now, I have looked at your plc code. BCD values need to be set using the # "data type" The & "data type" is decimal (not the same thing). Also, a MOV instruction will move 4 digits. If you look at the raw value in IR035, that value is #2710. For the size numbers you are working with, you will need to use the MULL(56) Double BCD Multiply. This instruction will require two consecutive words for the top and middle node and four consecutive words for the bottom node. There is still the question of the data being sent to the plc from the NT2S. Hope this will help.

Share this post


Link to post
Share on other sites
Thanks. The program I am using is NT2S_2.00A. I set the value as type integer, does it have to be set to BCD?

Share this post


Link to post
Share on other sites
In the first 2 lines you move decimal (&) numbers but they should be BCD (#) to work with MUL and DIV. Try writing them as MOVL #10000 and MOV #3142 Watch the size of the result of the MULL though because depending on LengthNeeded you could end up going into too many words and miss the vital data when dividing to find NOREVSNEEDED.

Share this post


Link to post
Share on other sites
Do I really need to use MULL? Because my multiplication answer will never exceed 8 digits. I don't think that CPM2A has MOVL function

Share this post


Link to post
Share on other sites
You will need to use MULL if you need to multiply by a value greater than 9999. The result size really has very little to do with which instruction is used. The size of the multiplicand and multiplier determine which instruction is required. Yes, if using BCD math instructions, the data type in the NT2S must be BCD. Note also, this same information will apply to the division instruction in your program. Hope this will help. You are correct, CPM2A does not support MOVL. However, you can use two MOV instructions, one to move data to HR4, a second MOV to put data into HR5. Do you have the W353 manual? This covers programming for the CPM2.

Share this post


Link to post
Share on other sites
Here is a link to the manual: Omron W353 Manual at Mr.PLC.com Let us know if you have any more questions.

Share this post


Link to post
Share on other sites
Hello Kristian, Your problem stems from the lengths of the words that you are using. Single BCD instructions can only handle values between 0 - 9999 (0 - 270F HEX). Your MOV instructions contain Decimal (not BCD values), but whatever you do, the MUL instruction cannot handle values greater than 9999, so you will need to re-think the way that you approach this. Blast - GT, just too fast for me! Edited by anonymous

Share this post


Link to post
Share on other sites
Both of you are fast enough for me. I still have problems. The value I input from the HMI MUST BE DECIMAL. Now from 1 to 9 the multiplication works fine, but when the user inputs from 10 on, the multiplicand becomes 16 (10 in hexadecimal). I need to work in decimal values, otherwise my machine won't work. Also worth mentioning that when I tried to mov #3E8 (1000 in hex) into the multiplier, the BCD multiply instruction did not work. What should I do now? Thanks

Share this post


Link to post
Share on other sites
If I recall... you can set the data type in the NT2S to be BCD can;t you ? That way what you enter will represent what you want... also for 1000 simply put #1000

Share this post


Link to post
Share on other sites
Sleepy is correct. (see image below) Also, be sure to monitor in HEX. Monitoring in Decimal will only confuse you as this is only a representation of the actual value. On another note... you should really be using NTXS instead of NT2S software. This has nothing to do with your current problem but you may have noticed that NT2S software is unstable.

Share this post


Link to post
Share on other sites
As you have found out, a BCD math instruction will only work with a BCD number. You can NOT have "alpha" characters in the values. As Sleepy has noted about to multiply by 1000 just enter #1000. You do not need to convert decimal values to hex. Also, as IO_Rack has noted, the NT2S can work in BCD values. Just modify the NT2S program to use BCD and I am sure this will work for your application. If you really think you need to use decimal, try using the Binary math instructions. This should work also, just a bit more difficult to read the values in the plc program. The hmi would be able to display these values with out a problem. Your choice. Not sure what plc systems you are use to using, but numbering systems seem to be one of the most confusing issues. The Omron processor deals with numbers in hex (or bcd for some instructions). Decimal representation is only there to make it "easier" for us to view values. I learned a long time ago to just use a decimal to hex and hex to decimal coverters and it has saved a lot of grief. Hope this helps. Let us know if you have any other questions.

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