Remainder math register does not update when using DIV instruction

jendrus

Member
Join Date
Nov 2011
Location
Midwest
Posts
21
Hello all, I am fairly new to Allen Bradley programming so bear with me.. ( I have prgogrammed microcontrollers and computers before). Im working on a ML1100.

I am trying to do a simple extraction of the last three digits from a four digit number (e.g. starting with a number like 3875, all I am interested in is '875'.) I figure I can do a DIV instruction ( Dividing the number by 1000 and moving the number in register S:13 to a location in memory. I have had no success doing this. The S:13 register always stays at 1. Attached is a picture of the code I have.

Any help is appreciated.
Thanks
Stan

micrologix divide code.jpg
 
N file types are integers. It will never show the fractional part. You need to use F file type which is floating point.
 
Ok, so do i have to divide twice then? Im not sure how the remainder is formulated, whats with the fractional part? When i divide two floating point numbers (3875.0 by 1000.0 I expect to get 875 as the remainder, correct? I am not seing this.
 
Exuse the dumb question but how do i get the decimal part alone in a memory location after the division. Im new with these data files in Allen Bradley pragramming. Thanks for the help
 
I think you can pull this off with a AIC and AEX instruction. AIC N20:99 ST9:0 , then next rung try AEX ST9:0 3 3 ST9:1 . You can then move ST9:1 back to an unused Integer if you want too.

Think that'll work.
 
Last edited:
Use the DIV instruction to divide one value by another value (Source A/Source B) and place the result in the Destination. If the Sources are single words and the Destination is directly addressed to S:13 (math register), then the quotient is stored in S:14 and the remainder is stored in S:13. If long words are used, then the results are rounded.

Note that S:13 must be directly used as the Destination to trigger the Quotient/Remainder behavior.​
 


Note that S:13 must be directly used as the Destination to trigger the Quotient/Remainder behavior.​

I think Bernie has it nailed as far as how I read the original post. 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.
 
I tried using S:13 as the destination, and occasionally I get erratic results. You can see the discrepancy in the attached image. Is this because of a difference in the floating point and S:13/14 math, or is it possibly a quirk inherent in RSEmulate?

3-digit Extraction Example errors.jpg
 
I would just keep subtracting 1000 until the number was less than 1000.

Maximum number of jumps would be 32.

2011-11-28_233124.jpg
 
There is a way to do this, and a normal DIV should work. I, too, tried in on the Emulator, and I am pretty sure what I am seeing is NOT correctly emulated. I have a ML1000 I can fire up to try out after supper.

I think my previous comment about the system bit was wrong. I was thinking of the S:2/14 flag which affects the results of overflows.

Paul
 
I'm with bmacattack33 that is exactly how I would approach getting the fractional only. I've wadded my way through a lot of good and bad programs and have never seen S:13/14 used.
Besides all math should be floating point! :)
 

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
3,974
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,962
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,517
does plc5 have a method for getting the remainder in a division function like in clx? thanks
Replies
15
Views
10,650
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,949
Back
Top Bottom