9/12/2019 8:25 PM  
Joined: 11/12/2017 Last visit: 9/18/2019 Posts: 107 Rating: (1) 
Hello everyone, I will explain my application using Step 7 V5.5 software. I have a 420 mA analog input signal fed into my S7300 PLC (CPU 3152DP). This current input signal is used to set the speed reference for a micromaster 420 inverter drive through Profibus. Ok, so I have created a function where this 420mA input signal (ADC result gives 0 to 27648 in decimal), is scaled between 0 and 16384 (where 16384 is 4000 hex, and corresponds to 50Hz on the micromaster 420). But my problem is I have declared all these variables as data type INT. But I cannot have decimal point numbers (or floating point numbers) so my calculations just return 0. My question is how can I get around this problem? At the end of my calculations, I have to be able to store the value in a WORD data type as this is what the micromaster 420 requires. I need a way to store/perform calculations with floating numbers while having a WORD at the end of the calculation. Is REAL my only option? Thanks David. 
Last edited by: DS_7 at: 09/12/2019 20:26:04 

9/12/2019 9:24 PM  
Joined: 1/21/2013 Last visit: 11/12/2019 Posts: 4369 Rating: (656) 
Hello David, I don't know your appkication but have you tried with FC 105 Scale and FC 106 Unscale if for you work? https://www.google.com/url?sa=t&source=web&rct=j&url=https://support.industry.siemens.com/cs/attachments/23330722/Scaling_and_Unscaling_Analog_Values.pdf&ved=2ahUKEwi4oPPBgMzkAhVFIlAKHfE5CiYQFjABegQICBAB&usg=AOvVaw13Lu14CTvEybOeafGIPl0n Attachmentscaling_and_unscaling_analog_values.pdf (7 Downloads) 
Last edited by: Jen_Moderator at: 09/13/2019 09:50:21Added PDF as an attachment. 

This contribution was helpful to1 thankful Users 
9/12/2019 9:58 PM  
Joined: 11/12/2017 Last visit: 9/18/2019 Posts: 107 Rating: (1) 
Hello again Ste39, FC106 would work for us was interested in having our own blocks. Do you know if there is any way to convert a REAL data type into a WORD type in LAD? Thanks David. 
9/12/2019 10:24 PM  
Joined: 1/21/2013 Last visit: 11/12/2019 Posts: 4369 Rating: (656) 
Hello, ROUND instruction? And then you use MOVE from double Word to Word e.g.  ROUND  MOVE  200.0 I I MD100 MW102 I I MW104 I I I I   
Last edited by: Ste39 at: 09/13/2019 13:07:42 

This contribution was helpful to1 thankful Users 
9/13/2019 5:50 PM  
Joined: 11/12/2017 Last visit: 9/18/2019 Posts: 107 Rating: (1) 
Hi Ste39, I will give this a go. I have a calculation where the result should be an decimal number between 0.0 and 1 (so for example could be 0.836584). This value is then used in some more calculations after. I need to keep the values after the decimal point. My problem is that at the end of my calculations I need to convert this value from above from INT or REAL into a single WORD for the drive. I will experiment a bit more with your suggestion. Thanks David 
9/13/2019 6:31 PM  
Joined: 1/21/2013 Last visit: 11/12/2019 Posts: 4369 Rating: (656) 
Hello, try to multiply by REAL e.g x 100.0 or x 1000.0 because with ROUND will be 1 or 0. 
This contribution was helpful to2 thankful Users 
9/14/2019 12:17 AM  
Joined: 11/12/2017 Last visit: 9/18/2019 Posts: 107 Rating: (1) 
I need to check something with you guys. I think I am getting rusty due to not using Step 7 in a while. I have attached 2 images of very basic division calculations with different data types. See the image in this post below: I am dividing 100 by 10 and returning a value of 10 as expected. This is true for the REAL type, DINT type and the WORD type. 
9/14/2019 12:21 AM  
Joined: 11/12/2017 Last visit: 9/18/2019 Posts: 107 Rating: (1) 
Now when viewing the same calculations as seen in the image attached to THIS post, in the REAL type division, the decimal equivalent is now seen as 1092616192, and NOT 10. But when this value is viewed as a REAL type, it returns 1.0000000e+001 which is 10. Can someone explain where this decimal equivalent of 1092616192 comes from, it is confusing me. I think it is due to be signed 32 bit number? Thanks David. 
9/14/2019 1:01 AM  
Joined: 9/27/2006 Last visit: 11/17/2019 Posts: 8754 Rating: (1805)

Hello David; I think you need to review your numbers theory just a little. A REAL value is written as a singleprecision floatingpoint value, based on IEEE 754: https://en.wikipedia.org/wiki/Singleprecision_floatingpoint_format So when you write a Real value to a 32bit register (MDxxx) it takes the form of mantissa + exponent as described in the article above. If you try to read the same register using binaryto decimal conversion directly without taking into account the internal formatting of the floatingpoint value (as you are trying to do using your "decimal" format) you will get a totally unrealistic number. See this site for examples of floatingpoint arithmetic in computers, there are examples for 32bit floatingpoint values that should enlighten you. http://sandbox.mc.edu/~bennet/cs110/flt/ftod.html Hope this helps, Daniel Chartier 
Last edited by: dchartier at: 09/14/2019 01:09:01 

This contribution was helpful to2 thankful Users 
9/14/2019 7:12 AM  
Joined: 1/21/2013 Last visit: 11/12/2019 Posts: 4369 Rating: (656) 
Hello David, and read also from Programming manual at Chapter 27.3.2.1 INT, 27.3.2.2 DINT and 27.3.2.3 REAL 
Follow us on