Sign in to follow this  
Followers 0
Guest Tony

No 32-Bit Multiplication or Division

4 posts in this topic

I am attempting to write a program which requires that I do some decimal math that would use numbers higher than 65536. I would have to manuipulate these numbers in order to find percentages as well. However, I do not have 32 bit Multiplication and only a 32-bit to 16 bit division with no carry function. Anyone got any ideas how I can achieve this? I do have 32 bit addition, moves, compares etc.

Share this post


Link to post
Share on other sites
What PLC?

Share this post


Link to post
Share on other sites
I'd suggest using a different plc. However, if you have a good reason for sticking with this model (whatever it is), I can offer a little help (perhaps too little). To do decimals without floating point, you simply need to multiply all of your numbers by 10 or 100 or 1000 or whatever you wish in order to achieve the number of decimal places needed. You just pretend the decimal is there. For instance 11 divided by 4 using integers gives an answer of 2. But if I turn the 11 into 1100 and then divide by 4, I get an answer of 275. I know I multiplied that 11 by 100 so I have to consider the answer as having 2 decimal places. That means I should pretend the answer is 2.75 rather than 275. Guess what? 11 divided by 4 = 2.75. Its easy to add or subtract numbers of any size without floating point even without a carry flag. Let me know if you want an explanation of how to do this. Multiplication and division is a little bit more work. I've never had to do it on a plc. I've worked on microproccesors that didn't have mulitiply or divide so you had to write your own routines for doing this. Such routines are not too long and they can easily be expanded to accomodate any length of numbers. The trouble is that on a plc, these routines would be kind of slow since you don't have access to the fast underlying processes. I suppose it might be best to stay away from that and just mimic the way you would do it yourself on paper. This way you could stay within the multiplying abilities of the plc you are using. Think about how you would do it with a pencil. You multiply the 2 least significant digits ("words" in your plc) and copy the answer down. Then you do the next 2 and so on. When you are done, you add up the vertical columns, etc. You can do the same in a routine in the plc. You need to add 1 to an addition if you had a carry in the previous operation just like on paper. I can tell you how to create a carry flag for addition/subtraction but I'm not sure how to prove a carry after mulitiplication. I'd double check your manual before being too sure that there is no carry available. I really find that hard to believe. Every processor has a carry flag and it's a trivial thing for them to give you that info in the plc's math routines. As for dividing.... you're a gluttin for punishment aren't you? You sure you don't want to find a nice plc with floating point?

Share this post


Link to post
Share on other sites
Thank you for your replies. As for what type of PLC I am using, it is a Toshiba T1-16S. As for using a different PLC, I am a Toshiba rep and this program is for an OEM. Toshiba does have PLCs that do the floating point, etc. However, if you have ever worked with an OEM you know that price is everything. I originally wrote the program for an Aromat FP0 (with another company), which had the floating point and all of these nice diagnostic functions were a piece of cake. But since I'm faced with using the least least expensive unit I have, I have to make do with what I got. Thank you Jim for the advice. By the way, this is how the Toshiba Instruction Set Manual explains the 32-bit to 16-bit division (now that you mention the carry, I will definitly moniter the C+1 register to see if there is anything in there): input executing output ———[ A+1·A DIV B -> C ]———————————————— Functions *Divides operand A+1·A by operand B. The quotient is stored in C and the remainder is stored in C+1. * The data range of operand A+1·A is from 0 to 4294967295. * The data range of operand B is from 0 to 65535. * When operand B is 0, division error is generated. (output OFF) * The data range of the results of the calculation (operand C) is from 0 to 65535. When the results of the calculation exceed 65535, the quotient is stored as 65535 and the remainder as 0. However, output is ON.

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