Remainder math register does not update when using DIV instruction

Besides all math should be floating point! :)

Sure, then we could say with certainty that "the results might be a little bit off" and never be forced to make it exact. And, with my ML1000s and 5/02s it will be so much fun to write my own floating point handler in ladder logic with 1k of user memory.

j/k

Paul
 
Last edited:
I hadn't noticed that the original poster stated he was using a ML1100. I've rarely if ever touched those or SLC502's.
My sincere apologies....
 
bmacattack33 - The 'N' table shows the last things YOU put in it before the end of the scan. The 'S' registers may have been modified by the system before the end of the scan. (i.e. changed between the time of your division and the communication at scan end.) Or possibly a quirk of the emulator.
 
Thanks for the quick replies, i will try some of the suggestions first thing tomorrow morning, and will post my results.

He doesn't need floats, just 32 bit math with 16 bit results. I also recall that there is a system bit that can affect the way overflow bits and remainders are used. I believe the default setting should give the normal result if S:13 is the destination.

This is correct, the number that I start with in an integer with an upper limit of 9999. And the number I am looking for is an integer from 0 to 999.

For those interested, the following is some background info. The system I have setup is an Automatic Train Identification system composed of track-mounted RFID readers and train-mounted RFID tags. The reader receives a message composed of, amongst other things, a four digit run number that includes a prefix digit and a 3-digit run number. The prefix digit changes depending on the time of day the train leaves the terminal ( it can be 0 thru 9). The run number corresponds to a particular route the train is going to take; these run numbers have a range of 100 for the same route ( e.g. trains going to destination 'A' have run numbers x300 thru x399, where x changes and can be 0 thru 9; and trains going to 'B' have run numbers x400 thru x499, etc. The RFID reader sends the 4 digit number and other information to the ML1100 via a RS485 serial line everytime a train approaches the reader.

These run numbers will then close a contact on the ML1100 ( or the expansion output module) and feed into a vital microprocessor so it can setup a particular route over a complex system of switches and tracks in advance of a train approaching.

Ive tried wrapping (OR-ing) the ranges to a particular output but run into a 'nesting limit error' after 5 branches. This isnt good practice in my opinion, and I feel there has to be a better, easier way to do this.
 
Last edited:
bmacattack33 - The 'N' table shows the last things YOU put in it before the end of the scan. The 'S' registers may have been modified by the system before the end of the scan. (i.e. changed between the time of your division and the communication at scan end.) Or possibly a quirk of the emulator.

Thanks, Bernie.
I'm guessing emulator quirk, since that was a test program with nothing but the one math exercise in the logic.

So, @ the OP, assuming that the DIV with S:13 destination works correctly on a real processor, then that is the method I would go with. Although I think I would MOV the result to a storage N register immediately after the DIV for later use in the program:

3-digit Extraction Example rev2.jpg

Good luck with your project, let us know how it turns out for you.

Cheers,
Dustin

🍻
 
jendrus said:
Ive tried wrapping (OR-ing) the ranges to a particular output but run into a 'nesting limit error' after 5 branches. This isnt good practice in my opinion, and I feel there has to be a better, easier way to do this.

I'd have to see the program to understand better what you're trying to do here with the 3-digit code, but as far as the "nesting limit error", that is probably due to "nesting" the branches. You can "extend" existing branches up to something like 60 times, but you are only allowed a few "nested" or "branches within branches".

Nested Vs Extended Branches.jpg

Extended branches, besides not being limited to 5 "OR's", execute faster, because for each "nested" branch, there is an extra BST and BND instruction for the processor to deal with.

Code:
Nested Code:

SOR XIC BST OTE NXB BST OTE NXB BST OTE NXB BST OTE NXB OTE BND BND BND BND EOR
Code:
Extended Code:

SOR XIC BST OTE NXB OTE NXB OTE NXB OTE NXB OTE BND EOR
 
I think if you are going to start using DIVs, DDVs, and the Math Registers, you will have some hefty testing to do to ensure ALL numbers in the range 0-9999 work as intended. Rounding errors and Floating Point precision may get in your way.

Certainly don't want to mis-route a train due to some math error!

Does no-one else think that the solution posted in post #13 is by far the simplest, and cannot go wrong. For the number range 0-9999 the maximum number of jumps would be 9 only - trivial in comparison ...
 
Ok so Ive tried using S:13 as the destination in the DIV instruction and I get a compile error.

I'd have to see the program to understand better what you're trying to do here with the 3-digit code, but as far as the "nesting limit error", that is probably due to "nesting" the branches. You can "extend" existing branches up to something like 60 times, but you are only allowed a few "nested" or "branches within branches".

See attached for what I tried to do until i got a nesting limit error.

program screen shot.jpg
 
Last edited:
Use "Extend branch down" option from the right-click menu - see pic

branch.jpg
 
After going offline, modifying the code with S:13 as the destination of the DIV instruction, and then saving and downloading the project , I got it to work. I guess I had to be offline to make a program change that involves registers.

Now the question is do I want to leave it this way or go with the subtraction or jump routine mentioned earlier?
 
jendrus said:
After going offline, modifying the code with S:13 as the destination of the DIV instruction, and then saving and downloading the project , I got it to work. I guess I had to be offline to make a program change that involves registers.

Yes, with a ML controller, online rung edits unfortunately aren't supported.

Now the question is do I want to leave it this way or go with the subtraction or jump routine mentioned earlier?
All things being considered, I would go with daba's subtract and jump routine.
I think the chances of errors with the S:13 method or with the method in post #9 are VERY small, however the consequences of such an error could potentially be disastrous. With the SUB/JUMP routine that potential error is eliminated.

That's my two cents
 
Patrick,
Your solution is a perfectly valid one, but as far as CPU resources used, it's far inferior to daba's method. And when you're controlling screaming locomotives with a Micrologix 1100 system, you don't want to bog the processor down unnecessarily!

Cheers,
Dustin
 
Now the question is do I want to leave it this way or go with the subtraction or jump routine mentioned earlier?

Assuming the 'S:13 Destination' method works ok then I would compare the time to execute for it compared to a string or the repeated subtraction method. You can look up execution times. Be sure to include the JMP execution times especially if you assume a beginning number in the 9000 range.

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)
 
Last edited:

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,966
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,661
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,961
Back
Top Bottom