Technical Forum

STEP 7 / STEP 7 Lite

double to integer in step 7

Thread Starter: Brooks   Started: 6/10/2008 3:05 PM   Replies: 7

« Previous thread Next thread »
Page 1 of 1 (8 items)
  6/10/2008, 3:05 PM
Joined 4/24/2007
Last visit: 6/18/2008
Posts: 24
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
hi - i'm trying to compare a real value (setpoint) with an analog word input (RTD process value).  i'd like to convert the real value to a word to compare.  how do i convert DI to I?  in microWIN i simply use the DTI convert function, but I can't find anything similar in step 7.

brooks
Top
  6/10/2008, 3:29 PM
Joined 12/22/2006
Last visit: 4/28/2009
Posts: 17
Rating:
Rated: Outstanding [3.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hi,

I think that your problem is not just conversion from real to word. The input analogic word is a value with a standard range from 0 (that correspond to 4mA or 0 Volt depending from the input analog card) to 27648 (20mA or 10 Volt). The real set point should be a value between the range of the instrument (e.g. temperature trasmitter from 0 to 200 °C).
So to compare the two values you have to rescale the real value to the analog range (0 to 27648) or the analog word value to the real range (e.g. 0 to 200).

Anyway to convert a real (floating point) to a double integer you can use the RND (round) or TRUNC command losing decimal part or the real value. From a double integer to an integer no conversion is required.
Top
  6/10/2008, 4:57 PM
Joined 6/10/2008
Last visit: 3/10/2009
Posts: 6
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
It is also good to remember that when you convert a Real value to an integer you will lose the decimal values from it  ....  =D
Top
  6/11/2008, 6:20 PM
Joined 6/22/2007
Last visit: 6/28/2009
Posts: 65
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Could you do it the other way ?  Convert the Int to a Dint than to Real and then compare them ?
Top
  8/30/2008, 9:55 PM
Joined 11/20/2007
Last visit: 5/28/2014
Posts: 17
Rating:
Rated: Above avarage [3 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
It´s easy.

eg
L MD x
T MW y

Watch the ranks of the DInt and Int, so they do not lose information.
Top
  8/31/2008, 3:52 PM
Joined 10/31/2005
Last visit: 7/15/2014
Posts: 238
Rating:
Rated: Excellent [4.3 out of 5 / rated 20 time(s)]. (20) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
It is very easy to convert from INT to REAL, then to compare. You need to use ITD (integer to double integer) then DTR (double integer to real) instructions.
Looek at this small STL code:



=== Edited by Pandiani @ 8/31/2008 3:53 PM [GMT ] ===


Top
  8/31/2008, 5:57 PM
Joined 5/28/2008
Last visit: 7/24/2014
Posts: 3261
Rating:
Rated: Outstanding [3.7 out of 5 / rated 591 time(s)]. (591) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
As I have understand from your post, your problem is to convert a real number into an integer number.

Ok.
Real number : 32 bits
Integer number : 16 bits.

So first of every thing you have the real number of the physical setpoint and/or the process variable.
Use RND function to round the analog floating poit value into "double integer value" (i.e. 32 bits)
Say that the output of the RND function is in MD164. so The bytes 164, 165, 166, 167 are occupied by that value.
Simply you can use MW 166 as an integer and you will find it containing the same number of the setpoint/ process variable

see the attachment, I think it will explain to you what you should do.

I have made it using PLCSIM.

Regards,

Attachment: PLCSIM.JPG  (272 Downloads)

Ayman Elotaify
MISC Egypt
www.miscegypt.com

Top
  8/31/2008, 6:21 PM
Joined 10/31/2005
Last visit: 7/15/2014
Posts: 238
Rating:
Rated: Excellent [4.3 out of 5 / rated 20 time(s)]. (20) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
If there is a need for comparing numbers, I would convert integer to real and then compare. I think it's safer this way.
Top
Page 1 of 1 (8 items)
Actions