Differential Pressure Transducer Scaling

joe7514

Member
Join Date
Aug 2021
Location
Tennessee
Posts
3
I am updating controls on a leak tester, from a SLC 5/02 to Compact Logix. The SLC used a DDV instruction to help scale a differential pressure transducer. I will have to scale in Compact Logix myself. It's a 4 - 20ma transducer. At 4 ma, I need -.500 psi. At 12 ma, 0 psi. and 20 ma, .500 psi. Would someone here be kind enough to me how to do this using a CPT instruction? I'm just a Tech. with a small company, without engineering support. TIA
 
For CompactLogix, I typically use an Add-On Instruction (AOI) that I found either on this forum or the Rockwell website that functions the same as an SCL (scale) or SCP (scale with parameters) instruction. This lets you put in the Input Minimum and Input Maximum in raw data counts, in my case 4000 for 4mA and 20000 for 20mA, and then you can put in whatever number you want for your Scaled Minimum and Scaled Maximum.

The internal logic of the AOI is just 3 CPT instructions:

lrWjSkm.jpg


You will need to adjust this based on how your analog channels are configured. For example, mine are configured with an Input Range of "4mA to 20mA", with a Filter of 60Hz, and the Data Format is "Engineering Units". Setting it to Engineering Units will make it read 4000 and 20000, which makes it easier to scale in my opinion.

ControlLogix lets you set the scaling in the card configuration, i.e. 4mA = 20psi, 20ma = 300psi, but the CompactLogix doesn't have that unfortunately.

EDIT: If I were going to just use a CPT instruction, I suppose the Expression would be as follows (replace Local:1:I.Ch1Data with whatever address your analog input is using):

ScaledValue = (0.0000625*Local:1:I.Ch1Data) - 0.75

This uses the following values for the Slope and Offset:

Slope = [0.500 - (-0.500)]/[20000 - 4000] = 1/16000 = 0.0000625
Offset = -0.500 - (4000 * 0.0000625) = -0.75

For example, if your analog input is at 20000 (or 20mA), you get the following:

ScaledValue = (0.0000625*20000) - 0.75
ScaledValue = (1.25) - 0.75
ScaledValue = 0.500
 
Last edited:
Multiply by unity.

Search the forum with the terms "analog digital scaling."

See also this: http://www.plctalk.net/qanda/showthread.php?t=69986

TL;DR


The input module will convert the analog signal (electrical current, 4-20mA), to a raw digital value in the PLC, typically a signed 16-bit integer. In that conversion, for example, an analog input signal of 4mA will become a digital value of 51 in the PLC, and an analog input signal of 20mA will become a raw digital value of 255 in the PLC. Your system will be different, but the same principles apply: in that case the formula would be summat like
engineering_value = (raw_value / 204) - 0.75,


or even
engineering_value = (raw_value - 153) / 204,

where 204 = 255 - 51.

But seriously dude, you need a sense of proportion.
 
Just for reference, this is literally just y=mx+b, which I've become quite familiar with dealing with various PLC platforms that don't let you scale the signal at the card.

y = scaled value
m = slope: (scaled max - scaled min)/(input max - input min)
x = unscaled value (the analog input)
b = offset: scaled min - (input min*slope) ... this is almost always -25% of your measurement range, so in your case your measurement range is 1.000psi (from -0.5psi to 0.5psi), and your offset ends up being -0.25. If your range was 40psi, your offset would end up being -10.

It's always important to know what the input resolution and corresponding raw data count will be for whatever PLC or analog input card that you're using. For example, I believe that one of the MicroLogix 1100 analog input cards (can't recall which off the top of my head) has a 15-bit resolution for 0-21mA, meaning that 0mA is 0 and 21mA is 32767. This means that 4mA is 6241 and 20mA is 31207. You can probably see now why being able to change the configuration to give you 4000 at 4mA and 20000 at 20mA is very useful.

EDIT: Just for an example with different numbers, I had one project where 4-20mA was 0-20" of water, and had to scale it as follows:

y = mx+b
y = ([20-0]/[20000-4000])*Local:1:Ch1Data + (0-[4000*0.00125])
y = (0.00125*Local:1:Ch1Data) - 5

So if we were measuring 12mA (12000), it would evaluate as follows:

y = (0.00125*12000) - 5
y = (15) - 5
y = 10"
 
Last edited:
Even with scaling at the card, I still use an SCP.

It's an easier window to what is going on and easier to make changes on the fly IMO
 
Even with scaling at the card, I still use an SCP.

It's an easier window to what is going on and easier to make changes on the fly IMO

This is true, it does make it more intuitive as to what’s going on regarding the scaling.
 
...I'm just a Tech. with a small company, without engineering support. ...


The topic of scaling, as some on this forum have already suffered, is a personal passion of mine.

TL;DR

@joe7514,

My dad was also "just a tech" (automtive and diesel technology, LIATI, Farmingdale, Long Island, 1952) at GE Large Steam Turbine, in Schenectady, NY ca. the early 1950s, and he was eventually known to stand equal to the best turbine test engineers in that company, and possibly in the world.

Apart from a stubborn attention to detail, much of the secret of his success, and to 90%, perhaps 95%, of engineering, wass this: multiplying by 1.

You really need to learn this, and not just learn it, you need to know it in your bones.

The remaining 5-10% is looking up/estimating/deriving the value of 1. If you learn to do that, you may become the de facto engineering department of your company.

Because if you are a "tech," but you apparently do not know this*, then you need to have a frank conversation with your former teachers about why they left you so unprepared.

* Otherwise you would not be asking the question in the OP of this thread, you would be explaining it to someone else.

Let's start with a simple example. If someone tells you a part is 0.57 metres (m) in length, and they want to know its length in millimetres (mm), you may already know that the answer is 570mm. You got than answer by multiplying 0.57 by 1000. But where does that factor of 1000 come from? I am glad you asked ;) ...

We know, from school or Google or SI fanatics, that 1m in length is the equivalent to 1000mm in length. Put another way, we can say
Code:
1000mm ≡ 1m
If we treat that as an equation, we could divide both sides by [1m]:
Code:
1000mm   1m
------ ≡ --
  1m     1m
We can do that because, if we have two things (quantities) that are equivalent, and we perform the same operation on each, in this case divide them both by the same thing, then the two results of that operation will also be equivalent.
Sidebar

For example, say the exchange rate from Euros to US dollars is 1.14, or
Code:
1.14USD ≡ 1.00EUR
If we divide both quantities by two, we get
Code:
1.14USD   1.00EUR
------- ≡ -------
   2         2

0.57USD ≡ 0.50EUR
And so we know that fifty-seven cents (US) is the equivalent of half a Euro at that exchange rate.
Returning to our length example,
Code:
1000mm   1m
------ ≡ --
  1m     1m
We see that the right-hand side of the equivalence is 1m divided by itself. Anything divided by itself is 1, so let's replace that 1m/1m ratio with 1:
Code:
1000mm
------ ≡ 1
  1m
We can also make the division calculation using the numbers 1000 and 1, and save the unit ratio on the left:
Code:
     mm
1000 -- ≡ 1
     m

1 ≡ 1000 mm/m
Now we have a rationale for multiplying the length of 0.57m by 1000, because it is not merely some arbitrary value of 1000 that we blindly pulled from Google, we now understand it to be 1000 mm/m, and it is equivalent to 1. And the multiplicative identity property states that when you multiply a quantity by 1, you get that same original quantity. In this case, we multiply 0.57m by 1 i.e. by 1000mm/m:
Code:
                           mm                      mm       [COLOR=Blue][B]m[/B][/COLOR] mm
0.57 m * 1 = 0.57 m * 1000 --  = (0.57 * 1000) m * -- = 570 ----
                           m                       m         [COLOR=blue][B]m[/B][/COLOR]
The blue [m]'s in the numerator and denominator "cancel (anything divided by itself is 1),: and we are left with 570mm, which is equivalent to 0.57m, the original quantity, because although we multiplied by 1000 numerically, we were instead multiplying by 1 (=1000mm/m) conceptually.

Carrying that concept to the query posed in the OP of this thread, see the following image:

  • The top-left plot describes the relationship of the input pressure (PSI) and output current (mA) of the transducer/sensor.
    • Start with a pressure on the horizontal axis, go up vertically until you hit the brown line, then go horizontally to the vertical axis to get the current (mA) corresponding to that pressure.
  • The top-right plot describes the relationship of the input current (mA) and the output digital Data Number (DN) of the PLC's analog input module (with the caveat the the OP's module will not use the range 51-255DN).
    • Start with a current (mA) from the top-left plot on the vertical axis, go right until you hit the blue line, the go down vertically to the horizontal axis to the the DN corresponding to that DN, and by implication the DN corresponding to the pressure from the top-left plot.
    • You can also run this backwards, from DN on the horizontal axis on the top-right plot up to the blue line, then horizonatlly to mA on the vertical axis, then over to the top-left plot and the brown line, then down vertically to the horizontal axis to get PSI.
  • The red line shows the conversion path for a pressure of +0.25PSI, to 16mA from the transducer and into the analog input module, and finally to 204DN inside the PLC.
  • The bottom two sketches remove all of the window dressing of the plots and show the linear relationship using similar triangles: the ratios of the legs of any triangle representing the linear relationships, from PSI to mA and from mA to DN, are constant.
mulunity00.png
That is the graphical representation of the two-step process that converts an analog pressure in the range [-0.500:+0.500] PSI; the first stop converts it to an analog current in a second equivalent range [4:20] mA, which is the signal output by the transducer/sensor; the second step converts that analog current signal to a digital Data Number (DN) in a third equivalent range [51:255] DN value in the PLC, which digital value is the output of the A/D (Analog-to-Digital) converter of the Analog Input Module of the PLC.

Here "equivalent" means that a analog pressure of -0.500PSI input to the transducer is equivalent to a tranducer/sensor output analog current signal of 4mA, and an analog current signal of 4mA input to the PLC analog input module is equivalent to a digital DN of 51 output from that module; also equivalent are the upper limits of the ranges i.e. +0.500PSI ≡ 20mA ≡ 255DN.

A small twist was added in that the bottom of all of those ranges (-0.5PSI; 4mA; 51DN) is not zero, but that would be the same as re-phrasing our length example above by saying "an object is 0.57m past the end of a 1000mm-long stick, where the beginning of the stick is against the wall of a building; how far is the object from that wall?" Obviously the answer is 1570mm i.e. [1000mm from the wall to the end of the stick, plus (0.57m * 1000mm/m) = 570mm from the end of the stick to the object] (assuming the object is in line with the stick centerline, for those following pedantically ;)).

In the same way in the current thread, we solve the problem by making all of the measurement relative to the bottom of the range. An as yet unspoken assumption is that the relationships, between pressure and current and between current and DN, are linear; this is shown in the image above by the plots of the relationships being a the brown and blue lines.

We have two values, both equivalent to 1: 16mA/PSI; 12.75DN/mA, so we can use those to scale a pressure from PSI to mA, and then scale that mA result to DN. We can also run the conversion in the opposite direction by taking the reciprocals of those values (1 divided by 1 is still 1): 1/(16mA/PSI) ≡ 0.0625PSI/mA; 1/(12.75DN/mA) ≡ ~0.0784314mA/DN.

If we have a DN of 204 (from a pressure of +0.250PSI), we subtract the bottom of the DN range of 51 from it to get 153 DN, multiply that by 0.0784...mA/DN to get 12mA, which means the incoming analog signal was 16mA (12 + 4), then multiply that 12mA by 0.0625PSI/mA to get 0.75PSI, which is the offset from -0.500 the bottom of the pressure range, so if we add those together we get +0.250PSI i.e. the original pressure.

We can also skip the intermediate conversion to mA and convert directly from DN to PSI:
Code:
                  mA          PSI             mA PSI            PSI
1 * 1 ≡ 0.784.... -- * 0.0625 --- = ~0.004902 ------ = 0.004902 ---
                  DN          mA              mA DN             DN
So the value 0.004902PSI/DN is yet another "value of 1" that we can use to scale DN offsets to PSI offsets:

A DN of 204, which is offset by 153 from the base DN of 51 becomes an offset of 0.75PSI (= 153DN * 0.04902PSI/DN) from the base pressure of -0.500PSI), resulting in a final pressure of +0.250PSI (= -0.500 + 0.750).

Take your time, try to understand this: if you can multiply by 1, I understand it may be an oversimplification to say you can be an engineer, but it really not all that far from the truth.

[Update: you may or may not understand what I did here; if not, then I suggest you search this forum for words like "scaling" or "analog conversion" or "engineering units" an read some of those threads. Perhaps one of those will click with you.]
 
Last edited:
+1 on the SCP instruction. I've attached the one I use and how it looks in ladder. Create a User Defined Tag that has pre built tags for the SCP instruction and it gets even simpler.

You must be using CompactLogix 5370? The 5380 allows the scaling to be done in the module configuration.

SCP_Inst.JPG
 

Attachments

  • SCP.zip
    1.2 KB · Views: 6
Just search the help file on the scaling instruction and use that formula.
This is what I use.
Code:
(* convert the inputs to floats *)
input_real:= raw_real;
input_min:= raw_min_real;
input_max:= raw_max_real;
scaled_min:= eu_min_real;
scaled_max:= eu_max_real;

(* calculates the slope or rate; i.e. rise over the run *)
If ((input_max - input_min) <> 0.0) Then
  rate:= (scaled_max - scaled_min) / (input_max - input_min);
Else
  rate:= 0.0;
End_if;


(* calculates the offset *)
offset:= scaled_min - (input_min * rate);

(* performs the scaling calculation; i.e. y = mx+b *)
output_real:= (input_real * rate) + offset;


(* If the "Limit_En" flag is set then limit the output to within the scaling parameters *)
IF limit_overflow THEN
	IF output_real > scaled_max THEN
		output_real:= scaled_max;
		fail:= true;
	ELSIF output_real < scaled_min THEN
		output_real:= scaled_min;
		fail:= true;
	else
		fail:= false;
	END_IF;
else
	fail:= false;
END_IF;

If fail_hi & fail then
	output_real:= scaled_max;
elsif fail then
	output_real:= scaled_min;
end_if;

scaled_out:= output_real;

I'm sure someone here could probably improve on this.
 
Hi everybody,
In my case I have a distance sensor 50mm to 350mm range and looking to use to meassure product height and I don't have SCP instruction available in RSLogix 5000 V13.
Sensor is fitted 220mm from the bottom of the conveyor. Conveyor empty raw_input is sitting at 32767. So I've done the x3 CPT insturction followed above.
Slope=(350-50)/32767=0.009155553
Offset= 50-(0×slope) so =50
Scaledheight=(slope×raw_input)+offset.
A product which I know it should be between 150-160mm is now reading 96mm.
Any help would be appreciated.
 
This isn't complicated. As pointed out it's a simple linear equation. For a compound gauge, you need to keep track of the sign, but the math doesn't change. Most PLCs will do the algebra in an equation block, but it can also be accomplished in a sequence of four-function math.

Scaling.png
 
oh dear. What @Tom Jenkins said.





Slope=(350-50)/32767=0.009155553

The origin of that equation is
Code:
    (350mm       -   50mm)
    ---------------------- = slope
    (32767count  - 0count)
where

  • a reading of 32767 counts corresponds to the distance sensor detecting something 350mm from the sensor, and
  • a reading of 0 counts corresponds to the distance sensor detecting something 50mm from the sensor.
  • and we are assuming any object detected between those distances (350mm and 50mm) of counts will give a reading between 0count and 32767count,
    • with linear behavior
      • e.g. a reading of 16383count, halfway between 0 and 32767, should be caused by an object at 200mmm from the sensor:
        • (50mm + ((350mm-50mm)/2)) = (50mm + (300mm/2mm)) = 50mm + 150mm = 200mm
  • Also note that, a higher raw input count reading implies an object farther away,
    • but with your formula,
      • ScaledHeight = (slope×raw_input)+offset
      • ScaledHeight = (0.009155553 x raw_input) + 50
    • the ScaledHeight value increases with increasing raw input count readings.
Also

In my case I have a distance sensor 50mm to 350mm range
...
Sensor is fitted 220mm from the bottom (surface?) of the conveyor. Conveyor empty raw_input is sitting at 32767


If the sensor is 220mm above the conveyor looking down at the conveyor* and the conveyor is empty, then is it likely that the sensor is detecting the surface of the conveyor i.e. an "object" of height zero.

In addition, the raw input reading is 32767 for a detection of something 220mm from the sensor**. That is very different from the 32767counts assumed above for an object detected at 350mm from the sensor. So now our formula looks like this:

Code:
    (220mm       -   50mm)
    ---------------------- = slope
    (32767count  - 0count)
But those 220mm and 50mm values are distances from the sensor, not heights above the conveyor:

  • 220mm from the sensor is 0mm height
  • 50mm from the sensor is 170mm height
So the formula now looks like this:

Code:
    (0mm         -  170mm)              -170mm
    ---------------------- = slope =  ---------- = -0.0005188
    (32767count  - 0count)            32767count


    170mm - (0xslope) = 170mm = offset


    ScaledHeight = 170mm - 0.0005188 x (raw_input - 0count)



    ScaledHeight = 170mm - 0.0005188 x raw_input
Let's test it out:

  • raw_input = 0counts
    • ScaledHeight = 170mm - 0.0005188 x 0 = 170mm (y)
  • raw_input = 32767counts
    • ScaledHeight = 170mm - 0.0005188 x 32767 = 0mm (y)
  • raw_input = 16383.5counts (halfway)
    • ScaledHeight = 170mm - 0.0005188 x 32767 = 85mm (y)






A product which I know it should be between 150-160mm is now reading 96mm.


Back calculating the raw input count value for the 150-160mm product using the old formula:

  • 96mm = 50 + 0.009155553 x raw_input
  • raw_input = (96 - 50) / 0.009155553 = 5024count
If we put that raw input count value of 5024 into the new formula:

  • ScaledHeight = 170mm - 0.0005188 x 5024 = 144mm
Which is a bit closer to the expected 150-160mm, but I would not declare victory until this had been validated on several more products of varying height.**

Also note that, with a negative slope, that the scaled heights get smaller as the raw input count value increases.


Finally, what type of sensor is this? Is the distance-to-counts characteristic truly linear? I know the infrared distance sensors' are very non-linear.




Bottom line: see item (vii) in my .signature below.



* I am assuming a lot here from the ambiguous description - "bottom:)hmmm:?) of the conveyor
** if the sensor is supposed to measure between 0mm-350mm, 220mm is a little early for the reading to be saturated at 32767 counts (assuming it is saturated). Also, if it is saturated at 220ms, we must consider whether it might also be saturated at 219mm, or 210mm, etc.
 
Last edited:
When you deal with numbers less than one, put a leading zero in front the decimal point, so that the decimal doesn't get 'lost'.


For instance, -.500 becomes -0.500


Yes, I'm a grammar nazi, too.
 
As usual, good old drbitboy as an elementary school teacher, we are with popcorn, and the questioner doesn't bother to read his own question.


In my case I have a distance sensor 50mm to 350mm range
Sensor is fitted 220mm from the bottom of the conveyor. Conveyor empty raw_input is sitting at 32767.
As drbitboy already wrote, please understand how these (red) numbers are interconnected.

It is best for you to make a drawing that will indicate:
- sensor installation point
- conveyor belt (?)
- sensor scale marked in millimeters and bits.
Looking at this picture, you can easily understand how the scaling formula is derived.
 
It is best for you to make a drawing that will indicate:
- sensor installation point
- conveyor belt (?)
- sensor scale marked in millimeters and bits.
Looking at this picture, you can easily understand how the scaling formula is derived.


Also, please give details about your distance sensor. A search on The Google for "distance sensor 50mm 350mm" gets a lot of hits for laser-based range finders (with some ultrasonics, plus this thread ;)), so either of those may be the tech underlying this particular sensor, so a linear characteristic is likely (unlike infrared).

P.S. What does it say when you look into a laser? "Do not look into device with remaining eye." "lolis:
 
Last edited:

Similar Topics

I am looking for a differential pressure transducer for a lab automation project. We need to be able to accurately measure level of water in a...
Replies
28
Views
9,647
Any recommendations for a DIY home automation suppler that has a inexpensive WiFi device that I can use to monitor my HVAC filter. Thanks, Bob O.
Replies
13
Views
3,330
On site we have Yokogawa EJA110E differential pressure transmitter connected to process air line. I'm not sure if this can be used to measure air...
Replies
9
Views
4,419
Hi, I am working on a current system using a Bailey Differential Pressure Transmitter. Unfortunately the label is torn off, the only thing left...
Replies
2
Views
1,705
Has anyone used a sensor like this on flammable gasses like natural gas? I have an orifice plate installed in a gas line that I'd like to...
Replies
17
Views
7,065
Back
Top Bottom