PLC5 DIV rounding vs ControlLogix DIV truncating

wildswing

Member
Join Date
May 2005
Location
Sault Ste Marie, Ontario
Posts
281
Hey fellas,

I'm down to my last bug in an RSL5k ladder program converted from RSL5. In the 5 there's a DIV that divides an INT, by an INT and stores it in an INT. The subsequent logic depends on how it rounds off the result.

Now in 5000 I see that the DIV does not round. It truncates. This was screwing up the logic that depends on the properly rounded off result.

My solution was to put the result of the DIV into an intermediate REAL, then MOV the REAL to the original destination INT. See attached. This seems to work ok when I simulate the process. I'm just checking with y'all to see if you see anything wrong with doing it this way.

CLX v PLC5 DIV rounding.PNG
 
In an interesting twist I think that the Logix processor handles that calculation correctly and the PLC5 handles it incorrectly. This is a calculation with two integers. The calculation should be done as an integer calculation. There should be nothing to round. If the calculation acts correctly the result shouldn't become "5" until Source A becomes "500". In other words, 499/100 should be 4 in an integer calculation.

That being said, I think your code change is fine with one possible issue. I THINK the PLC5 would always round up when presented with a 0.5 value. I THINK the Logix family rounds to even on a 0.5. So 1.5 would round to 2 but so would 2.5. You might want to test those conditions a little bit.

Keith
 
You solution seems like a reasonable one. Anytime you change platforms there is always some little thing like this that just makes you o_O

Just curious, why did you go with the old PLC5 addressing in the new program instead of using tag names? I used to to a bunch of SLC and Micrologix programming but ever since I did my first RSL5K project I am totally sold on tag names. When I do a RSL500 project I use the hell out of the Symbols that it has just because it makes it kind of like a RSL5K project.

Like I said just curious as I have some upgrades coming the future and was wondering.
 
Whether or not it rounds up or down at #.5 is not an issue. The process does not require that degree of precision, however, now that you've mentioned it I might run some more simulations. Thanks.

Why did I stick with the old addresses? Time. I'm an in-house, chief cook and bottle washer. I simply do not have the time to rewrite a complete plc program. I used RSL5000's conversion app. Besides, we have an entire staff of electrical techs, with a wide range of talents, that are accustomed to looking at RSL5 logic. Keeping things as similar to what they were in the 5 results in me receiving far fewer phone calls at 3 am.

Thanks for the replies guys. Much appreciated.
 
Just a quick update. RA tech agrees with my solution. In fact, it's shown in the help file for the DIV instruction. I guess I should have looked there first. :oops:

Thanks for the feedback fellas.
 
Div then use the S:13 and 14 registers ?

Yes this thread is old but this is relevant.
in Logix 500 the DIV command does this same rounding - but the instruction help says that the unrounded answer is contained in S:13 and S:14. How are these registers then captured? Wouldn't capturing the math registers allow for a MOD functionality to be attained?

Thinking that would work I tried to capture these S registers and MOV them to N registers on the rung following the DIV of 2 integers... but I can't seem to capture them nor do I see a change in the math registers.

What am I missing here?
 
Yes this thread is old but this is relevant.
in Logix 500 the DIV command does this same rounding - but the instruction help says that the unrounded answer is contained in S:13 and S:14. How are these registers then captured? Wouldn't capturing the math registers allow for a MOD functionality to be attained?

Thinking that would work I tried to capture these S registers and MOV them to N registers on the rung following the DIV of 2 integers... but I can't seem to capture them nor do I see a change in the math registers.

What am I missing here?

Check out the attachments posted by bernie in this thread, they may be what you're looking for.
 
plvce...

Answer = DIV N7:0 60 S:13

I would never have thought to place anything into those registers on purpose. This has been a valuable post. Thank You!
 
I wouldn't have thought of it either, but I remembered having run across a thread on the topic and just hunted it down for you. Cheers.
 
Yes, but look at that example in the help file, nowhere does it demonstrate to put the result *into* the S13 register, It just says the unrounded and remainder just wind up there. That example pic is misleading, at least in todays experience.

DIV.jpg
 
Last edited:
About eliminate floating point

hey fellas,

i'm down to my last bug in an rsl5k ladder program converted from rsl5. In the 5 there's a div that divides an int, by an int and stores it in an int. The subsequent logic depends on how it rounds off the result.

Now in 5000 i see that the div does not round. It truncates. This was screwing up the logic that depends on the properly rounded off result.

My solution was to put the result of the div into an intermediate real, then mov the real to the original destination int. See attached. This seems to work ok when i simulate the process. I'm just checking with y'all to see if you see anything wrong with doing it this way.


i need this ,..... I have a analog input and adter scaling the number is for example 4.5726366387213
i need let the number only as 4.57
how i do that ?
Please
 
i need this ,..... I have a analog input and adter scaling the number is for example 4.5726366387213
i need let the number only as 4.57
how i do that ?
Please



Multiply it by 100 into an integer destination, then divide that result by 100 into a floating point destination.

But you are not "eliminating" the floating point ...
 

Similar Topics

I am using the following formula and I am getting error, Invalid Expression - too many closing parenthesis. when i copy the formula to notepad or...
Replies
4
Views
132
Preface: Kinda long, so I made section titles Intro: I just want to see if anyone here has seen anything similar. A PLC5-40 series C enhanced...
Replies
3
Views
339
Hi, can anyone help me get a pdf file for this RSP files. They are from a PLC5. Thanks
Replies
1
Views
367
Hello all, I am seeing this behaviour where an integer file (N46:33), has an integer in binary (11110) which is 30 in decimal. I did a...
Replies
7
Views
502
Back
Top Bottom