Convert Float to Integer in SLC 500

Tim Ganz

Member
Join Date
Dec 2010
Location
Dallas, Texas
Posts
689
I have a Float that is F45:10 and I need to convert it to an integer to display on an HMI that is in VB.net and we can't change.

I look on the AB Knowledge base and found a tech-note that said to do a COP F45:10 to N150:100 length of 2 and in N150:100 I have a number that is 16436 and in N150:101 I have a number that is 31457 and the amps reading in the float F45:10 is 3.1 which is oil pump amps.

What other steps do I need to do to get it to just display an integer number of 3 for the amps? I am missing something.
 
Subtract 0.5 from the floating point number with a destination of an integer. The value will be rounded off to 3 in your case.
 
I have a Float that is F45:10 and I need to convert it to an integer to display on an HMI that is in VB.net and we can't change.

I look on the AB Knowledge base and found a tech-note that said to do a COP F45:10 to N150:100 length of 2 and in N150:100 I have a number that is 16436 and in N150:101 I have a number that is 31457 and the amps reading in the float F45:10 is 3.1 which is oil pump amps.

What other steps do I need to do to get it to just display an integer number of 3 for the amps? I am missing something.

the SLC analog comes in as an integer from the analog module (16 bit binary 0-32767), and it must be scaled to the floating point. You'll have to look the integer data file for your analog module, there you will find the integer value for each channel (0-32767).

take your value of 3.1, multiply by 10 and get 31 and put this value in a N: file. Im not sure how that HMI software displays, can it just display one digit?
 
Last edited:
Subtracting .5 will leave you with just the whole number "3 in your case.

3.1 minus .5 = 2.6 destination an integer will round the number to 3.
3.8 minus .5 = 3.3 destination an integer will round the number to 3.


Keep in mind that if the float is 3.8 ( greater then 3.5) then using this method will still give you a value of "3". If you just want to round the number to the nearest whole number then just use a "MOV" instruction. ( 3.1 will be 3, 3.6 will be 4 and so on)
 
Last edited:
Mickey it's an amp reading that can go from 0 to about 18 amps.

How can I convert this changing floating point number to an integer that scales as the amps increase?

The existing HMI is setup only for an integer and we can't change it because the original programmer of the vb app is deceased for many years now. We just want to have the whole number from 0 to 18 amps on that HMI.

On our other HMI we are using the float directly so it read from 0 to 5.7 or 10.5 or 17.6, etc.
 
Again if you want to display the value to the nearest whole number then use the "MOV" instruction. The floating point number will be rounded off.

Source is your floating point number
Destination is your integer register.

5.7 will be 6
10,5 will be 11
17.6 will be 18

If you just want the whole number without rounding up then use the sub .5 method.

5.7 will be 5
10.5 will be 10
17.6 will be 17
 
Mickey it's an amp reading that can go from 0 to about 18 amps.

How can I convert this changing floating point number to an integer that scales as the amps increase?

The existing HMI is setup only for an integer and we can't change it because the original programmer of the vb app is deceased for many years now. We just want to have the whole number from 0 to 18 amps on that HMI.

On our other HMI we are using the float directly so it read from 0 to 5.7 or 10.5 or 17.6, etc.

Mickeys suggestion will work, if you don't like that one, you can use a SCP instruction to scale your incoming analog to 0-18 amps and put that in an integer file.
 
okay,

The float you are trying to convert is 32bit float. So if you use CPW or COP instruction with length 2 . It will split your 32bit data into two int data ( Example F120:1 to N120:1 and N120:2)

If you wanna convert 32bit float into single 32bit int. Then you have to create data file for long Int . And try CPW or COP with lenght 1 . It will work.
 

Similar Topics

Hello i hope a get some help here. Is´s possible to convert float into integrer in S7?
Replies
6
Views
4,221
Hi all, Going to use a ML1400 to talk to a Krohne gas meter via Modbus. Krohne's totals come as doubles (64-bit floats). I was wondering if...
Replies
5
Views
4,703
Hi, I read a modbus map in array of 350 elements. The destination is integer. Now I want to copy this array into floating point array while...
Replies
3
Views
2,033
Jees... Continuing from this thread... http://www.plctalk.net/qanda/showthread.php?t=85341 I now have the correct pressure in Torr and mBar...
Replies
24
Views
7,430
Hi all, I'm communicating with a modbus device which sends data in 32 bits data. You can see the structure in this example: N7:4...
Replies
6
Views
4,579
Back
Top Bottom