**PLC Raw Value to engineering units conversion formula**

For example, I have a field device which delivers an analog signal to a PLC which I then have to convert to usable numbers. Here is what I’ve come up with and I would appreciate it, very much, if some of you more knowledgeable folks would check over my work and see if there’s something that I missed.

So let’s get started:

**In** = Raw input value

**Out** = Scaled value, in Engineering Units

**EU_Max** = Engineering Units Maximum Value (i.e. for 0 to 100, this would be 100)

**EU_Min** = Engineering Units Minimum value (i.e. for 0 to 100, this would be 0)

**Raw_Max** = Raw value Maximum (i.e. for a 4-20ma signal this would be 20)

**Raw_Min** = Raw value Minimum (i.e. for a 4-20ma signal this would be 4)

```
Out = In * ((EU_Max - EU_Min) ÷ (Raw_Max - Raw_Min)) - (Raw_Max * ((EU_Max - EU_Min) ÷ (Raw_Max - Raw_Min)) - EU_Max)
```

So, in order to simplify things, let’s say that I’m using a level transmitter and I’m working with an analog signal with a range of 4ma to 20ma. My Engineering Units (%) range is 0% (empty) to 100% (full). If I am getting a singal of 12ma from my transmitter my calculation would look like the following;

**In** = 12

**EU_Max** = 100

**EU_Min** = 0

**Raw_Max** = 20

**Raw_Min** = 4

```
12 * ((100 - 0) ÷ (20 - 4)) - (20 * ((100 - 0) ÷ (20 - 4)) - 100)
```

That would give us a result of 50, which would indicate that our vessel or container is 50% full.

If our analog signal is 8ma it would indicate that our vessel is 25% full.

Now let’s switch things up a bit. Let’s say I’m using a temperature transmitter with a range of 4-20ma. My range for my Engineering Units is 0º to 150º. Let’s assume I’m getting, again, a 12ma signal.

```
12 * ((150 - 0) ÷ (20 - 4)) - (20 * ((150 - 0) ÷ (20 - 4)) - 150)
```

If you suspected that we would get a value of 75 you would be correct! So our temperature transmitter is reading 12ma or 75º!

If we change the operating range of our input to -150º to 150º and we’re getting a 12ma signal we would get a result of 0º.

This all seems to be working well. Even when we throw some non-typical numbers at it.

**In** = 6

**EU_Max** = 125

**EU_Min** = 10

**Raw_Max** = 20

**Raw_Min** = 0

**Out** = 44.5

This also seems to work if our ranges are inverse (i.e. Raw_Max < Raw_Min or EU_Max < EU_Min)

**In** = 8

**EU_Max** = 0

**EU_Min** = 100

**Raw_Max** = 20

**Raw_Min** = 4

**Out** = 75

So there you have it. Do you see anything that I’m missing? Any glaring holes in my formula that would cause the math to fail that you notice?

THE FINAL SOLUTION/FORMULA

Can be simplified to

```
Out = EU_Min + (EU_Max - EU_Min) * ((In - Raw_Min) / (Raw_Max - Raw_Min))
```

And this is called “Linear interpolation”. Nice.