Scale an analogue value

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
I have an extremely dumb math question.

An analogue input gives me 0 to 27648 when operating in 0 to 20mA

In the program I want to scale into a mA value.

So, INPUT / 27648 gives me a range of 0 to 1, after that I make a new range by multiplying it with 20. Then I have the Value INPUT in mA in the program.

But, if u do this: INPUT / 1382,4, then u get the same.

27648 / 20mA gives me a usable factor.

Is there anyone who can explain me more, why 27648 / 20mA, from where it comes...


Tnx
 
Looks like you are making your own scaling function which is OK.
27648 / 20 = 1382.4 is correct, so dividing the input with 1382.4 gives you a mA value. But what are you trying to achieve ?
Normally you want to scale to engineering values, the current signal (mA) is only an intermediary value.

Depending on the PLC type, there is probably a scaling function available.
 
Use the following equations to calculate the scaled units:
Scaled value = (input value x rate) + offset

Rate
= (scaled max. – scaled min.) / (input max. – input min.)
Offset = scaled min. – (input min. x rate)
it is something like Y=MX+C
 
Hey

First of all, siemens has FC105 to scale something, but using a little calculation is much quicker.


I understand this:
Scaled value = (input value x rate) + offset

Rate
= (scaled max. – scaled min.) / (input max. – input min.)
Offset = scaled min. – (input min. x rate)
it is something like Y=MX+C


It's a good thing to use, tnx

What I asked is:

why is INPUT / 1382,4 = (INPUT / 27648) x 20. it really is a math confusion of me
 
I am guessing that you are using S7.
The 27648 is the typical max value for an analog input in S7.

An INT has a range of -32768 .. + 32767.
That Siemens has chosen +/-27648 to represent +/-20mA is so that some overrange is allowed. Do not count on that above 27648 that the analog value follows linearly. I think that you do not have 23.7mA at 32767 but some other overrange value.
 
Combo,

Would it help you if you could see inside FC105?

Here it is:-

Code:
FUNCTION "SCALE" : WORD
TITLE =SCALING VALUES
//
AUTHOR : SEA
FAMILY : CONVERT
NAME : SCALE
VERSION : 2.1
 
VAR_INPUT
IN : INT ; // input value to be scaled
HI_LIM : REAL ; // upper limit in engineering units
LO_LIM : REAL ; // lower limit in engineering units 
BIPOLAR : BOOL ; // 1=bipolar; 0=unipolar
END_VAR
VAR_OUTPUT
OUT : REAL ; // result of the scale conversion
END_VAR
VAR_TEMP
IN_REAL : REAL ; // input value as a REAL number
K1 : REAL ; // low limit for input value
K2 : REAL ; // high limit for input value
SPAN : REAL ; // HI_LIM - LO_LIM
TEMP1 : REAL ; // temporary result
END_VAR
BEGIN
NETWORK
TITLE =
//
// set K1 and K2 constants based upon BIPOLAR
//
	 SET ; // if(BIPOLAR=0)
	 A	 #BIPOLAR; // .
	 JC	EL01; // {
	 L	 0.000000e+000; // K1=0
	 T	 #K1; //	 .
	 JU	EI01; // } else {
EL01: L	 -2.764800e+004; // K1=-27648.0
	 T	 #K1; //	 .
EI01: NOP 0; // }
	 L	 2.764800e+004; // K2=+27648.0
	 T	 #K2; // .
//
// convert input (IN) to real
//
	 L	 #IN; // ACC1=IN
	 ITD ; // convert to double integer 
	 DTR ; // convert to real
	 T	 #IN_REAL; // IN_REAL-IN as a real
//
// determine SPAN = HI_LIM - LO_LIM
//
	 L	 #HI_LIM; // SPAN=HI_LIM-LO_LIM
	 L	 #LO_LIM; // .
	 -R	; // .
	 T	 #SPAN; // .
//
// If the input value is outside the K1 and K2 range, the output
// is clamped to the nearer of either the LO_LIM or the HI_LIM 
// and an error is logged. If the input value is exactly at a limit the
// output will be set to the computed limit with no error returned.
//	 changed 2/14/00 by ERI per RQ210693
	 L	 #IN_REAL; // if(IN_REAL<K1)
	 L	 #K1; // .
	 >=R ; // .
	 JC	EL02; // {
	 L	 8; // error
	 T	 #RET_VAL; //	 .
	 L	 #LO_LIM; //	 ACC1=LO_LIM
	 T	 #OUT; // OUT=ACC1
	 JU	FAIL; // error
EL02: POP ; // } else {
	 L	 #K2; // if(IN_REAL>K2)
	 <=R ; //	 .
	 JC	EI04; // {
	 L	 8; //	 error
	 T	 #RET_VAL; //	 .
	 L	 #HI_LIM; //	 ACC1=HI_LIM
	 T	 #OUT; //	 OUT=ACC1
	 JU	FAIL; //	 error
EI04: NOP 0; // }
	 NOP 0; // }
//
// scale the input
//
	 L	 #K2; // TEMP1=K2-K1
	 L	 #K1; // .
	 -R	; // .
	 T	 #TEMP1; // .
	 L	 #IN_REAL; // IN_REAL-K1
	 L	 #K1; // .
	 -R	; // .
	 L	 #TEMP1; // divide by TEMP1
	 /R	; // .
	 L	 #SPAN; // multiply by SPAN
	 *R	; // .
	 L	 #LO_LIM; // add LO_LIM
	 +R	; // .
	 T	 #OUT; // OUT=scale(IN_REAL)
//
// set BR bit : no error-set BR bit to 1; with error-set BR bit to 0.
//
	 L	 0; // return error code 0
	 T	 #RET_VAL; //
	 SET ; // RLO = 1 (NO ERROR)
	 JU	SVBR; // 
FAIL: CLR ; // RLO = 0 (ERROR)
SVBR: SAVE ; // BR = RLO
END_FUNCTION

Paul
 
Combo said:
I have an extremely dumb math question.

An analogue input gives me 0 to 27648 when operating in 0 to 20mA

In the program I want to scale into a mA value.

So, INPUT / 27648 gives me a range of 0 to 1, after that I make a new range by multiplying it with 20. Then I have the Value INPUT in mA in the program.

But, if u do this: INPUT / 1382,4, then u get the same.

27648 / 20mA gives me a usable factor.

Is there anyone who can explain me more, why 27648 / 20mA, from where it comes...


Tnx

Hello Combo

27648 counts in PLC register divided by 20 ma. equals to 1382.4 count per milliamp.
So if you divide (input counts/1382.4) you have determined the milliamp value at that time. It will be somewhere between 0 ma to 20 ma (the actual milliamps).
If you divide (input counts/27648) you have determined what percentage of the total counts (0 to 27648) is happening at that time. This will be some where between 0 and 1. Then if you multiply that times 20, it will give you the millamps at that time.

input counts/1382.4 = ma.

input counts/27648 = to a % of the total counts
% of the total counts X 20 = ma.
 
This is High School Algegra 1. You are talking about the linear equation for slope and intercept. It is expressed as:

Y=MX+B where Y is the vertical axix
X is the horizontal axis
M is the slope or gain; M = Y divided by X or the ratio of Y to X
B is the offset
 
Last edited:
Input Reading / 27648 (max reading) is proportional to

Resultant current / 20 ma (max current)

therefore

Input / 27648 = Resultant / 20

multiplying both sides by 20 gives

(Input / 27648) * 20 = Resultant

As DJM said - High School Algebra

Note: this easy method works because the low end of each scale is zero
 
I'll give general procedure that can be applied when ever there is need to scale one interval into another using linear function.
Suppose you have values in interval [x1, x2] and you want to convert it into interval [z1, z2] using linear transformation:
z = K*x+N. All you need to do is to determine koefficients K and N. Here's how:
x1 is mapped to z1 and x2 is mapped to z2. These values are sufficient to determine K and N.
z1 = K*x1+N
z2 = K*x2+N
If we subtract second equation from first, we get:
z1-z2 = K*x1-K*x2
From this point we can easily determine K:

K = (z1-z2)/(x1-x2);

When we know K, now it is easy to determine N. If we now just insert expression for K into either first or second equation we can obtain N.
For instance, if we insert K expression into first equation:
z1 = (z1-z2)*x1/(x1-x2)+N
this equivalent to this:
z1*(x1-x2) = x1*(z1-z2)+N*(x1-x2) =>
N*(x1-x2) = z1*x1-z1*x2 - z1*x1+z2*x1 =>
N*(x1-x2) = z2*x1-z1*x2 =>
Now finally...

N = (z2*x1-z1*x2)/(x1-x2)

Now when we know K and N, we can convert any number in interval [x1, x2] to corresponding number in [z1, z2] interval.

Example:
Scale numbers from interval[10, 20] to corresponding numbers in interval [0, 2].
Now, x1 = 10, x2 = 20, z1 = 0, z2 = 2.
Using obtained expressions for K and N we can get:
K = 0.2, N = -2.
So linear transformation is:
z = 0.2*x-2;
Now if following x values:

10 11 12 13 14 15 16 17 18 19 20

using transformations are scaled to following z values:

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

I hope this helps.
Cheers!
 
Last edited:

Similar Topics

Hello, I'm confused with Instruction called "SCP" with RSlogix. Never really had to use this one, till now. I need to control an Acid pump at a...
Replies
8
Views
1,789
the scale occasionally stops working and displays the message "no response from modbus" on the control screen . tunaylar - load line2
Replies
2
Views
124
Hi! I'm wondering if PLCs are used for small-scale production. I've got four machines doing different things with textiles, and I'm exploring the...
Replies
16
Views
1,302
I am having an issue writing a carriage return to my scale, I can manually push the print button the the scale and then read the buffer. The scale...
Replies
4
Views
1,088
Good afternoon. 1794-ie12 module available, channel set to 4...20 mA. According to the table from the manual, we get from 0 at 4mA to 30840 at...
Replies
5
Views
2,200
Back
Top Bottom