PLC5 Math CPT

Can someone please explain why these 2 CPT instructions in a PLC5 would evaluate differently?

F239:1 = (N49:13 * 3000.0) | 4095.0

F239:1 = (N49:13 * 3000) | 4095

I had 2 instruments to scale (the F and N numbers used above are for eg) 4-20. The first rung I wrote added the .0 the second one didnt. The first rung scaled OK, the second one didn't. I don't understand the difference between having the .0 and not.
 
HMMM?
See picture below.

The decimal was added to the 3000 and 4095 constants because the destination is a floating point. I used an integer as a destination and get the same (correct) values.
The instruction without the decimal points gave an incorrect value.??
Someone with knowledge of how the math in executed within the PLC will probalaly
be able to explain it to us (hopefully).

FYI in my example the value of N7:19 is 2048

cpt.png
 
Without the decimal point the first multiplication overflows the integer accumulator. The division then gives a bad result.

With a decimal point (3000.0) the process immediately switches to floating point which doesn't overflow. The process then continues using flaoting point until the assignment to an Integer where the answer is rounded.
 
Incidentally, You can simplify your expression by combining the constants and use the MUL instruction which executes slightly faster. In this case there won't be any ambiguity about type casting and you won't have integer overflow.

MUL N49:13 .7326 F239:1
 

Similar Topics

Hey everyone, I'm on a commissioning currently working on a project involving a PLC5/40C and I'm in need of access to RSLogix 5. I understand the...
12
Replies
709
Views
So ya our plant is weighing upgrading photoeyes on a conveyor system of about 30 motors to better distinguish product , very limited upgrade...
34
Replies
1,597
Views
Just did a conversion of a PB32 project to CCW using a PanelView800, setting up serial DF1 (only choice of processor was ML1400) after the project...
3
Replies
283
Views
Hello all this may have been covered elsewhere but I did not see it. I need to test a PLC processor that would normally go in to a 16 slot...
12
Replies
614
Views
how is the example indirect address done in RSLOGIX5000 for Contrologix ver 20 B90[N32:13] Thanks for any input
39
Replies
1,526
Views
Top