--- This block scales input between two points ( X1, Y1 ) and
( X2, Y2 ). The points are stored in the doublewords of X- and Y-tables ( DBs ).
First the block searches the two points, so that X1 < Input <= X2.
The line between those two points ( X1,Y1 and X2,Y2 ) is y = k*x + b.
So gain ( k ) can be calculated
Y1 = Gain * X1 + b
Y2 = Gain * X2 + b
=>
Y2 = Gain * X2 + Y1 - Gain * X1
= Gain * ( X2 - X1 ) + Y1
=>
Gain = ( Y2 - Y1 ) / ( X2 - X1 )
So Output is Output = Gain * Input + b
= Gain * Input + Y1 - Gain * X1
= Gain * ( Input - X1 ) + Y1
Limiting:
If Input <= first X-point: Output = first Y-point
If Input > last X-point: Output = last Y-point
If number of points < 2: Output is not updated
L #No_of_points
L 2
BEC // if there is not enough points
LAR1 P##X_table
L W [AR1,P#0.0]
T #XDBno // DB-number of X-points
L D [AR1,P#2.0]
T #Xpointer // X-table pointer
LAR1 P##Y_table
L W [AR1,P#0.0]
T #YDBno // DB-number of Y-points
L D [AR1,P#2.0]
T #Ypointer // Y-table pointer
OPN DB [#YDBno] // Opening of the Y-point DB
L DBD [#Ypointer]
T #Y1 // First Y-point
OPN DB [#XDBno] // Opening of the X-point DB
L DBD [#Xpointer]
T #X1 // First X-point
L #Input
>=R // If first X-point >= Input
L #Y1 // Output = first Y-point
JC OUT
L 2
T #Point_counter
LOOP: L #Ypointer
L P#4.0
+D // Increment the Y-pointer
T #Ypointer
OPN DB [#YDBno] // Opening of the Y-point DB
L DBD [#Ypointer]
T #Y2 // Second Y-point
L #Xpointer
L P#4.0
+D // Increment the X-pointer
T #Xpointer
OPN DB [#XDBno] // Opening of the X-point DB
L DBD [#Xpointer]
T #X2 // Second X-point
L #Input
>=R // If second X-point >= Input
JC EXIT // calculate the Output
L #X2 // Update first points
T #X1
L #Y2
T #Y1
L #Point_counter
INC 1 // Increment loop counter
T #Point_counter
L #No_of_points
<=I
JC LOOP // Next loop
L #Y2 // Input > last X-point
JU OUT // => Output = last Y-point
EXIT: L #X2
L #X1
-R
T #X_difference // X2 - X1
L #Y2
L #Y1
-R // Y2 - Y1
L #X_difference
/R
T #Gain
L #Input
L #X1
-R
L #Gain
*R
L #Y1
+R // Output = Gain * ( Input - X1 ) + Y1
OUT: T #Output
上面有程序的说明,在调用这个FB时,#No_of_points为15,输入
X_table为100.200...1500.
问题:当 #Input逐渐增加时(大概是100到800),为什么
L #Input
>=R // If second X-point >= Input
JC EXIT // calculate the Output
(其中>=R监视的时候此RLO一直为0,怎么回事啊?找不到这个点??程序肯定没问题,是正在使用的项目。另外,当输入大于200时,在此FB里面监视时也看不到OUT: T #Output输出值,调用此FB的FC里面能看见输出变化的。