Math on the Automation DL06

agarb

Member
Join Date
May 2006
Location
USA
Posts
309
I've realized that implementing math functions on the DL06 is much more difficult for me than it is on the Allen Bradley processors that I am most familiar with.

Lets consider a real-world example, taken directly from a project I am working on.

I have a TMRA that I want to calculate the percentage complete.

TMRA is T4
Preset for the timer is in V13002
Result is to be a real number stored in V12000

Here is how I did it:
LD K100
MULD TA4
DIVD V13002
BIN
BTOR
DIVR R100
OUTD V12000

Is there a better way?
 
That looks about right. Any particular reason you need the result in a real number? Assuming it is for display purposes, I would likely have just OUTDed the result after the DIVD. Then, in the HMI, you specify that you have 2 implied decimal places. The HMI will then display the number properly.

Edit: I don't know what the rest of your logic for controlling the timer looks like, but keep in mind that timers in AD can time past their setpoints if still enabled. This could result in your math showing a few hundred percent complete.

Brian
 
The result is a real number because it is used in additional calculations later on. It is not ever used for display purposes.
 
Then what you have is good. There are a couple of IBoxes that could have helped make it look better, but not faster or more efficient.

Brian
 
Is it possible to do it with a single ibox?

If more than one ibox is required, is it possible to do it without any intermedite holding registers?

I wish the Math-Real ibox would let me convert from BCD within the same instruction.
 
I was going to use the MATHBCD Ibox for the first part, but I realized that it will not work with the double words that we are using. So, you are down to just one Ibox to clean up the conversion to Real.

You will notice that I am using V12000 as the intermediate holding register as well as the final result register. This is a useful technique on multistep math functions like this. It will work fine as the entire calculation will be taking place on the same rung (same conditions). It is impossible to have this calculation get stalled and leave the intermediate result in the register. Be careful with this technique when the calculation is spread across multiple rungs.

Brian

timer_percent.JPG
 
Thanks, I missed the BCDTORD instruction. That gets rid of the BIN, BTOR, DIVR R100 and makes it look cleaner.

The Allen Bradley way looks cleaner yet:

DIV
Source A - T4:0.ACC
Source B - T4:0.PRE
Dest - F8:0

:)
 
Agreed. I was just thinking about it now, but you _could_ use the MATHBCD Ibox, but it would be really ugly and not as efficient. The formula would look like ((TA5*k10000 + TA4)*k100)/(V13003*k10000 + V13002)
:)
 
Originally posted by agarb:

The Allen Bradley way looks cleaner yet:

True, it is cleaner looking. But that clean look is relatively expensive from a processing standpoint. The CPU still rerquires the correct typecasting. The AB oeprating system just does it for you. So that little timer division you have giong on there has two implied data type checks as well as two INT2REAL conversion in order to get your float result. You may not think this is a big deal until you consider this needs to be done on every operation, even the ones that don't require it.

Keith
 

Similar Topics

I am taking a Simple SP which is in BCD and adding to that, When doing so I have noticed if the value is < 8 it works out fine, but if > 8 it...
Replies
4
Views
2,492
I'm writing a program to control the speed of a motor with an encoder. As part of the program the motor turns a worm gear attached to a linear...
Replies
5
Views
3,743
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
389
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,365
Hi all. First time programming a machine of this type. A center driven unwind feeding to a center driven rewind. No dancers or load cells, just...
Replies
37
Views
4,895
Back
Top Bottom