Convert a Real to an Integer in S7-300

Clay B.

Lifetime Supporting Member
Join Date
Jun 2005
Location
Concord,NC
Posts
1,304
I am still looking but have not found the answer yet.o_O

I am getting data from a Rice Lake controller thru Profibus DP
to a Siemens S7-314C-2DP PLC.

All of my data is in Floats. I want to convert some of it once it is in my PLC from Real to word.

All of the reals I need to convert are single didget numbers with nothing after the decimal place.

I need these values for data logs and I hate to give up space for a bunch of zeros. :geek:

AM hopping someone else has crossed this bridge and already has the answer.
 
Try RND to get double integer. And then there should be a truncate function to convert it to 16 bit integer. Or, you can use some address shifting to get the value you want in 16 bit format.

Say that you have your double integer variable in MD0 after converting to double integer. If you read MD2, you should be reading the value in 16 bit format.

However, you need to be sure that the value won't overflow 16 bit, otherwise... well, I guess you get the picture.
 
Make an FC (Let's call it FC1000 "Real2Int"
1. Declare "RealValue" as Real in the IN Table
2. Declare "IntValue" as INT in the OUT Table
3. Delcare "Temp1" as DINT in the TEMP Table
4. in FC1000 (I'm assuming your a ladder guy) Use ROUND function and Use "RealValue" in and "Temp1" Out
5. In the same network Move "Temp1" to "IntValue"

Now you can use FC1000 as many times as you like to convert Real to Int. A little verbose but easy for someone to follow.

Note I am assuming you checked that you are within range before you converted. Otherwise you could check in the block and report error etc.

FC1000.jpg
 
Last edited:

Similar Topics

Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,436
Hello, First, please excuse my question I am new to Modbus. I have a CX-5140 control unit from Beckhoff and an instrumentation device that...
Replies
3
Views
3,134
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,620
Hi Guys, i'm begginer and i'm trying to convert a real value (not fix value) to BCD. It works if i put fix real value but when i put variable...
Replies
2
Views
1,947
I converted 2 consecutive Ints to a Real using a Copy instruction. So now I need to reverse this process. Convert a Real into 2 consecutive Int's...
Replies
9
Views
2,473
Back
Top Bottom