DINT to REAL

mylespetro

Member
Join Date
Dec 2015
Location
NS
Posts
740
Hey everyone,


I feel like I'm missing something completely obvious here, but I'm trying to convert a DINT to a REAL number in a ControlLogix L71 processor for a belt scale. I've searched the forum and came up with a few posts that said to just use a copy (COP) instruction and move the DINT into the REAL with a length of 1. When I do this however, I end up with an extremely miniscule number in the REAL word, even with very large DINT numbers. I've attached a screenshot of the test program I have on the bench, literally just the two tags and a COP instruction. Can someone shed any light on what I'm missing here?


Thanks


EDIT: This was the largest number that actually produced a non-microscopic result, we're expecting approximately with 6 digits, e.g. 447829 will be a rate of 447.829 tons/hr, but using 447829 as the DINT gives a REAL of 6.27542090e-040

DINTtoREAL.JPG
 
Last edited:
Thanks guys, I was just confused because people were saying that using the COP instruction worked for them. I've used MOV instructions in the past, but I was trying to follow the advice of previous threads.
 
COP works OK when you're going from REAL to REAL - or from DINT to DINT ... specifically, when you're NOT changing from one data type to another ...

basic idea: a MOV command moves VALUES ... a COP command moves BIT PATTERNS ... the bit locations in a REAL number aren't stored with the same binary bit values as the bit locations in a DINT number ... that's why things get crazy when you COP (copy) from one data type to another ...

and going further ...

no offense - but you might not be aware of some of the "gotchas" involved when using REAL numbers - so here's a little experiment that you might find enlightening ...

go to a REAL location - and manually type in the number 123456789 ... now look carefully and see what value actually pops up when you try to store that simple sequence ...
 
Last edited:
COPY works when you need to send a REAL as a DINT. I had a client that was already sending 10 DINTS from one controller to another. I needed to send a REAL, Copied REal to DINT, then in receiving controller, copied DINT to REAL, since Copy does bit by bit, worked like a charm.
 
ALL, and I mean ALL instructions will automatically convert the result of an expression, or just the source value of a MOV, to the data-type of the destination.

Going from DINT, INT, or SINT to REAL is no problem, but going the other way there are issues that crop up.

Because the destination is an Integer type, the controller will have to ROUND the result to "fit" into the integer.

The Logix5000 series of controllers use a method of rounding that is strange to many people, called "Round-to-Even". This means that if the result is xxx.5 , the rounding method converts it to the nearest EVEN number, not upwards as is more traditional.

So, if you divide an odd number by 2, eg ....

1, 3, 5, 7, 9, 11, etc., you will get ....

0.5, 1.5, 2.5, 3.5, 4.5, 5.5 etc., and storing these in a DINT will give ...

0, 2, 2, 4, 4, 6, etc.


This can cause severe issues unless you deal with the strange results.
 
The round to even only comes in to play when the result has a fractional part of exactly .5 It performs as normal for all other fractional parts.
 

Similar Topics

Situation: Single [EQU] instruction with single [OTE] on a rung, nothing else/simple. [EQU] operand(A) is a real number data type...
Replies
16
Views
2,557
I work at a cheese factory and we recently ran into a problem where in an older controller they where able to use a REAL Data type in OTU and XIC...
Replies
13
Views
2,399
I have been working on an existing project for some time now and restructured the whole program into POUs instead of a singular main. Everything...
Replies
18
Views
3,188
Greetings fellow PLC programmers, I know there is a simple way to get the system date time of the RSLogix system. But, is there then a way to...
Replies
12
Views
8,380
I'm being directed to fill process values into an array of DINTs. A portion of the REAL values got copied into 2 DINTs each, but there are more...
Replies
2
Views
2,201
Back
Top Bottom