现有压力变送器一只,量程0~6MPa,输出4~20mA,请选择CPU及AI/O模块,写出模拟量的输入输出程序,并对程序作出注释及说明。压力要求精确到0.01MPa。
PLC品牌不限。
工控PLC擂台每周一期,本期下周末结贴。奖项设置:一等奖1名:50MP,二等奖5名:10MP,三等奖10名:30积分。
MP介绍:gongkongMP即工控币,是中国工控网的用户积分与回馈系统的一个网络虚拟计价单位,类似于大家熟悉的QB,1个MP=1元人民币。
MP有什么用?兑换服务:以1个MP=1元来置换中国工控网的相关服务。 兑换现金:非积分获得的MP可兑换等值现金(满100MP后、用户可通过用户管理后台申请兑换)。
硬件品牌 | 型号 | 数量 | 功能 |
siemens 电源模块 | 6ES7 407-0DA01-0AA0 | 1 | 电源模块 输出4A DC24V |
siemens CPU312 | 6ES7 312-1AD10-0AB0 | 1 | CPU312,16K 内存 |
siemens I/O模块323 | 6ES7 323-1BH01-0AA0 | 1 | 8 点输入24VDC;8 点输出24VDC 模块 |
siemens 模拟量 334 | 6ES7 334-0CE01-0AA0 | 1 | 模拟量输入4路模拟量输出2路 |
ifm压力传感器 | ifm 0~6MPa | 1 | 用于检测压力 |
OB35
Network 1 convert analog input to engineering unit
for the exanple .assume that there is a level transmitter at piw272 ,generating
a 4-20mA signal ,with 4mA=0 inches,and 20mA=600inches.
mineu must be set to the engineering unit value corresponding to 0 mA,which is-
12 inches .maxeu is set to the eu value corresponding to 20 mA,or600 inches.as
long as the analog input signal is between 4 to 20 mA,tank_level will be set to
the current height in inches.
CALL FB 100 , DB100 // 调模拟量输入量化程序,scale analog input to engineering units
raw :=PIW272
mineu:=0.000000e+000
maxeu:=6.000000e+006
valeu:=DB10,DBD0
Network 2 convert setting in engineering units to analog output
in this example ,assume that pqw272 connects to a control value that is fully
closed at 0 V output ,and fully open at 10 V output .valve_pos is a number
between 0 and 100 ,indicating the valve open percentage
CALL FB 101 , DB101 //调模拟量输出量化子程序,unscale fromeu range to analog output range
valeu:=DB10,DBD20
mineu:=0.000000e+000
maxeu:=1.000000e+002
raw :=PQW272
call fc 10 //调用压力换算程序 ,press conversion
name | data type | address | initial | commet |
raw | int | 0.0 | 0 | value from analog input card ,0..27648 range |
mineu | real | 2.0 | 0.000000e+000 | engineering unit value corresponding to 0 raw |
maxeu | real | 6.0 | 6.000000e+006 | eu value corresponding to 27648 raw |
name | data type | address | initial | commet |
valeu | real | 10.0 | 0.000000e+000 | rw ,scaled to engineering units |
name |
data type | address | commet |
rawdi | Dint | 0.0 | raw ,as 32-bit integer |
rawr | Real | 4.0 | raw ,as floating point number |
rngeu | Real | 8.0 | eu range |
FB100 :scale analog input to engineering units
converts integer analog input value from 0..27648 range to mineu..mineu range
.coversion equation is:
valeu =raw*(maxeu-mineu)/27648+mineu
Network 1 convert raw to real
L #raw
ITD
T #rawdi
L #rawdi
DTR
T #rawr
Network 2 calcuate eu span
L #maxeu
L #mineu
-R
T #rngeu
Network 3 convert rawr to eu range
L #rawr
L 2.764800e+004
/R
T #rawr
L #rngeu
*R
T #rawr
Network 4 add eu offset
L #rawr
L #mineu
+R
T #valeu
name | data type | address | initial | commet |
valeu | Real | 0.0 | 0.000000e+000 | eu value corresponding to 0 raw |
mineu | Real | 4.0 | 0.000000e+000 | eu value corresponding to 0 raw |
maxeu | Real | 8.0 | 1.000000e+002 | eu value corresponding to 27648 raw |
name | data type | address | initial | commet |
raw | Int | 12.0 | 0 | analog output value in 0..27648 range |
|
data type | address | commet |
rngeu | Real | 0.0 | eu span |
rawr | Real | 4.0 | unscaled value as floating point |
rawdi | Dint | unscaled value as 32-bit integer |
FB101:unscale fromeu range to analog output range
unscales from specified eu range to 0..27648 analog output range .unscale
equation is:
raw =(valeu -mineu)*27648/(maxeu-mineu)
if valeu>maxeu or valeu <(2*mineu-maxeu) then valeu may not be convertable to a
16-bit integer if this occurs ,the output of this function is undefined .the
output is also undefined if maxeu=mineu
Network 1 calculate eu span
L #maxeu
L #mineu
-R
T #rngeu
Network 2 remove offset a convert valeu to 0..1 span
L #valeu
L #mineu
-R
T #rawr
L #rawr
L #rngeu
/R
T #rawr
Network 3 convert output to 0..27648 range
L #rawr
L 2.764800e+004
*R
T #rawr
Network 4 convert to integer
L #rawr
TRUNC
T #rawdi
L #rawdi
T #raw