You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old September 11th, 2019, 02:49 PM   #1
mylespetro
Supporting Member
Canada

mylespetro is offline
 
mylespetro's Avatar
 
Join Date: Dec 2015
Location: NS
Posts: 156
DINT to REAL

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
Attached Images
File Type: jpg DINTtoREAL.JPG (118.6 KB, 123 views)

Last edited by mylespetro; September 11th, 2019 at 02:52 PM.
  Reply With Quote
Old September 11th, 2019, 02:58 PM   #2
Aabeck
Member
United States

Aabeck is offline
 
Aabeck's Avatar
 
Join Date: Feb 2013
Location: Detroit
Posts: 1,372
I would simply use a MOV DINT REAL instruction. That moves the DINT value without changing it.
__________________
Never underestimate the quality of idiots that will be running your machines
http://aabeck.com
  Reply With Quote
Old September 11th, 2019, 03:00 PM   #3
mylespetro
Supporting Member
Canada

mylespetro is offline
 
mylespetro's Avatar
 
Join Date: Dec 2015
Location: NS
Posts: 156
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.
  Reply With Quote
Old September 11th, 2019, 03:03 PM   #4
Ron Beaufort
Lifetime Supporting Member
United States

Ron Beaufort is offline
 
Ron Beaufort's Avatar
 
Join Date: Jul 2002
Location: Charleston, SC
Posts: 5,540
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 ...
__________________

2-B ?
Best regards, ----+----] [----+------------( )----
Ron | |
PLC Training Boot Camp - Retired | 2-B |
+----]/[----+

I once was lost, but now am found, was blind, but now I see.


Last edited by Ron Beaufort; September 11th, 2019 at 03:10 PM.
  Reply With Quote
Old September 11th, 2019, 03:05 PM   #5
Ken Moore
Lifetime Supporting Member
United States

Ken Moore is offline
 
Ken Moore's Avatar
 
Join Date: May 2004
Location: North, West, South Carolina
Posts: 2,658
I just multiply, DINT * 1=REAL.
  Reply With Quote
Old September 11th, 2019, 03:07 PM   #6
Ken Moore
Lifetime Supporting Member
United States

Ken Moore is offline
 
Ken Moore's Avatar
 
Join Date: May 2004
Location: North, West, South Carolina
Posts: 2,658
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.
  Reply With Quote
Old September 12th, 2019, 04:26 AM   #7
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,587
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.
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old September 12th, 2019, 09:59 AM   #8
bernie_carlton
Lifetime Supporting Member + Moderator
United States

bernie_carlton is offline
 
bernie_carlton's Avatar
 
Join Date: Apr 2002
Location: Yakima, Washington
Posts: 6,297
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.
__________________
Controlling outputs is the PLC's way of getting its inputs to change.

www.thePLCguy.com
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Writing a Decimal DINT to a Float REAL Saturn_Europa LIVE PLC Questions And Answers 12 October 30th, 2018 04:14 PM
Step 7 5.5, DINT to REAL janner_10 LIVE PLC Questions And Answers 3 July 13th, 2018 02:35 AM
misunderstanding CMP MartyMaucher LIVE PLC Questions And Answers 5 November 16th, 2015 01:37 PM
Compare bits of dint to another dint value seth350 LIVE PLC Questions And Answers 7 April 3rd, 2015 02:46 AM
Writing a ST compiler Peter Nachtwey LIVE PLC Questions And Answers 60 September 21st, 2012 03:27 PM


All times are GMT -5. The time now is 01:34 AM.


.