Convert function

zezito

Member
Join Date
Jun 2004
Posts
45
hello to all!
i'm using a s7-200 cpu 224 wich dont have a REAL-INTEGER or REAL-DINTERGER convert instruction.

DOes any one have a solution to this problem?

thanks!
 
hello zezito;
Analysing basic math functions can be rewarding at times; however, if you just look at the S7-200 online help for the functions "round" and "trunc" you will find that they transform a Real variable into a DINT variable, in 2 slightly different ways.
Hope this helps,
Daniel Chartier
 
some_REAL = 176.565

l some_REAL
RND
T ROUNDED_DINT // ROUNDED_DINT = 177 (Fractional part rounded up)

L some_REAL
TRUNC
T TRUNCATED_DINT //TRUNCATED_DINT = 176 (fractional part stripped)


An example basic FC I use in S7 is this one:


L #REAL_In // Load acc with input real
RND // Round to nearest double int, store in ACCUM1
T #TmpDI // store copy for later
// Declares:
// in REAL_In REAL Input Value to convert
// out INT_Out INT Signed result of conversion
// out bValid BOOL True if conversion was valid
// temp TmpDI DINT Temporary working double int



AD DW#16#FFFF8000 // Create a mask for bits 15-31
JZ good // if all bits are clear, number is positive and valid.
XOD DW#16#FFFF8000 // else, if all bits set, number is negative and valid
JZ good // If result is not zero, then at least one bad bit detected.

R #bValid // Validity check failed, reset vailid status
L W#16#0 // and for the hell of it, reset the output word to zero.
T #INT_Out
BE

good: S #bValid // Set conversion valid flag (Ok, assume it will be valid)
L #TmpDI // Result was zero, so move low word
AD DW#16#FFFF // mask off high word for hell of it
T #INT_Out // to ouput word,
BE



I use that to go from Reals to Int's, while safely preserving the sign. Without range checking, you could pass a real value of say 128,382, which would give unexpected results when converted to an integer.

Your milage may vary.
 

Similar Topics

Hello guys, I'm using SCL to create the control for my drive. I have a value in the OS (0-100%) what stands for the speed of the drive= setpoint...
Replies
12
Views
7,575
Is there anyway to take an RsLogix 5000 Ladder and auto convert it to Function Block, or any software that would automatically do it. even Ladder...
Replies
1
Views
7,500
Hello all, I'm currently working on a servo motor linear positioning system (ball screw). I'm all set up regarding communication between my HMI...
Replies
1
Views
115
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
8
Views
376
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,596
Back
Top Bottom