Scale a value 4-20mA on a 0-20mA input (Siemens)

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
I'm not sure of a scaling I did. I have a underpressuresensor that measures between -1 and 0 bar. Given by the sensor in 4-20mA.
This goes into a 0-20mA analogue input on a frequency drive (so that we don't need to use a plc analogue input-card.

This is what I did to scale it:

Code:
 L	 #PCD_RECV3
 ITD   
 DTR   
 L	 3.276800e+003			   // INT waarde bij 4mA
 -R	
 L	 1.310720e+004
 /R								// Range 0..1
 L	 1.000000e+000
 -R								// Meetbereik -1..0 bar
 T	 #Onderdruk

So, Integervalue from drive is not 0-27648 like in a PLC, but 0-16384.

So 20mA = 16384. deviding 20 by 5 gives us 4mA, so 16384 / 5 = 3276,8 this is the value that stands for 4mA.
So the range is 16mA, not 20. 16384 - 3276,8 = 13107,2 (range in integervalue

So what I did is:

(Measured value (0-16384) - 3276,8 (4mA)) / 13107,2

Now I have the measurement scaled into 0..1 bar.

But it has to be -1..0 bar, so:

((Measured value (0-16384) - 3276,8 (4mA)) / 13107,2) -1




Did I scale it well ? I have my doubts, therefor this POST
 
I'm confused between the -1 to 0 sensor, 4-20mA, 0-20mA analog input on the drive, and where you get the drive as 0-16384.

However, linear scaling is simple algebra. Your 2nd paragraph seems flawed.

Combo said:
So 20mA = 16384. deviding 20 by 5 gives us 4mA, so 16384 / 5 = 3276,8 this is the value that stands for 4mA.
So the range is 16mA, not 20. 16384 - 3276,8 = 13107,2 (range in integervalue

The trick is to use your input ranges as x values and your output ranges as y values. So scaling a 4-20mA input to a -1 to 0 bar output would be fitting a line to the following points. (4, -1) and (20,0). You could plug in the values to y=mx+b and solve for m and b.

Or, m=(y2-y1)/(x2-x1) then plug in either set of x,y values to get b. You should plug in the other set to check your equation.

In that case I get y=(1/16)x-(5/4), where x is the 4-20mA signal and y is the output in bar. The range is valid from (4-20) and domain is valid from (-1 to 0).

You should be able to linearly scale between any inputs and outputs this way. A second opinion would be nice...
 
Combo - your scaling is correct although it can be re-written as follows to save a few intructions:

y=x/13107.2 - 1.25

Where x is the measured value 0 -16384, y is pressure in Bar

If x < 3276.8 then y = -1
If x > 16384 then y = 0

Edit: added image

ymxc.JPG
 
Last edited:
hey

Thanks very muchos. 1 thing I don't understand, is the C part, how do you come to the C formula ?



L D[AR2 said:
Combo - your scaling is correct although it can be re-written as follows to save a few intructions:

y=x/13107.2 - 1.25

Where x is the measured value 0 -16384, y is pressure in Bar

If x < 3276.8 then y = -1
If x > 16384 then y = 0

Edit: added image

ymxc.JPG
 
help!?!?

I feel like I'm taking crazy pills. The math is simple and the concepts are getting me. I can deal with the 16384 from the drive at 20mA. But on a 4-20 mA, how can you simply do 16384/5 to get that 3276.8? Wouldn't that only be true in a y=mx+c form if c=0? I agree that if 4 mA = 3276.8 and 20 mA = 16384, that your equation is correct.

Am I missing something basic? Please explain how 4mA translates to 3276.8.


L D[AR2 said:
If x < 3276.8 then y = -1
If x > 16384 then y = 0
 
surferb said:
I feel like I'm taking crazy pills. The math is simple and the concepts are getting me. I can deal with the 16384 from the drive at 20mA. But on a 4-20 mA, how can you simply do 16384/5 to get that 3276.8? Wouldn't that only be true in a y=mx+c form if c=0? I agree that if 4 mA = 3276.8 and 20 mA = 16384, that your equation is correct.

Am I missing something basic? Please explain how 4mA translates to 3276.8.

I am also having a problem with working out analogue to digital scaling but after reading this page it has helped a lot.

With reference to surferb's question. 20mA = 16384 is always going to be true as that is what the drive will say it can see when presented with 20mA. Since 0 - 20mA has to be a linear scale 16384/5 has to be what the drive will see when you give it 4mA as it has to be linear.

On another note. Does anyone have some code written for Siemens S7-200 that I could use for doing analogue scalling. I have tried doing it my self but I am not getting the right answers.

It would be great if you could post it to the forum so that I could have a read through.

JonnyDY2J
 
Thanks ABTech - I get it. The c is 0 since we're talking about a 0-20mA scale. The part about the 4-20mA sensor feeding into a 0-20mA drive was what was throwing me off.
 
yep

yep, indeed


surferb said:
Thanks ABTech - I get it. The c is 0 since we're talking about a 0-20mA scale. The part about the 4-20mA sensor feeding into a 0-20mA drive was what was throwing me off.
 
Math is easy, application was a bit tricky.

Forgot to answer your question.
re-arranging y = mx + c
gets, c = y - mx

At that point, he already solved for m. You can plug either set of points (x, y) to get c. He omitted showing that he was using (16384, 0) and chicken scratched the plugging of 16384 for x.

Combo said:
Thanks very muchos. 1 thing I don't understand, is the C part, how do you come to the C formula ?
 
Ugh, I was referring to you not formally writing everything out/using formal notation (for that line only). Maybe a bad term since it normally implies sloppy and your work was neat.

The c=-1/13107.2 * x|16384
 
Yes, I see what you mean when I look back at my hand written solution. I mentally re-arranged y = mx + c to solve for c when y = 0 and substituted the values in.

I also meant to comment on your y = mx + b

Is this common across the states as in the UK we are taught using

y = mx + c
 
Yes, that's what I was saying. We use C as a constant but b for the basic equation of a line - c makes more sense.

L D[AR2 said:
Yes, I see what you mean when I look back at my hand written solution. I mentally re-arranged y = mx + c to solve for c when y = 0 and substituted the values in.

I also meant to comment on your y = mx + b

Is this common across the states as in the UK we are taught using

y = mx + c
 
What I never understood was 27648, where does that number come from?

16384 is easy, 2 to the power of 14, standard resolution for many analog devices.

Regardles of how you look at if 16384 is the input values then its divided by 20 then times 4 to get the value = to 4ma.

Another way to do that since many KNOW off the top of their head 20/5 = 4 is divide 16384 by 5, same result.

WAIT, I think the 27648 was a misprint (error), 2^15 is 32768, close enough for me.
 

Similar Topics

Hi! I'm trying to obtain a scaled value for a distance of 1090 units (10nths of 1")read by a distance laser in the range of 4-20ma. I want to use...
Replies
10
Views
2,869
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...
Replies
11
Views
4,395
the scale occasionally stops working and displays the message "no response from modbus" on the control screen . tunaylar - load line2
Replies
2
Views
144
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,356
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,127
Back
Top Bottom