PLC 5 Scaling raw to Engineering units

EICS

Member
Join Date
Dec 2008
Location
Melbourne, Australia
Posts
323
I need to scale a raw value into Engineering units.


i don't think there is a standard scaling block in PLC 5 instruction set (or i didn't see one?)


what are you guys using to scale in PLC 5 CPU's ?



· Raw Input value

· Raw Min
· Raw Max
· EU Min
· EU Max


· EU Output value



I can probably do this with a compute statement and use variables (integers or floats) for the red values above. just wondering if someone has found a better way?


Regards
Alan
 
the canonical formula


Code:
EUOutputValue=((RawInputValue-RawMin)*(EUMax-EUMin)/(RawMax-RawMin))+EUMin
can be simplified to

Code:
EU_OutputValue = (m * RawInputValue) + b
where m and b can be pre-computed:
Code:
m = (EUMax - EUMin) / (RawMax - RawMin)


b = EUMin - (RawMin * (EUMax - EUMin) / (RawMax - RawMin))

and hardcoded into a CPT instruction:

Caveat

  • Typos likely
 
Last edited:
Here is the formula.. It can be simplified if the scaled min and max, the raw min and max are fixed. A compute instruction will work.

(((Scaled Max-Scaled Min)/(Max Raw Input-Min Raw Input))*(Raw Input-Min Raw Input))+Scaled Min = Scaled Value

Edit: drbitboy types faster then I do.
 
Last edited:
A compute instruction will work.

(((Scaled Max-Scaled Min)/(Max Raw Input-Min Raw Input))*(Raw Input-Min Raw Input))+Scaled Min = Scaled Value

Agreed, you can use a CPT instruction, but I will wager that doing the math piece by piece will be faster. CPT has never been a fast instruction, whereas the MULs and DIVs have been optimised over the years.

The major reason is that the CPT has to initially parse the expression to determine the evaluation order, then it has to do the individual maths in that order.

By writing it long-handed, the programmer determines the order of evaluation.

If you have multiple scalings to do, you could write the code in a subroutine, passing the parameters in and the result out in JSR/SBR/RET instructions.
 
Last edited:
#1 Daba, I have just done exactly that to show a bit of code in ladder in a post for displaying a percentage level in a tank.
I would normally create a function block but the OP has an existing system in ladder only.
 
Another point to consider, is do you want to Clamp the scaling to the Min/Max EU values? The above examples don't do this, if the raw value dips or exceeds the raw min/max due to signal variation or in the case of a 4-20ma signal, loss of signal (0ma) or instrument error (21ma). We have facilities that don't want to see a negative 0-100% level for example on loss of signal.
 
Another point to consider, is do you want to Clamp the scaling to the Min/Max EU values? The above examples don't do this, if the raw value dips or exceeds the raw min/max due to signal variation or in the case of a 4-20ma signal, loss of signal (0ma) or instrument error (21ma). We have facilities that don't want to see a negative 0-100% level for example on loss of signal.

My opinion is you put the result of the calculation on the screen with no clamps. If an operator sees a -25% reading and an alarm is going off saying analog signal failure, what's the issue ?

And if it's only slightly negative, it could prompt him to report it to maintenance as a "probe needs re-calibrating" ...
 
My opinion is you put the result of the calculation on the screen with no clamps. If an operator sees a -25% reading and an alarm is going off saying analog signal failure, what's the issue ?

And if it's only slightly negative, it could prompt him to report it to maintenance as a "probe needs re-calibrating" ...

Because -25% isn't really a level....It's confusing. It's a personal preference by some plants. They'd rather clamp at 0 and have a separate alarm.
 
I agree with Daba, many a time I have gone to a plant that does not work, maintenance fitters have been crawling all over it for an hour or so, I go to the alarm page & hey presto, the alarm is there. It seems maintenance engineers have some sort of blind spot for alarms so only look at the graphics for ideas.
Typically in one plant we had although alarms were present for a tank weight below 0kg, the operators instinct was there was a problem with the weighing system if it went to -90 kg.
 
0%, +/- "a bit" is empty.
100%, +/- "a bit" is full.

-25% would not be possible unless the sensor or probe is not giving a signal.

Some devices can be configured to give "fail-safe high" signals instead of 0mA, e.g. if the sensor detects that it cannot measure the parameter correctly. In the context of 4-20mA devices, "high" is usually 22mA


You can use that conflicting information to decide whether the signal wiring has failed, or the sensor has detected an internal error.

But this thread has been about what you show the operators. Conversely where do you set your alarm levels.

It's genuinely a case of "horses for courses", and the possibilities are endless, but I would still display what the system is calculating the level, temperature, pressure, or whatever is, rather than introducing an arbitrary "clamp", which can hide important information, just so it looks nice.
 
Many thanks to you all for posting info here, it's really appreciated.


the processing time of the compute instruction could be an issue for me as my calculation will be driving an analog output and I/P converter on a packaging machine, its not ideal having a legacy plc5 to work with here but money is tight post covid 19 (in Australia at present).


as noted by some responders i have coded in some clamps to allow for under/over range to the final address and this can also be done in the analog module applet. My HMI "engineering page" will have all values displayed as this will help with commissioning.



thanks for good info
 
If you can afford to loose some resolution. Just span the AO card 0-1000 instead of 0-4095. Multiply you engineering unit by 10 and send to card.

55.6% x 10 =556 to AO channel.

I would not worry about speed, if will not be really quick regardless of the math. You are still going to wait for a Block transfer instruction to send the value to the AO card.


You did not mention the model of PLC-5 or if you did, I missed it. Anyway, in the older non-enhanced models, the CPT instruction was not supported.
 
Last edited:
................................................
.......................
You did not mention the model of PLC-5 or if you did, I missed it. Anyway, in the older non-enhanced models, the CPT instruction was not supported.


Thanks Ken


The Model is a PLC5/40E Series F with RJ45 on-board so it will support CPT instructions.


I am using N series High resolution Analog Output card in this case its a 1771-NOV

so can scale in module -10,000 to +10,000 (-10V to +10V) so yes I can set it up for 0 to 10,000 (0V to +10V)


once again many thanks to all that took the time to respond, much appreciated.
Merry Xmas
 
Last edited:
Since there is a HMI attached do you really need to scale in the PLC?
why not work with RAW data in the PLC and use the HMI to do the scaling?
 
Since there is a HMI attached do you really need to scale in the PLC?
why not work with RAW data in the PLC and use the HMI to do the scaling?

No-no, limit the HMI to doing what it MUST do. PLCs are much faster than HMI's, and what if another system needs to read the data ?


HMI's should be a window into the PLC, not an interpretation of the data therein

just 2c from me
 

Similar Topics

I want to measure the tank level and get the sensor output to the PLC. Below are the details : Tank Height =0 - 3m, the sensor is stalled 0,2m...
Replies
15
Views
630
Hello everyone, been trying to figure this one out for awhile now. The system configuration is as follows: Processor is an L63 5563 ControlLogix...
Replies
0
Views
613
I’m trying to perfect the HMI interface for analog configuration. I’ve provided the user the same options for all analog inputs, as follows...
Replies
10
Views
1,675
Hello All, What Wil be the raw scaling range if I want to connect 0-1vdc humidity sensor. Thanks
Replies
1
Views
950
Hi, I have to make an weighing system with load cells. Here is what I had understood until now: Load cells: Sensibility often 2mv/V Recommended...
Replies
29
Views
8,562
Back
Top Bottom