please critique my Allen Bradley type SCP function

ganutenator

Lifetime Supporting Member
Join Date
May 2002
Location
kansas
Posts
1,440
(* convert the inputs to floats *)

input_min:= raw_min_real;
input_max:= raw_max_real;
scaled_min:= eu_min_real;
scaled_max:= eu_max_real;

(*limit raw to 0 to 10,000*)
If raw_real < 0.0 then
input_real:= 0.0;
elsif raw_real > 10000.0 then
input_real:= 10000.0;
else
input_real:= raw_real;
end_if;



(* 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;
 
FYI the form does have a CODE format which can be helpful for ST.

Code:
input_min:= raw_min_real;
input_max:= raw_max_real;
scaled_min:= eu_min_real;
scaled_max:= eu_max_real;

(*limit raw to 0 to 10,000*)
If raw_real < 0.0 then
    input_real:= 0.0;
elsif raw_real > 10000.0 then
    input_real:= 10000.0;
else
    input_real:= raw_real;
end_if;
Not sure if your buffer tags are necessary here. I'm also not much of a fan of hard coded limits like this, especially if this is to be an AOI.

Code:
(* 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 don't like forcing values here. I'm assuming that you are using the SCP in this instance for an analog input. So your "input_real" value is the raw data from the card and the "output_real" is the scaled value after the math? Many cards can read beyond 20mA and many can be configured to read below 4mA. Both instances are handy. I'm more of a fan of a tolerance check, so if the signal is above 20 or below 4 by x% then error but don't overwrite the data. Make an indicator on the HMI. Overwriting invalidates the sensor's data and makes the assumption it is "BAD". Which may or may not be the case.

If a sensor has a max of 200 PSI, and a fault indicator is active because the sensor is reading 213.7 PSI (max mA reading the card can do), it's a bit more obvious to me there is a problem, such as the line pressure is actually way too high. More often than not the sensor hasn't failed, the process has.

I don't like the tag convention, it's confusing. After seeing the limit logic I thought perhaps it was for analog outputs and capping that, which I can understand. But that doesn't appear the case.

If it were me, my tags would be:

Code:
rData //Raw data value from Analog to Digital converter
rMin //Raw Min (Analog Card value at 0 or 4mA (-10V or 0V)
rMax //Raw Max (Analog Card value at 20 mA (10V)
sMin //Scaled Engineering Unit Min
sMax //Scaled Engineering Unit Max
sValue //Scaled Value
slope //Use instead of rate (since you are calculating the slope of a line which is probably more familiar terminology for y=mx+b)

I would also keep the "SCP" logic you are building to just that. Just do the calculation and no more. If you want to add faults and such, then personally I would just build all the functionality I needed right in an Analog Input AOI (scaling, fault detection, calibration, simulation...etc).
 
additional info

The buffer tags are because this is a user defined function block.

Good points though.

I wrote it for my use only and my 4-20ma is 0- 10k after the analog to digital conversion by the card.

I agree about the clamps. That needs work.

The card sends weird numbers that stand for different error codes when the sensor is out of range, but yes, probably won't happen at 10,100.

I need to do more testing.
 

Similar Topics

please help me . I have to make this ladder diagram and I can’t figure it out :(
Replies
12
Views
348
Hi , Where i can find Mitsubishi PLC Card end of line & replacement model details. i am looking for Q02CPU replacement model. Please advice. thanks
Replies
2
Views
126
Hello, I am trying to get a Yokogawa Hart pressure Transmitter and a Rosemount Temp Transmitter to read on a 1769-IF4 module on an L33ERM...
Replies
10
Views
378
Please help me, I have solve many week but still not solve it. I found trouble of factory talk studio when I set tag by browse address of OPC...
Replies
0
Views
122
Back
Top Bottom