DIV in RSLogix 5000

jaden

Member
Join Date
Sep 2009
Location
Pleasant Dale, Nebraska
Posts
305
When doing a Divide function in RSLogix 5000, the instruction is listed as putting the "result" in the destination. To me, the result could be the quotient, either exact or rounded. What about any remainder? In RS500, these are all defined and accessible.
 
if you're really interested in the "remainder" of the division, then you might want to take a look at the MOD (Modulo) instruction ...

TIP: PLCs often don't handle arithmetic operations the same way that a "calculator" does ... with RSLogix5000/Studio5000 this can lead to some unexpected results ... for example: when "rounding off" we NORMALLY round a fractional value of .5 UP to the next highest whole number ... but RSLogix5000 will round .5 to the nearest EVEN whole number ...

so ...

putting the fractional value 2.5 into an INTEGER location would "round off" to result in a value of 2 (nearest EVEN value) - and not the value of 3 (next HIGHER value) that most people would expect ...

if you can give us more detail about exactly what you're trying to accomplish (with some relevant examples) we might be able to give you some more detailed advice ...

good luck with your project ...
 
Last edited:
If your destination is a REAL then you get the resulting floating point value.

If the destination is a DINT (or INT or SINT) then the result will be either rounded or truncated. If at least one source is a REAL then result is rounded. If neither source is a REAL (all values are SINT/INT/DINT) then the result is truncated.

If you want the remainder of the DIV then use the MOD instruction. I don't understand why you would say "In RS500, these are all defined and accessible." This is all defined too.

OG
 
Originally posted by Operaghost:

I don't understand why you would say "In RS500, these are all defined and accessible."

What he means is that in the SLC processors the remainder of an integer division ends up in one of the math system registers, S:14 I believe. You don't have to explicitly execute the MOD instruction to get the remainder. It is available as a matter of course. But I suspect you knew that already.

Keith
 
Also be careful as AB PLC's treat dividing by zero as a major fault and shutdown.

That is not true in ANY AB PLC.

In PLC2, PLC3, PLC5, PLC5/250, Logix500 and Logix5000 systems it is simply a "minor fault", which does not shutdown the processor.

Dividing by zero does not cause a major fault itself, but it will set the "Overflow" status bit.

That is not the problem either, because the overflow status bit is a "minor fault", and logic scan will continue. The overflow bit will most likely be reset on the next "successful" instruction that affects the arithmetic status bits.

So looking at Logix500, SLC and Micrologix systems, the "problem", if you'd like to call it that, is that any setting of the "overflow" bit during the program scan, will also set the "Overflow Trap" bit S:1/5

It is that "Overflow Trap" bit S:1/5 that causes the Major Fault, if it is still set at the end of the scan of file 2.

IMHO it is a stupid thing that they did when designing that functionality, for the following reasons.....

1. "We've reached the end of the logic scan, and somewhere along the way an instruction set the "overflow" bit. This was flagged by the "overflow trap" bit, and it's now on, so we will major fault the processor." - Why? The programmer may have inspected the "overflow" bit where it was important to know it, and dealt with it accordingly......

2. "We've reached the end of the logic scan, and somewhere along the way an instruction set the "overflow" bit. This was flagged by the "overflow trap" bit, and it's now on, so we will major fault the processor." - Why? Do they think it "unsafe" to proceed with executing any more code because the program is "flawed" in some way. Don't you think you should have stopped processing any more code in that scenario, why wait until the end of the scan? Agreed, faulting the processor will stop outputs coming on, but the output data will already have been written to the Output Image Table, and internal flags and registers will have been processed with the "minor fault" on one or more instructions occurring.

3. "We've reached the end of the logic scan, and somewhere along the way an instruction set the "overflow" bit. This was flagged by the "overflow trap" bit, and it's now on, so we will major fault the processor." - And? : Please tell me where this occurred if you think it's that important... Oh, you can't, which is both sad and useless at the same time.

For those reasons, and possibly many others, without exception every single Logix500 application I have laid my eyes on, have, as the last rung of file 2, an unconditional unlatch (OTU) of the "overflow trap" bit, S:1/5 !!

Programmers : If you consider it important to test the overflow status of an instruction, do so immediately following that instruction, and if it is set, deal with it there and then, and OTU the overflow trap bit.

Everyone : If programmers follow the above advice, that is the only case where the overflow trap bit is (somewhat) useful, in the sense that "something unforseen" occurred.. You'll get no indication which instruction it waq though....
 
A distinguished colleague has notified me by PM that I misquoted the address for the overflow trap bit...

It is S:5/0 "Overflow Trap", not S:1/5 "Forces Enabled"

In my defense I have been scouting around the "forces enabled" status S:1/5 for another project, so got them confused.
 

Similar Topics

I'm looking for some clarification if anyone here is familiar with UL698a panels. Panel is out of zone/class'd area. with thermocouples extending...
Replies
0
Views
126
Hi - I am searching for an M12 panel receptacles to use for ethernet connections. I see lots of M12 cables that are ATEX / C1D2 rated but nothing...
Replies
2
Views
990
Can someone please recommend a signal light tower that can be used in a Class 1 Div 2 Classified area? Explosive gasses can be present under...
Replies
4
Views
1,758
Hi everyone, I have a customer looking for a printer that has Class 1 Division 2 rating. I would like it to have a Ethernet connection and be...
Replies
0
Views
1,185
Hi, i used DIV function in my program. i am dividing a MD8 with 10. i selected REAL. but the result show in Hex. how will i get REAL value? Thanks
Replies
1
Views
2,261
Back
Top Bottom