You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
76 lines
1.8 KiB
FUNCTION BS_Scale : REAL
|
|
VAR_INPUT
|
|
Input :INT;
|
|
Input_Type :BYTE; (*1,PT1000; 2,2-10V/4-20ma 3,0-10V/0-20ma *)
|
|
PVL :INT;
|
|
PVH :INT;
|
|
ROffset :INT; (*补偿值*)
|
|
Offset :REAL; (*补偿值*)
|
|
END_VAR
|
|
|
|
VAR
|
|
Input_Isolate:INT;
|
|
END_VAR
|
|
(*
|
|
|
|
时 间:20210610
|
|
版 本:1.2
|
|
作 者:姚立
|
|
名 称:AIAO通用量程转换函数
|
|
说 明:用于量程转换的函数
|
|
备 注:
|
|
1.0 初步建立
|
|
1.1 优化算法
|
|
1.2 加入修正IOM.0801U-E5版本温度跳变问题的过滤函数
|
|
|
|
依赖块:BF_IOM0801U_E5
|
|
|
|
*)
|
|
|
|
(*
|
|
Input_Type: 输入 1,PT1000;
|
|
2,0-10V/0-20ma;
|
|
3,2-10V/4-20ma;
|
|
输出 4,PVL-PVH对应 0-10V/0-20ma;
|
|
5,PVL-PVH对应 4-20ma/2-10V输出;
|
|
|
|
PVH为示值上限,PVL为示值下限,PVL可以为负值
|
|
Offset 输出补偿
|
|
ROffset 基准补偿 AI基准值27648 AO基准值214
|
|
*)
|
|
|
|
Input_Isolate:=BF_IOM0801U_E5(Input,Input_Isolate);
|
|
|
|
if Input<>0 then
|
|
case Input_Type of
|
|
1:
|
|
BS_Scale := (INT_TO_REAL(Input_Isolate)/100.0)+Offset;
|
|
2:
|
|
if PVL>0 then
|
|
BS_Scale := ((INT_TO_REAL(Input)/(27648.0+(INT_TO_REAL(ROffset))))*INT_TO_REAL(PVH-PVL))+Offset;
|
|
else
|
|
BS_Scale := (((INT_TO_REAL(Input)/(27648.0+(INT_TO_REAL(ROffset))))*INT_TO_REAL(PVH-PVL))-INT_TO_REAL(abs(PVL)))+Offset;
|
|
end_if;
|
|
3:
|
|
if PVL>0 then
|
|
BS_Scale := (INT_TO_REAL(Input-REAL_TO_INT((27648.0+INT_TO_REAL(ROffset))*0.2))/((27648.0+INT_TO_REAL(ROffset))*0.8)*INT_TO_REAL(PVH-PVL))+Offset;
|
|
else
|
|
BS_Scale := (INT_TO_REAL(Input-REAL_TO_INT((27648.0+INT_TO_REAL(ROffset))*0.2))/((27648.0+INT_TO_REAL(ROffset))*0.8)*INT_TO_REAL(PVH-PVL))-INT_TO_REAL(abs(PVL))+Offset;
|
|
end_if;
|
|
4:
|
|
BS_Scale := (((INT_TO_REAL(Input)/INT_TO_REAL(PVH-PVL)/100.0))*(214.0+Offset));
|
|
5:
|
|
BS_Scale := ((((INT_TO_REAL(Input)/INT_TO_REAL(PVH-PVL))/100.0)*((214.0+Offset)*0.8))+((214.0+Offset)*0.2));
|
|
end_case;
|
|
end_if;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
END_FUNCTION
|