发表于:2007-02-08 02:29:00
3楼
OB35:CALL FB100
1:convert analog input to engineering unit
for the exanple .assume that there is a level transmitter at piw256 ,generating
a 4-20mA signal ,with 4mA=0 inches,and 20mA=48inches.
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,or 48 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
raw :=PIW256
mineu:=-1.200000e+001
maxeu:=4.800000e+001
valeu:=#tank_level
NOP 0
fb100
in mineu:engineering unit value corresponding to 0 raw
in maxeu:eu value corresponding to 27648 raw
in raw:value from analog input card ,0..27648 range
out valeu:rw ,scaled to engineer
temp rawdi:raw ,as 32-bit integer
temp rawr:raw ,as floating point number
temp rngeu: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
1: convert raw to real
A(
L #raw
ITD
T #rawdi
SET
SAVE
CLR
A BR
)
JNB _001
L #rawdi
DTR
T #rawr
_001: NOP 0
2:calcuate eu span
L #maxeu
L #mineu
-R
T #rngeu
NOP 0
3:convert rawr to eu range
A(
L #rawr
L 2.764800e+004
/R
T #rawr
AN OV
SAVE
CLR
A BR
)
JNB _002
L #rawr
L #rngeu
*R
T #rawr
_002: NOP 0
4:add eu offset
L #rawr
L #mineu
+R
T #valeu
NOP 0