dunc

can someone explain this maths code to me please?

9 posts in this topic

please see attached screenshot of code.

can someone please explain it to me? my maths isn't the greatest anyway, i just cant get my head round what it is trying to achieve?

i can see that the calculations are being done, then the remainder overflows to the next register, the calculation is being done again and the result is compared against 50 which can increment the initial value.

 

there was some scale limits and other bits i have removed, it was just this section i didnt understand. please help!

Untitled.png

Edited by dunc

Share this post


Link to post
Share on other sites

Take D534 and multiply by 100, putting result in D90.

Take D90, divide by 160, putting result in D90 and remainder in D91.

Multiply the remainder from the divide (D91) by 100, putting in D92.

Take D92, divide by 160, putting result in D92 and remainder in D93.

If the final remainder is less than 50, increment D534.

Put end result in W534.

 

Sounds like you already understood it.  No idea based on this why they are doing that code...

Share this post


Link to post
Share on other sites

i can explain what it is used for, but i still cant get my head round it:


the value D534 is a setting value on our SCADA system for our malt kiln bed height shrinkage. this is a manually inputted value for how far the bed shrinks after the kiln cycle so the stripping arm knows how far to move down and begin stripping the grain from the kiln.

the k160 value is the ratio we use to do all our calculations as the kiln is very old so everything is based on time with an upper and lower datum point only. this time is then converted to a mm measurement.
the stripping of the kilns is done in layers, 12 in total i think.

in this bit of code; when you input a number in the SCADA, depending on whether the remainder calculation result is <50 or not, the value will either go in and stay, or be incremented by one?

i assumed i was just being stupid and it was a standard bit of a code for working out fractions of numbers and rounding up or down without converting the number to a float or something similar? i just cant see how it would achieve anything worthwhile?

 

 

thanks

Share this post


Link to post
Share on other sites

Wild guess that they are using the code to make sure that the setpoint entered is formatted correctly? As in, must be in increments of a certain depth.

Share this post


Link to post
Share on other sites

perhaps, but i cant see how a single increment would help?

im tempted to remove the calc to see what effect it has on the process.

 

it may just be one of those mysteries that will never be solved....

Share this post


Link to post
Share on other sites

It's D534 changed by the process, or just by the user? If it's the user, then create a spreadsheet that does the same math and put in a whole bunch of typical numbers to see what happens. The MOD function in Excel will give you the remainder from a division.

If it's changed by the process, then this is harder unless you know what usually is in the register.

I would disable rather than delete until you know what will happen.

Share this post


Link to post
Share on other sites

D534 is a user setting in the engineering parameters. once set, in theory, it never changes.

if i was to delete it, if no one ever needs to change the value, there would never be an issue. but i get your point, i dont nromally delete code, unless its been tested as not needed, or i know what its doing.

i will have another look when i next get a chance. thanks

Share this post


Link to post
Share on other sites

Anyone care to please explain D/ instruction for A-series CPU (see attached manual instruction below).

Instruction example: D/   D52   K1000   D76

According to the manual this math is:  D53, D52 divided by (/) 1000 = quotient in D77,D76 and remainder in D79,D78. OR apparently it just stores the quotient in D77,D76 ???

I really need the following explained:  part (2) where it says: "In regards to the operation result....64 bits in the case of word device, .....32 bits in the case of bit device". What does this mean and when does it use a 32 bit destination (for quotient only) as opposed to 64 bit destination (for quotient and remainder)? 

 589b8a57e6b50_DoubleDivide.jpg.2f2240cec

Edited by Paolo_911

Share this post


Link to post
Share on other sites

Interesting. My only thought is that there is a system bit you can turn on to drop the remainder instead of storing it, but I've never used that feature or noticed the information in the manual. I always just account for the remainder when laying out memory.

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