PLC5 Math CPT

Oceansoul

Member
Join Date
Apr 2010
Location
England
Posts
307
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
 
That makes sense. Could someone explain why this happens? I.e. how the maths works. Espically the - number when moving to an interger.
 
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

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
180
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
397
Hi, can anyone help me get a pdf file for this RSP files. They are from a PLC5. Thanks
Replies
5
Views
559
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
552
Back
Top Bottom