Remainder math register does not update when using DIV instruction

DIV (S:13), MOV - 24.06 microseconds
AIC - AEX - ACI - 139.92 microseconds
Repeat Subtract - 24.2 microseconds (1 execution) - 217.8 microseconds (9 executions)

Wow, well I stand corrected. That's very surprising. It looks like a wash on average between the String and Repeat-Subtract method.

I tried the DIV S:13, MOV approach on a SLC 5/04 today, and I never could get a remainder error out of it. I probably plugged 50 different 4-digit integers in without an incorrect 3-digit result.

That being said, I would still sacrifice speed for peace of mind. I would go with the SUB/JUMP routine just because it looks like it would be easier for a maint. man to cipher out at 3am then String instructions. Your average tech is not going to want anything to do with Strings at anytime of the day.
 
If the value is always 4 digits and it is in bcd format why not use a MVM with a FFFh mask to only copy the last 3 digits. If it is a binary value use a TOD first.

I'm not near an AB plc to try this but what do you think?

Jerry
 
If the value is always 4 digits and it is in bcd format why not use a MVM with a FFFh mask to only copy the last 3 digits. If it is a binary value use a TOD first.

I'm not near an AB plc to try this but what do you think?

Jerry

Now I'm wondering why I didn't think of that...

But I think an AND would be better, as it would automatically clear the upper 20 bits....

Sorry - should have shown it as Micrologix code....

2011-12-02_121502.jpg
 
Last edited:
Substituting that for the AND saves about 7 microseconds (35.15 total). The TOD takes 29.31 microseconds. (Publication 1763-RM001B-EN-P - April 2007)
 
Last edited:
This thread reminds me of the 'Learning by Doing' thread or those where one must do indirect addressing on a S7.

I would question the decision to use a ML1100 if it doesn't have a MOD instruction.
You guys have wasted more in time than than the difference between the ML1100 and a controller that has a MOD instruction.

Threads like this should not exist. There be threads about how to solve applications not how to kludge with an inferior tool to do the job.

Daba's method can be optimized and is obvious. First try subtracting by 5000 then by 1000. The number of loops drops to 6 if the dividend is limited to 9999. Better yet try subtracting by 3000 or 4000 first.
 
LOL. Don't hold back, tell us what you REALLY think Peter!

There is no MOD instruction in Logix 500. This is probably because the math registers give you one directly, and I've used them for years to do just what the OP is asking about.

From the instruction Help file, available in the Logix 500 editor, a normal DIV (divide) works like this:

When rung conditions are true, this output instruction divides Source A by Source B and stores the result in the destination and the math register. The value stored in the destination is rounded. The value stored in the math register consists of the unrounded quotient (placed in the most significant word) and the remainder (placed in the least significant word).

Sheesh. RTFM! Emulator aside, this has worked fine in all the uLogix and SLC controllers I've run it. Now, I have to admit that I do agree with Peter that anything other than examining S:13 and S:14 is a kloodge!

Paul T
 
Though note, Paul, the requirement in the 1100 that the destination be S:13 for the Quotient/Remainder to appear in the math Register. Some of the SLC/Micrologix require this and some don't. Gotta be careful.

And I tried to point out that the other methods are probably time wasters.
 
Though note, Paul, the requirement in the 1100 that the destination be S:13 for the Quotient/Remainder to appear in the math Register. Some of the SLC/Micrologix require this and some don't. Gotta be careful.

And I tried to point out that the other methods are probably time wasters.

Thanks! Yeah, there are enough little difference between the various uLogixs and SLCs, it does keep you on your toes.

I have to admit, I enjoy doing math and logic operations in a PLC as much as I like making things move. So, I usually try and find a better way than brute force when thinking about algorithms. Not always... but whenever I can, I will.

Paul T
 
Though note, Paul, the requirement in the 1100 that the destination be S:13 for the Quotient/Remainder to appear in the math Register. Some of the SLC/Micrologix require this and some don't. Gotta be careful.

And I tried to point out that the other methods are probably time wasters.

Not sure I understand what you are saying, Bernie - On some machines the destination of the DIV has to be S:13 like picture Dest_S13 ?

And on others it doesn't have to be ? That doesn't sound clever to me.

Anyway, I tried both in a ML1000 see the pics - and Dest_N7.jpg clearly shows that the remainder goes into S:13.

As a bonus, the one instruction yields both the parameters that the OP may be interested in.

If the ML1100 behaves like the 1000, then may I suggest problem solved, even though it may not be so obvious to Mr. Maint at 3 a.m. a few well-worded rung comments should sort that.

Dest_N7.jpg Dest_S13.jpg
 
Not sure I understand what you are saying, Bernie - On some machines the destination of the DIV has to be S:13 like picture Dest_S13 ?

And on others it doesn't have to be ? That doesn't sound clever to me.

Hey, we haven't accused AB of being clever.

I don't think there would be any problem in leaving S:13 as the destination on all units, unless you are ALSO interested in the rounded quotient.
 
Last edited:
Not sure I understand what you are saying, Bernie - On some machines the destination of the DIV has to be S:13 like picture Dest_S13 ?

And on others it doesn't have to be ? That doesn't sound clever to me.

Anyway, I tried both in a ML1000 see the pics - and Dest_N7.jpg clearly shows that the remainder goes into S:13.

As a bonus, the one instruction yields both the parameters that the OP may be interested in.

If the ML1100 behaves like the 1000, then may I suggest problem solved, even though it may not be so obvious to Mr. Maint at 3 a.m. a few well-worded rung comments should sort that.

That's how I took it. On the higher level uLogix, and all (?) the SLCs, the "destination" register is whatever you want. The actual system math registers S:13 and S:14 are never thought of or examined in most cases. It's only when you get into things like this, or when you have an integer DIV where you're worried about roundoff, that you get into it.

I am kind of surprised too that the uLogix 1100 is "special" but you get used to that, especially with AB. LOL.
 
Paul_T said:
I am kind of surprised too that the uLogix 1100 is "special" but you get used to that, especially with AB. LOL.

I'm surprised you're surprised, lol. In this case, it seems that "special" is the operative word. I'm noticing the same thing in testing with a SLC, ML1000, and then a ML1100. The 1100 is the only one that requires the S:13 destination. Strange.

Wonder which method the OP ended up using?
 
I'm surprised you're surprised, lol. In this case, it seems that "special" is the operative word. I'm noticing the same thing in testing with a SLC, ML1000, and then a ML1100. The 1100 is the only one that requires the S:13 destination. Strange.

Kinda makes it hard for people like me to speak with authority - Have I got to go buy EVERY model of MicroLogix, EVERY Model of SLC, and EVERY model of ControlLogix, and test EVERY program on all platforms.....

I would definitely like to say "now you do this on a Micrologix/SLC machine, except for the 1100 series, because it behaves differently...."

IMHO it sounds like a firmware "bug" that they can't/won't fix. But then they should put the info into the Help files, because that is my first point-of-call when trying to understand something.

Thanks for the info - next time I get my hands on an 1100, it sure is something I'm gonna play with...
 

Similar Topics

Working with a MicroLogix 1400 Ser B. I have a Divide Instuction and need to know if the result is a whole number or has a remainder. Currently...
Replies
6
Views
4,079
Im having a lot of trouble programming a Minutes and Seconds count down timer display in Productivity Software. Is there a math instruction that...
Replies
1
Views
1,968
Hello, I've got a tricky math problem. I have a double integer that I need to divide by 10,000, and separate it into quotient and remainder. I...
Replies
9
Views
7,534
does plc5 have a method for getting the remainder in a division function like in clx? thanks
Replies
15
Views
10,662
Hi, I'm pretty new to PLCs (about 2 weeks experience) and still learning all the commands but I had a problem and after spending a long time...
Replies
4
Views
3,964
Back
Top Bottom