Scaling function

pauly

Member
Join Date
May 2002
Location
South Wales,U.k
Posts
244
I have written a scling block to scale real values in the PLC code to integers for use on analogue output blocks, I want the scaling block to scale -150.0 --- +150.0 to 0 --- 4096. But testing the block with -150 only delivers 2048 out.
The Scalefactor is =(OutMax-OutMin)/(InMax-InMin)
The output is then: Input*ScaleFactor
Do I need an offset in there?
 
if I understand your question, try a slope/rate/m of 13.65333_ and an offset/intercept/b of 2048 ...

are you sure about that output range? ... 0 to 4095 is more common ...
 
may be this function will helpful for you.




FUNCTION FC 44 : VOID
TITLE =scaling
//This function carries out the scaling by four point irrespective of quadrant
//and
//sign of gain.
AUTHOR : vovan
VERSION : 0.1


VAR_INPUT
IN_1_point : INT ; //first constant for unscalled value
IN_2_point : INT ; //second constant for unscalled value
OUT_1_point : INT ; //first constant for scalled value
OUT_2_point : INT ; //second constant for scalled value
IN_var : INT ; //unscalled input variable
END_VAR
VAR_OUTPUT
OUT_var : INT ; //scalled!
Err_bit : BOOL ; //error bit
END_VAR
VAR_TEMP
Divident : REAL ; // */
Divisor : REAL ; // /*
A : REAL ; //Gain
B : REAL ; //Bias
T_Real : REAL ; //temporary store of a value
IN_1_r : REAL ;
IN_2_r : REAL ;
OUT_1_r : REAL ;
OUT_2_r : REAL ;
END_VAR
BEGIN
NETWORK
TITLE =division by zero
//If both borders of unscalled variable are equal that will cause division by
//zero. Error bit is True.
L #IN_1_point;
L #IN_2_point;
==I ;
= #Err_bit;
JCN m001;
BEC ;
m001: NOP 0;
NETWORK
TITLE =converting of everything from Int to Real
//five variables
L #IN_1_point;
ITD ;
DTR ;
T #IN_1_r;
// -------------------
L #IN_2_point;
ITD ;
DTR ;
T #IN_2_r;
// ------------------
// ------------------
L #OUT_1_point;
ITD ;
DTR ;
T #OUT_1_r;
// ------------------
L #OUT_2_point;
ITD ;
DTR ;
T #OUT_2_r;
// ------------------
// ------------------
L #IN_var;
ITD ;
DTR ;
T #T_Real;
NETWORK
TITLE =
//The equation of a kind y=Aх+B is set by four points,thus
//
//A = (OUT_1 - OUT_2)/(IN_1 - IN_2)
//
//B = OUT_1 - A * IN_1
//or
//B = OUT_2 - A * IN_2
//
//OUT = A * IN + B
//
// calculation of Gain, ie "А"
L #OUT_1_r;
L #OUT_2_r;
-R ;
T #Divisor;
L #IN_1_r;
L #IN_2_r;
-R ;
T #Divident;
L #Divisor;
L #Divident;
/R ;
T #A;
// calculation of Bias, ie "В"
L #IN_1_r;
L #A;
*R ;
L #OUT_1_r;
TAK ;
-R ;
T #B;
// calculation of Out value, ie "y"
L #T_Real;
L #A;
*R ;
L #B;
+R ;
T #T_Real;
L #T_Real;
RND ;
T #OUT_var;
END_FUNCTION



 
Last edited:
ggg009.JPG
 

Similar Topics

Hi all, i am trying to scale a 0 - 1000 analogue input to a -10000 to 10000 output with 0-500 been -10000 to 0 and 501-1000 to 0-1000 is there...
Replies
7
Views
2,855
Hi All Omron Experts I need help to create a FB for Omron PLC CP1L-E Task: Detect and Monitor Oil Level in a Hyd. Tank Using Incorporated...
Replies
1
Views
1,724
Hi Friends, Please, who can tell me the Function Block used for scaling 4-20mA to say 0-200PSI in Mitsubishi GX Works3?
Replies
6
Views
7,240
Hello Experts, I am using Step 7 V5.5 Sp4 for my project. In my project, I was scaling 4-20mA signal to -180 to 180. As of now it sounds like a...
Replies
4
Views
1,702
Hello Experts, Need your advice on this. I am using Step7 V5.5 SP4 for my programming. I am using FC105 scaling function to scale 4-20 mA signal...
Replies
7
Views
2,263
Back
Top Bottom