Seimens Scale with Parameters ?

GTX

Member
Join Date
Dec 2003
Posts
36
Hi

I have been programming Allen Bradley Micrologix 1500 PLC's for about a year now and have been using the function "Scale With Parameters" a lot. Well now I am starting a Siemens S7 PLC program and I was wondering if the Seimens PLC's have a "Scale With Parameters" or similar function ?

Thanks for any help !!

Barry
 
In the Standard library under TI-S7 Converting Blocks you can find FC105 SCALE . It will generate a scaled REAL value from the raw INT value you provide.

Personally, I ended up writing my own scaling function that resembles the AB SCP function a bit more.
 
Heres the code :)

Paste this in the Sources section of a block in STEP7:

FUNCTION "SCALE_ANALOG_SIMPLE" : VOID
TITLE =Scaling of values InPMin..InPMax / SclMin..SclMaxOutput INT
AUTHOR : JMP
FAMILY : STD
VERSION : 0.1


VAR_INPUT
iInput : INT ; //Raw input value.
iInpMIN : INT ; //Input minimum definition point.
iInpMAX : INT ; //Input maximum definition point.
iSclMIN : INT ; //Scaled minimum definition point.
iSclMAX : INT ; //Scaled maximum definition point.
END_VAR
VAR_OUTPUT
iOutput : INT ; //Scaled Output
END_VAR
VAR_TEMP
Dummy : BOOL ;
rInput : REAL ;
rInpMIN : REAL ;
rInpMAX : REAL ;
rSclMIN : REAL ;
rSclMAX : REAL ;
rRate : REAL ; //Rate of conversion
rOffset : REAL ; //Offset of conversion.
rDiffInp : REAL ;
rDiffScl : REAL ;
END_VAR
BEGIN
NETWORK
TITLE =Convert input values from INT to REAL

L #iInput;
ITD ;
DTR ;
T #rInput;
L #iInpMIN;
ITD ;
DTR ;
T #rInpMIN;
L #iInpMAX;
ITD ;
DTR ;
T #rInpMAX;
L #iSclMIN;
ITD ;
DTR ;
T #rSclMIN;
L #iSclMAX;
ITD ;
DTR ;
T #rSclMAX;
NETWORK
TITLE =Calculate the Differences for conversion

L #rSclMAX;
L #rSclMIN;
-R ;
T #rDiffScl;
L #rInpMAX;
L #rInpMIN;
-R ;
T #rDiffInp;
NETWORK
TITLE =Trap error: Input values are same.

L #rDiffInp;
L 0;
==R ;
BEC ;
NETWORK
TITLE =Calculate the RATE for conversion


L #rDiffScl;
L #rDiffInp;
/R ;
T #rRate;
NETWORK
TITLE =Calculate the OFFSET for conversion

L #rInpMIN;
L #rRate;
*R ;
L #rSclMIN;
TAK ;
-R ;
T #rOffset;
NETWORK
TITLE =Calculate scaled value (INT)

L #rInput;
L #rRate;
*R ;
L #rOffset;
+R ;
RND ;
T #iOutput;
END_FUNCTION

 
Thanks JesperMP

Do you have an example of how to use the FC105 Scale Convert function ?

Here is what i am trying to do:

I have the PLC's analog input hooked up to a device that outputs a voltage that ranges from 0 - 1 volt. Now, this voltage represents a percentage, for example:

0.0 volts = 0%
0.5 volts = 12.5%
1.0 volt = 25%.

What i need to do is take that incoming 0 - 1 voltage and turn it into a percentage ranging from 0% - 25% then save that percentage into a Memory word file so i can display it on a HMI touch screen.

Thanks
 
Last edited:
Using FC105. Assign your inout word, like PIW256 to the IN handle. Put 250.0 on the HI_LIM. 0.0 on LOW_LIM and an "Always_OFF" bit on BIPOLAR, some dummy word on RET_VAL and MD0 on the OUT handle.
 
Tip:
In step7 manager, highlight FC105 and hit the F1 key - a help for the particular library function will pop up. The usage of FC105 looks fairly straightforward.

The code that I provided is for an FC that works exactly as the SCP instruction.
 
Last edited:
Rolling your own

Regardless of PLC brand, it's possible to make a convert/scale-function as long there is MUL, DIV, SUB and ADD instructions.

This is the equation Jesper based his fuction on:

x1,y1 = known point1
x2,y2 = known point2
x = input raw for scaling
y = output, scaled


(y2 - y1)
y = --------- * (x - x1) + y1
(x2 - x1)


More can be read here in this old thread about this subject: http://www.plcs.net/dcforum/DCForumID1/2755.html

Only a remark: Without floating-point math, try doing all MUL before the DIV. (as long as the result of the MUL isn't to large....)
 
Here is the source code for a scaling routine that gives an integer answer and allows allows the decimal place to be moved in the process.
Code:
FUNCTION "RtoI_Dec" : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
  RealIn : REAL ;   
  Dec : INT ;   
END_VAR
VAR_OUTPUT
  IntOut : INT ;    
END_VAR
VAR_TEMP
  i : INT ; 
  MulVal : REAL ;   
  TempReal : REAL ; 
END_VAR
BEGIN
NETWORK
TITLE =

      SET   ; 
      SAVE  ; 

      L     #RealIn; //Read Input
      T     #TempReal; // Save In Storage Area
      L     #Dec; // # Decimal Places To Move  
      ITD   ; // Make Into A Double For Comparison
      L     0; // Add Zero
      +D    ; // To Setup Compare For Jumps
      JP    Rt; // Set Multiplier For Move Right 
      JM    Lft; // Set Multiplier For Move Left
      JZ    Cvt; // Skip Move, Jump To Convert

Lft:  L     -1; // Multiply Places By -1
      *D    ; // To Make Positive Value
      T     #i; // Store Places To Move
      L     1.000000e-001; // Multiply By 0.1 (Move Left)
      T     #MulVal; // Save Multiplier  
      L     #i; // Return Places Needed To Move (Counter)
      JU    L1; // Start Move

Rt:   L     1.000000e+001; // Default Multiply By 10 (Move Right)
      T     #MulVal; // Save Multiplier
      L     #Dec; 

L1:   T     #i; // Save As Loop Count   
      L     #TempReal; // Real Value To Make INT    
      L     #MulVal; // Multiply To Move Decimal 1 Place
      *R    ; 
      T     #TempReal; // Save New Value
      L     #i; // Load Loop Count
      LOOP  L1; // Loop                       

Cvt:  L     #TempReal; // Load Final Answer
      RND   ; // Convert to INT
      T     #IntOut; // Thank you bye

      SAVE  ; 
      BEC   ; 
END_FUNCTION

FUNCTION "ScaleToINT" : VOID
TITLE =
VERSION : 0.0


VAR_INPUT
  MaxIN : REAL ;    
  MinIn : REAL ;    
  MaxOut : REAL ;   
  MinOut : REAL ;   
  InputValue : INT ;    
  Dec : INT ;   
END_VAR
VAR_OUTPUT
  ScaledINT : INT ; 
END_VAR
VAR_TEMP
  input_range : REAL ;  
  output_range : REAL ; 
  input_value : REAL ;  
  ScaledREal : REAL ;   
END_VAR
BEGIN
NETWORK
TITLE =STL network
//compiled by SCL compiler version:  SCL V5.1 (R5.1.6.6)
      SET   ; 
      SAVE  ; 
      =     L     16.1; 
      L     #MaxIN; 
      L     #MinIn; 
      -R    ; 
      T     #input_range; 
      L     #MaxOut; 
      L     #MinOut; 
      -R    ; 
      T     #output_range; 
      L     #InputValue; 
      ITD   ; 
      DTR   ; 
      T     #input_value; 
      L     #input_value; 
      L     #MinIn; 
      -R    ; 
      L     #output_range; 
      *R    ; 
      L     #input_range; 
      /R    ; 
      L     #MinOut; 
      +R    ; 
      T     #ScaledREal; 
NETWORK
TITLE =

      CALL "RtoI_Dec" (
           RealIn                   := #ScaledREal,
           Dec                      := #Dec,
           IntOut                   := #ScaledINT);
      NOP   0; 
NETWORK
TITLE =

      SAVE  ; 
      BE    ; 

END_FUNCTION
 
I know the following is a old post, but been trying to learn more about how to scale with siemens and have searched the help and just can not figure out how to paste this in a block and create the block. could someone please tell me what i am overlooking. Thanks


Paste this in the Sources section of a block in STEP7:

FUNCTION "SCALE_ANALOG_SIMPLE" : VOID
TITLE =Scaling of values InPMin..InPMax / SclMin..SclMaxOutput INT
AUTHOR : JMP
FAMILY : STD
VERSION : 0.1


VAR_INPUT
iInput : INT ; //Raw input value.
iInpMIN : INT ; //Input minimum definition point.
iInpMAX : INT ; //Input maximum definition point.
iSclMIN : INT ; //Scaled minimum definition point.
iSclMAX : INT ; //Scaled maximum definition point.
END_VAR
VAR_OUTPUT
iOutput : INT ; //Scaled Output
END_VAR
VAR_TEMP
Dummy : BOOL ;
rInput : REAL ;
rInpMIN : REAL ;
rInpMAX : REAL ;
rSclMIN : REAL ;
rSclMAX : REAL ;
rRate : REAL ; //Rate of conversion
rOffset : REAL ; //Offset of conversion.
rDiffInp : REAL ;
rDiffScl : REAL ;
END_VAR
BEGIN
NETWORK
TITLE =Convert input values from INT to REAL

L #iInput;
ITD ;
DTR ;
T #rInput;
L #iInpMIN;
ITD ;
DTR ;
T #rInpMIN;
L #iInpMAX;
ITD ;
DTR ;
T #rInpMAX;
L #iSclMIN;
ITD ;
DTR ;
T #rSclMIN;
L #iSclMAX;
ITD ;
DTR ;
T #rSclMAX;
NETWORK
TITLE =Calculate the Differences for conversion

L #rSclMAX;
L #rSclMIN;
-R ;
T #rDiffScl;
L #rInpMAX;
L #rInpMIN;
-R ;
T #rDiffInp;
NETWORK
TITLE =Trap error: Input values are same.

L #rDiffInp;
L 0;
==R ;
BEC ;
NETWORK
TITLE =Calculate the RATE for conversion


L #rDiffScl;
L #rDiffInp;
/R ;
T #rRate;
NETWORK
TITLE =Calculate the OFFSET for conversion

L #rInpMIN;
L #rRate;
*R ;
L #rSclMIN;
TAK ;
-R ;
T #rOffset;
NETWORK
TITLE =Calculate scaled value (INT)

L #rInput;
L #rRate;
*R ;
L #rOffset;
+R ;
RND ;
T #iOutput;
END_FUNCTION

 
In Simatic Manager you have a Blocks folder and a Sources folder.
In the Sources folder create new source, copy/paste this into the new source and compile it.

Do make sure you specify an unused FC as the compile with replace any existing Block without asking permission.
 
Thanks,
I did that, now for another question, i compiled it, then how would you use it in a program?
Hate to ask so many questions, but very confused
 

Similar Topics

opening up a copy of my HMI program I can go to where the passwords are created but they are all asterisks. How can I view what is there? I see...
Replies
4
Views
1,098
I have installed ver 16 of tia portal and I am running in the 21 days grace period. My question is this, is it fully functional during that 21...
Replies
8
Views
3,061
Hi; In our corrugator plant, there are one Corrugator and five Flexo graphic printing machines. One of them is a BOBST brand French made...
Replies
1
Views
1,912
We have these in our shuttles. The IP Address is stored on the SD card for the unit. We had a card go bad and I am trying to copy another card...
Replies
3
Views
1,149
Good morning, experts! I have a Siemens PLC and IO that I need to cross to Rockwell, and I have zero experience with the Siemens line of products...
Replies
2
Views
1,547
Back
Top Bottom