Step 7 300 INT to Real Convertion

Hal9000

Member
Join Date
Jun 2010
Location
London
Posts
140
Thanks eveyone for all your help!!

I now have another puzzle to solve...Converting back the other way. i.e. 2x INT's to a Real.

Assuming

DB143 DBW80 is the Integer
and
DB143 DBW82 is the fraction part

I need the result to show the result (as a real) to 1dp only.

The problem is that some fraction parts contain 3 numbers and other 4 numbers. I must always use the value on the left side.

See DB143 below as a reference.

DB143.DBW80 INT 83 MOTOR POWER (INTEGER)
DB143.DBW82 INT 9764 MOTOR POWER (FRACTION)

The real result should equal 83.9


DB143.DBW84 INT 102 MOTOR TEMPERATURE (INTEGER)
DB143.DBW86 INT 883 MOTOR TEMPERATURE (FRACTION)

The real result should equal 102.8

I have over 200 values to map, ideally I need a function where I need to only add 3 x parameters to the FC. i.e. integer(in), Fraction(in) and real(out)
I now have another puzzle to solve...Converting back the other way. i.e. 2x INT's to a Real.

Basiaclly

DB143 DBW80 is the Integer
and
DB143 DBW82 is the fraction part

I need the result to show the result (as a real) to 1dp only.

The problem is that some fraction parts (sent to me via modbus) contain 3 numbers and other 4 numbers. I must always use the value on the left side.

See DB143 below as a reference.

DB143.DBW80 INT 83 MOTOR POWER (INTEGER)
DB143.DBW82 INT 9764 MOTOR POWER (FRACTION)
The real result should equal 83.9

DB143.DBW84 INT 102 MOTOR TEMPERATURE (INTEGER)
DB143.DBW86 INT 883 MOTOR TEMPERATURE (FRACTION)
The real result should equal 102.8

I have over 200 values to map, ideally I need a function where I need to only add 3 x parameters to the FC. i.e. integer(in), Fraction(in) and real(out)
 
Hi,

I attached the image and the STL source code.

immaginec.png


Code:
FUNCTION FC 7 : BOOL
TITLE =
VERSION : 0.1

VAR_INPUT
  INTEGER : INT ; 
  FRACTION : INT ; 
END_VAR
VAR_OUTPUT
  _REAL : REAL ; 
END_VAR
VAR_TEMP
  Buffer_INTEGER : REAL ; 
END_VAR
BEGIN
NETWORK
TITLE =
//Extract INTEGER Side
      L     #INTEGER; 
      ITD   ; 
      DTR   ; 
      T     #Buffer_INTEGER; 
//Check if FRACTION Side > 4 or < 3 decimal point, if affermative set error bit RET_VAL
//and exit function (Store the previous correct result in REAL data)
      O(    ; 
      L     #FRACTION; 
      L     10000; 
      >=I   ; 
      )     ; 
      O(    ; 
      L     #FRACTION; 
      L     100; 
      <I    ; 
      )     ; 
      =     #RET_VAL; 
      JC    EXIT; 
//Check if Fraction Side > 3 decimal point, if affermative Jumo to label M002
      L     #FRACTION; 
      L     1000; 
      >=I   ; //if negative mean Fraction side= 2 decimal point
      JC    M002; 
      TAK   ; 
      L     100; 
      /I    ; //extract Fraction side only one decimal point
      JU    M003; 
M002: L     #FRACTION; 
      L     1000; 
      /I    ; //extract Fraction side only one decimal poin
M003: ITD   ; 
      DTR   ; 
      L     1.000000e+001; 
      /R    ; 
      L     #Buffer_INTEGER; 
      +R    ; 
      T     #_REAL; //Sum of FRACTION and INTEGER
      SET   ; 
      SAVE  ; 
      BEU   ; 
EXIT: CLR   ; 
      SAVE  ; 
NETWORK
TITLE =
 

NETWORK
TITLE =
 
END_FUNCTION
 
I must always use the value on the left side.

See DB143 below as a reference.

DB143.DBW80 INT 83 MOTOR POWER (INTEGER)
DB143.DBW82 INT 9764 MOTOR POWER (FRACTION)

The real result should equal 83.9

Conventionally 83.9764 would be shown as 84.0 to 1 d.p.

Why do you wish to ignore the 0.0764 ?
 
Hi,

I attached the image and the STL source code.

If the fraction is zero (surely this is a valid condition), your function does not write to the output parameter _REAL

With functions, you must always write to the output parameters.
 
Hi,

If the fraction is zero (surely this is a valid condition), your function does not write to the output parameter _REAL

L D[AR2,P#0.0] you're right.

I make some modification... inserted a new comparing instruction to know if FRACTION = 0.

This function has too big concerning the number of instruction used.
So I'm pratically sure is possible to find a best way to develop the code using and adding some instructions for example in the KalleOlsen code.
I'm moving my first step in STL and trying to learn the SCL

Code:
FUNCTION FC 7 : BOOL
TITLE =
VERSION : 0.1

VAR_INPUT
  INTEGER : INT ; 
  FRACTION : INT ; 
END_VAR
VAR_OUTPUT
  _REAL : REAL ; 
END_VAR
VAR_TEMP
  Buffer_INTEGER : REAL ; 
END_VAR
BEGIN
NETWORK
TITLE =
//Extract INTEGER Side
      L     #INTEGER; 
      ITD   ; 
      DTR   ; 
      T     #Buffer_INTEGER; 
      T     #_REAL; 
//Check if FRACTION Side = 0 if affermative go to label EXIT and routine exit
      L     #FRACTION; 
      L     0; 
      ==I   ; 
      SPB   EXIT; 
//Check if FRACTION Side > 4 or < 3 decimal point, if affermative set error bit RET_VAL
//and exit function (Store the previous correct result in REAL data)
      O(    ; 
      L     #FRACTION; 
      L     10000; 
      >=I   ; 
      )     ; 
      O(    ; 
      L     #FRACTION; 
      L     100; 
      <I    ; 
      )     ; 
      =     #RET_VAL; 
      SPB   EXIT; 
//Check if Fraction Side > 3 decimal point, if affermative Jumo to label M002
      L     #FRACTION; 
      L     1000; 
      >=I   ; //if negative mean Fraction side= 2 decimal point
      SPB   M002; 
      TAK   ; 
      L     100; 
      /I    ; //extract Fraction side only one decimal point
      SPA   M003; 
M002: L     #FRACTION; 
      L     1000; 
      /I    ; //extract Fraction side only one decimal poin
M003: ITD   ; 
      DTR   ; 
      L     1.000000e+001; 
      /R    ; 
      L     #Buffer_INTEGER; 
      +R    ; 
      T     #_REAL; //Sum of FRACTION and INTEGER
      SET   ; 
      SAVE  ; 
      BEA   ; 
EXIT: CLR   ; 
      SAVE  ; 
NETWORK
TITLE =
 

NETWORK
TITLE =
 
END_FUNCTION
 
I cannot understand how you can convey the value 123.0123 for example.
If you recieve a fraction part with a value of "123", how do you know that it means .123 or .0123 ?

And if you get a value of "12" does it mean .12, .012 or .0012 ?

Somehow, the number of decimals in the fraction part MUST be implied.

I am also pussled as to why you want to round to one decimal, as LD already asked
"Why do you wish to ignore the 0.0764 ? ".
 
Last edited:
Also does both fraction part and integer part carry sign? Altough, point that Jesper pointed out is one very big one. Care to elaborate device make and model that is interfaced like this (or is it custom)? Then there is also this thing about 0,9 to -0,9 if fraction part does not carry sign, you have no way of knowing if 0 int part + 123 fract part is positive or negative. If values can be only positive this is ofc no issue.
 
Last edited:
DB143.DBW80 INT 83 MOTOR POWER (INTEGER)
DB143.DBW82 INT 9764 MOTOR POWER (FRACTION)
The real result should equal 83.9
Do you really want to discard the .0764 ?
The rounding of 83.9764 to one decimal gives 84.0, not 83.9.

DB143.DBW84 INT 102 MOTOR TEMPERATURE (INTEGER)
DB143.DBW86 INT 883 MOTOR TEMPERATURE (FRACTION)
The real result should equal 102.8
Do you really want to discard the .083 ?
The rounding of 102.883 to one decimal gives 102.9, not 102.8.
 
I have received more information from the equipment manufacturer;

a fraction of 345 would be 0.0345
a fraction of 3456 would be 0.3456

Sorry for the confusion
 
ok, so it IS always four digits.

Code:
FUNCTION CombToReal : VOID
VAR_INPUT            
    iInt, iFrac: INT;    
END_VAR
VAR_OUTPUT
    rOut : REAL;
END_VAR

BEGIN

L iInt;
ITD;
DTR;
LAR1;
L iFrac;
L L#1000;
/D;
DTR;
L 10.0;
/R;
TAR1;
+R;
T rOut;

SET;
SAVE;

END_FUNCTION
This ignores all but first digit of fraction part, I dont understand why would u ever want to ignore that 0,0999. But it is made as you requested. Only for positive values.

PS. Kalle Olsen what editor you are using. I atleast did not find syntax coloring with "normal" stl editor. Sources i get syntax painted but not "normal". Would be nice.
 
Last edited:
Sorry there was left two unnecessary instructions left from playing around

Code:
FUNCTION CombToReal : VOID
VAR_INPUT            
    iInt, iFrac: INT;    
END_VAR
VAR_OUTPUT
    rOut : REAL;
END_VAR

BEGIN

L iFrac;
L L#1000;
/D;
DTR;
L 10.0;
/R;
L iInt;
DTR;
+R;
T rOut;

SET;
SAVE;

END_FUNCTION
 

Similar Topics

Hello everyone I'm new here and was hoping someone can help me out. I have a pneumatic punching/ bending machine that broke down running on a...
Replies
39
Views
5,182
Hi, I have a 315-2 PN/DP CPU. It was programmed in Step 7 V5.5. Then a colleague programmed it in TIA Portal V13 for a test. Now I want to...
Replies
6
Views
2,279
Hi All, I am new to Siemens, and trying to implement a logic state below. Have 5 valves to open for certain time in Automatic and Manual. I got...
Replies
5
Views
2,714
Dear Experts. I have one project using HMI Ktp 1500 comfort and S7-300 CPU 315-2DP. The HMI KTP is using Software TIA porttal for programming, and...
Replies
2
Views
2,033
IS it possible to write this on a better way: L #db_Num2 L 121 ==I JNB _02 CALL "CONT_C" , "DB_reg_igla1"...
Replies
3
Views
2,628
Back
Top Bottom