Sign in to follow this  
Followers 0
BenJones

Multiplying large numbers

6 posts in this topic

Hi all, I'm new to PLC programming and I'm having a few issues when multiplying large numbers. When multiplying two numbers using the MUL function, the number bottoms out at 32768 and then changes sign (16 bit signed number). I thiink I need to use a floating point number with two 32 bit inputs creating a 64 bit output number which will be sufficient. This should allow an output of up to 2,147,483,646. I've read the programming manual and believe I need to use the DMUL function which save the multiplication result in two consecutive registers but I'm struggling to get the correct output result. This is what I have done (attachment) : It obviously doenst like me putting inputs or outputs as Data registers but I do not understand why as this is what it states in the programming manual. There is also talk of turning on Memory register (either M8023 or M0283) which one is it as it quotes both in the programming manual (must be a typo). And how do you turn this on ? Is itas simple as doing a line from the left (in ladder) to an output relay, naming this as M8023 and double clicking it and saying SET / RESET ? Many thanks for any help in advance. Thanks, Ben

Share this post


Link to post
Share on other sites
You don't have to go to float unless you have fractions. You're problem however is not getting the wrong result. It is your monitoring when a result of a multuplication is 32 bit. For instance MUL D0 D1 D10 The result is not just D10 but also D11. Because you have not used defined global variables but used direct adressing the result you are monitoring is only the bottom part which will the be incorrect. Edited by Gambit

Share this post


Link to post
Share on other sites
When working with "Double's", the compiler in GX IEC will only accept defined variables (you have to define the variable with a name and the correct type), and not HW addresses. The programming manual usually use GX Developer (which allows for HW addresses directly). As long as you only want to add up some numbers I wouldn'y bother thinking about the special registers (M80**). The output is by the way NOT a 64bit number, but a 32bit number (but you are correct regarding the output value). DINT is not floating point (it's simply double integer). If you want to use floating point (REAL), then you'll have to use the instruction "DEMUL_M". See both examples:

Share this post


Link to post
Share on other sites
Ahha ! I see, got it thanks. (I have used Type DINT for Data32Bits). And obviously I need to make sure that I don't overwrite the next memory location as this is keeping the value of the upper part of the calculation. That is clear, thanks. And now if I want to divide this number (which would in some cases mean I get a fraction shall I use DDIV or DIV ? And what type would I specify the output ? Would it be either FLOAT or BOOL) ? Thanks, Ben

Share this post


Link to post
Share on other sites
Use DDIV for DINT numbers. The result will be an array of DINT with two elements, where the first element is the value and the second element is the remainder (if any)

Share this post


Link to post
Share on other sites
Great, I've done it. Works perfectly so thanks for your help ! I think what was confusing me the most was that I didn't realise that I needed to input varible names and define them in the global list. Heres what I did : Much thanks, Ben

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