新古典经济学-climate
附录1:外文资料翻译译文
基于PLC的自动化制造系统
15.梯形图逻辑函数
主题:
?
数据处理、数学运算、数据转换、阵列操作、统计、比较、布尔量运算等函数
? 设计实例
宗旨:
? 理解基本函数,允许计算和比较
?了解使用了内存文件的数组函数
15.1介绍
梯行图逻辑输入触点和输出线圈之间允许简单的逻辑判断。这些函数把基
本的梯形图逻辑延伸到其他控制形式中。例如,附加的定时器和计数器允许基于
事件的控制。在下图1
5.1中有一个较长的关于这些函数的表。这包括了组合逻
辑和事件函数。本章将会研究数据处理和数值
的逻辑。下一章将介绍表、程序控
制和一些输入和输出函数。剩下的函数会在后面的章节中讨论
输入输出函数
程序控制函数
数字逻辑函数
列表函数
事件函数
数据处理函数
组合逻辑函数
继电器触点
线圈
计时显示
计数显示
移动
数学运算
转换
布尔量运算
比较
转移入栈出栈
序列发生器
分支循环
立即输入输出
错误中断检测
PID
通讯
高速计数器
字符串函数
图15.1 基本PLC函数分类
大多数的函数会使用PLC的存储单元获取值、储存值和跟踪函数状态。一<
br>般大部分函数当输入值是“真”时,会被激活。但是,有些函数,如延时断开定
时器,可以在无输
入时,保持激活状态。其它的函数仅当输入由“假”变“真”
时,才会被执行,这就是所谓的上升沿触发
。想想,一计数器仅仅是输入由“假”
变“真”时才会计数,输入为“真”状态的持续时间并不影响函数
动作。而下降
沿触发函数仅当输入由“真”变“假”时才会触发。多数函数并非边沿触发:除
非
有规定说明函数不是边沿触发。
标签:我并没有像说明书或者软件里那样准确的画出这些函数。因为
这样会节省空间并且易于阅读,但是所有的必要信息我都给出了。
15.2数据处理
15.2.1传递函数
有两种基本的传递函数;
MOV(值,操作数)
-把值传递到指定的存储位置。
MVM(值,标号,操作数)
-把值传递到指定的存储位置,但是用标号来指定一个
传递的位。
这个MOV函数从一个存储
空间取出一个值放置到另外一个存储空间里。下
图15.2给出了MOV的基本用法。当A为“真”,M
OV函数把一个浮点数从原
操作数传递到操作数存储位置。原操作数地址中的数据没有改变。当B为“真
”
时,原操作数中的浮点数将被转换成整数存储在操作数存储区中。浮点数会被四
舍五入成整数
。当C为“真”时,整数“123”将被存储在整数文件N7:23中。
MOV
原操作数F8
:07
操作数F8:23
MOV
原操作数F8:07
操作数N7:23
MOV
原操作数123
操作数N7:23
标签:当函数值改变时,除了输入与输出,其值是瞬间改变的。试想:
1
图15.2中,如果ABC都为“真”,那么F8:23的值将会在下一个指令到来前
就变化。这与输入输出扫描只发生在逻辑扫描之前或者之后不同。
图15.2
MOV的基本用法
下图15.3给出了更多更复杂的MOV函数用法。当A为“真”时,第一个
模块将会把值“123”送入N7:0,同时第二个模块将会把值“-9385”从N7:1 送
到
N7:2中(这个值之所以为负数,是因为我们使用了2S的compliment)。对
于基本的MO
V函数使用中,二进制数值不是必要的;但是在MVM函数中,二
进制数值却是必要的。这个模块中从N
7:3 移动二进制数值到 N7:5
中。
但是这
些“位”在N7:4中仍为“ON”
,操作数的其他位将不会受到影响。请注意:
N7:5的第一位N7:50在指令执行前后仍为“ON”
,但是在N7:4中却不同,MVM
函数当应用在个别二进制位的处理中时非常有用,但是处理实数却是
用处不大
了。
MOV
原操作数130
dest
N7:0
MOV
原操作数N7:1
dest
N7:2
MVM
原操作数N7:3
标号N7:4
dest
N7:5
MVM
原操作数N7:3
标号N7:4
dest N7:6
地址
N7:0
N7:1
N7:2
N7:3
N7:4
N7:5
N7:6
之前数据
二进制
十进制
B#0000 0
B#1111 -9385
B#1000 -32768
B#1011 22715
B#1010 10922
B#0001 1
B#1111
之后数据
二进制 十进制
B#0010 130
B#1111 -9385
B#1111 -9385
B#1111
-10053
B#1010 10922
B#10 2219
B#1111
2
标签:标号的概念非常重要,并且也可以用在其他函
数中。标号允许指令改变一
个二进制数据的其中四位,而不用改变它的全部数值。当你使用二进制数据中
的
位来表示声明,模式或者状态等内容时,你会很希望这么做。图15.3是MOV和
MVM函
数对二进制数值的操作例子
图15.3MOV和MVM函数的使用实例
15.2.2数学函数
数学函数将检索一个或多个值,执行一个操作然后把结果储存在内存中
。
图15.4展示的是一个ADD函数从N7:4和F8:35中读取数据操,把他们转换成
操
作数的地址格式,把两个浮点数相加,结果储存在F8:36中。该函数有两个原
操作数记做“原操作数
A” 、“原操作数B”。对于该函数来说原操作数顺序
可以改变,但是这对于“减法函数”或“除法函
数”等其他操作来说却不一定正
确,下面列出了其他一些基本的数学函数。其中的一些,如“取负”是一
元的函
数,也就是说它只有一个原操作数。
加
原操作数A
N7:04
原操作数B F8:35
操作数F8:36
加(值1,值2,操作数)-累加两个值
减(值1,值2,操作数)-值1减值2给操作数
乘(值1,值2,操作数)-值1乘值2给操作数
除(值1,值2,操作数)-值1除值2给操作数
取反(值,操作数)
-将值取反送给操作数
清除(值) -将值存储区清零
标签:为了节省空间上图给出了函数的缩略符号,例如函数ADD(值1,值2,
操作数)需要两个原
操作数,并把值存入操作数。为了减少描述函数时的空间这
些符号将被用在很多地方
图15.4数学函数
图15.5列出了数学函数的用法,多数函数的执行会给出我们期待的结
果,
第二个ADD函数从N7:3中取了一个值,加1然后送入原操作数,这就是通常
所说的“
自加”操作。第一个DIV,执行操作整数25除以整数10,结果四舍五入
3
为最接近的整数,这时,结果被储存在N7:6中。NEG指令取走了新数“
-10”,
而不是源数据“0”,从N7:4取出的数据符号被取反,结果存入N7:7。
地址
N7:0
N7:1
N7:2
N7:3
N7:4
N7:5
N7:6
N7:7
N7:8
F8:0
F8:1
F8:2
F8:3
10.0
25.0
0
0
之前值 之后值
10
25
0
0
0
0
0
0
100
10.0
25.0
2.5
2.5
图15.5 数学函数例子
10
25
35
1
-10
250
3
10
0
标签:调用,整数范围从-32768到32767并且没有小数。 图15.6列出了更多的高级函数。这个列表包括基本的三角函数、取绝对值
函数、对数函数、取二
次方根函数。最后一个函数CPT能接受表达式并且可以执
行一个复杂的运算。
ACS(值,操作数) - 反余弦
COS(值,操作数) - 余弦
ASN(值,操作数) - 反正弦
SIN(值,操作数) - 正弦
ATN(值,操作数) -反正切
TAN(值,操作数) - 正切
4
XPY(值1,值2,操作数) - X的Y次幂
LN(值,操作数) - 自然对数
LOG(值,操作数) - 以10为底的对数
SQR(值,操作数) - 开二次方根
CPT(操作数,表达式) - 做运算
图15.6 高级数学函数
图15.7展示的是把表达式转化成梯形图逻辑。转换的第一步是
把表达式的
变量存入PLC中没被使用过的存储区中。接下来拥有很多嵌套运算的方程就可
以被
转化,例如LN函数。这时LN函数的运算结果被保存在其他存储空间中,
之后会被调用。其它的一些操
作会应用在相似的情况下。(注意:这些方程可能
应用在其他场合中,占用更少的存储空间。)
给定方程
指定存储
图15.7 用梯形图表示的方程
和图15.7中一样的方程被应用于图15.8所示的CPT函数中。存储区也和上
5
图使用的一样。该表达式被直接输进了PLC程序中。
图15.8 利用CPT函数计算
数学函数可以导致诸如溢出,进位等状态标识位
变化,注意要尽量避免出
现像“溢出”这样的问题。但是使用浮点数时这种问题会少一点。而整数极易出
现这样的问题,因为它们受到-32768—32767这样一个数据范围的限制。
15.2.3 转换函数
梯形图中的转换函数列在了图15.9中。例子中的函数将会从D存
储区读取
一个BCD码数据,然后把它转换为浮点数存储在F8:2中。其它的函数将把二进
制
负数转换成BCD码数据,下面的函数也包含了弧度数和角度的转化。
TOD(value,destination) – 把BCD码转换为二进制数
FRD(value,destination) - 把二进制值转换为BCD码
DEG(value,destination) – 把弧度数转换为度数
RAD(value,destination) - 把度数转换为弧度数
图15.9
转换函数
图15.10给出了转换函数的例子。这些函数读取一个源数据后,开始转换,
结束
后储存结果。TOD函数转换成BCD码将会出现“溢出”错误。
6
地址
N7:0
N7:1
F8:0
F8:1
F8:2
F8:3
D9:0
D9:1
之前值
0
548
3.141
之后值
1793
548
3.141
45 45
0
0
0000 0000 0000 0000
0001 0111 1001 0011
180
0.785
0000
0101 0100 1000
0001 0111 1001 0011
图15.10
转换例子
15.2.4矩阵函数
矩阵可以储存多列数据。在PLC中这将是一系列的整数数字,浮点数或者
其它类型的数据。
例如,假定我们测量和保存一块封装芯片的重量时要使用浮点
数存储区F8:20。每十分钟要读取一次
重量数据,并且一小时后找出平均重量。
这一节我们将聚焦于矩阵中多组数据的处理技术,也就是说明书
中所谓的“块”。
15.2.4.1-统计
这些函数也是可以处理统计数据的。图15.1
1列出了这些函数,当A变为
“真”AVE函数的转换操作从存储区F8:0开始,并算出四个数的平均
值。控制
字R6:1被用来跟踪运算的进程,并判断运算何时结束。这些运算还有其它的一
些是
边沿触发的。该次运算可能会需要经过多个扫描周期才能完成。运算结束后,
平均值被储存在F8:0中
,同时R6:1DN位被置ON。
AVE(开始值,操作数,控制字,长度)
– 求平均值
STD(开始值,操作数,控制字,长度)
– 求标准差
SRT(开始值,控制字,长度)
– 排列一串值
图15.11统计函数
7
如图15.12给出的统计函数例子,它拥有一个有四个字长从F8:0开始的数
组数据。每次执行平均
值运算的结果储存在F8:4中,标准差储存在F8:5中。一
系列数值被存放在从F8:0到F8:3
的按升序排列的存储区中。为防止出现数据覆
盖现象,每个函数都应该有自己的控制存储器。同时触发该
函数与其他运算不是
一个明智的选择,因为在计算期间该函数会移动数据,这会导致错误的结果。
A导通B导通C导通
地址
F8:0
F8:1
F8:2
F8:3
F8:4
F8:5
之前
3
1
2
4
0
0
后
3
1
2
4
2.5
0
后
3
1
2
4
2.5
1.29
后
1
2
3
4
2.5
1.29
图15.12 统计运算
旁白:这些函数允许SPC(统计)数据控制中的实数运算。仅
有的不是这样的PLC函数是随机函数,它允许出现随机样本数据。
15.2.4.2-块操作
图15.13给出了最基本的块函数。这个COP函数将会拷贝从
N7:50到N7:40
拥有十个数据的数组。FAL函数将会通过一个表达式执行数学运算。FSC函
数通
过使用表达式允许数组之间进行比较。FLL函数会利用一个数据把块存储区填充
起来。
8
COP(开始值,操作数,长度)
拷贝一个数据块
为得到一个多重值而执行基本的数学运
FAL(控制字,长度,模式,操作数,表达式) 算
FSC(控制字,长度,模式,操作数,表达式) 为得到一个多重值而作一个比较
FLL(值,操作数,长度) 把一个单一值拷贝到一个数据块
图15.13块操作函数 <
br>图15.14显示的是拥有不同地址模式的FAL函数使用例子。第一个FAL函
数将会执行下列
运算:
N7:5=N7:0+5, N7:6=N7:1+5, N7:7=N7:2+5,
N8:7=N7:3+5, N7:9=N7:4+5.
第二个FAL函数中在表达式值之前缺少“#”标识,因此运算将变为:
N7:5=N7:0+5, N7:6=N7:0+5, N7:7=N7:0+5,
N8:7=N7:0+5, N7:9=N7:0+5.
当B为真,且为模式2时该指令在每次扫描周
期到来时执行两个运算。最后一
个FAL运算的结果为:
N7:5=N7:0+5,
N7:5=N7:1+5, N7:5=N7:2+5, N7:5=N7:3+5,
N7:5=N7:4+5.
最后一个操作貌似没什么用处,但是请注意,该运算是增值的。在C上升沿
到来
时该运算都会执行一次。每次扫描周期经过时,这几个运算将执行所有的5个操
作一次。用
来指示每次扫描运算的编号,而插入一个号码也是有可能的。由于有
较大的数组,运算时间可能会很长,
同时尝试每次扫描时执行所有运算也将会导
致看门狗超时错误。
9
图15.14 文本代数函数例子
15.3 逻辑函数
15.3.1 数值比较
图15.15所示为比较函数,先前的函数块是输出,它取代了输入
联系。例子
展示的是比较两个浮点数大小的函数EQU。如果数值相当,则输出位B3:51
为
真,否则为假。其他形式的相等函数也裂了出来。
EQU(值1,值2)
NEQ(值1,值2)
LES(值1,值2)
LEQ(值1,值2)
GRT(值1,值2)
GEQ(值1,值2)
CMP(表达式)
MEQ(值,符号,临界值)
LIM(低限,值,高限)
相等
不相等
小于
小于等于
大于
大于等于
比较两值是否相等
使用一个符号来比较值是否相等
检测值是否在范围内
图15.15比较函数
图15.16展示了六个基本的比较函数。图右边是比较函数的操作例子,
10
图15.16比较函数例子
图15.16中的梯形图程
序在图15.17中又用CMP函数表达了一遍,该函数
可以使用文本表达式。
11
图15.17使用CMP函数的等价表述
表达式可以被用来做许多复杂运算,如图15.18
所示。表达式将会判断F8:1
是否介于F8:0和F8:2之间。
图15.18一个更加复杂的比较函数
LIM和MEQ函数如图15.19所示。前三个函数
将会判断待检测值是否处在
范围内。如果上限值大于下限值且待测值介于限值之间或者等于限值,那么输
出
为真。如果下限值大于上限值,则只有待测值在范围之外时输出值才为真。
12
地址
N7:0
N7:0
N7:0
N7:0
N7:0
N7:0
十进制(之前值)
二进制(之前值) 二进制(之后值)
1
5
11
15
8
0
0001 0001
0101 0101
1011 1011
1111 1111
1000 1000
0000 1101
图15.19复杂的比较函数
上限
下限
下限上限
图15.20LIM函数的线段表示
图15.20展示的线段可以帮助我们判断待测数值是否在限值内。
在图15.21中使用F
SC指令进行文件与文件的比较也是被允许的。该指令使
用了控制字R6:0。它将解释表达式10次,
做两次比较在每次逻辑扫描中(模式2)。
13
比较为:F8:10
中该模式也会一直执行所有比较。或者当函数前面的
输入为真时就更新增量---
在这种情况下输入为一条线,而一直为真。
FSC
控制
字R6:0
长度10
位置0
模式2
表达式#F8:10
图15:21使用表达式的文件比较
15.3.2布尔函数
图15.22显示的是
布尔代数函数。函数显示从位存储单元获取数据字,执
行一个AND操作,把结果储存在一个新的位逻辑
单元。这些函数都是面向“字”
层面的运算。执行布尔运算的能力,该能力允许不止单一位上的逻辑运算
。
AND(值1,值2,操作数)
OR(值1,值2,操作数)
NOT(值1,值2,操作数)
XOR(值1,值2,操作数)
二进制“与”函数
二进制“或”函数
二进制“非”函数
二进制“异或”函数
图15.22布尔函数
图15.23展示了布尔函数的使用。前三个函数需要两个参数,最后
一个函
数只需要一个参数。与函数只有两个操作数同时为真结果位才会被置ON。或函
数只要两
个操作数中任意一个为ON,那么它就将结果位置ON。异或函数两操作
数中有且仅有一个为ON那么结
果位才会被置ON。非函数将字中所有位取反。
14
附录2:外文原文
Automating Manufacturing Systems
with PLCs
LOGIC FUNCTIONS
Topics:
?
Functions for data handling, mathematics,
conversions, array operations,
statistics,
comparison and Boolean operations.
?
Design examples
Objectives:
? To
understand basic functions that allow calculations
and comparisons
? To understand array
functions using memory files
15.1INTRODUCTION
Ladder logic input contacts and output coils
allow simple logical decisions.
Functions
extend basic ladder logic to allow other types
of control. For example, the
addition of
timers and counters allowed event based
control. A longer list of functions is
shown
in
Figure 15.1. Combinatorial Logic and Event
functions have already been covered.
This
chapter will discuss Data Handling and
Numerical Logic. The next chapter will
cover
Lists and Program Control and some of the
Input and Output functions.
Remaining
functions
will be discussed in later chapters.
15
Combinatorial
Logic
- relay contacts and
coils
Events
- timer instructions
- counter instructions
Data Handling
-
moves
- mathematics
-
conversions
Numerical Logic
- boolean
operations
- comparisons
Lists
- shift registersstacks
-
sequencers
Program Control
-
branchinglooping
- immediate
inputsoutputs
- faultinterrupt
detection
Input and Output
- PID
- communications
- high speed
counters
- ASCII string functions
Figure 15.1 Basic PLC Function Categories
Most of the functions will use PLC memory
locations to get values, store values
and
track function status. Most function will normally
become active when the
input is true. But,
some functions, such as TOF timers, can remain
active when the
input is off. Other functions
will only operate when the input goes from false
to true,
this is known as positive edge
triggered. Consider a counter that only counts
when the
input goes from false to true, the
length of time the input is true does not change
the
function behavior. A negative edge
triggered function would be triggered when the
input goes from true to false. Most functions
are not edge triggered: unless stated
assume
functions are not edge triggered.
NOTE: I do
not draw functions exactly as they appear in
manuals
andprogramming helps save space and
makes the instructions
somewhat easier to read.
All of the necessary information is given.
16
15.2 DATA
HANDLING
15.2.1 Move Functions
There are
two basic types of move functions;
MOV(value,destination) - moves a value to a
memory location
MVM(value,mask,destination) -
moves a value to a memory location, but with a
mask to select specific bits.
The
simple MOV will take a value from one location in
memory and place it in
another memory
location. Examples of the basic MOV are given in
Figure 15.2.
When A is true the MOV function
moves a floating point number from the source to
the destination address. The data in the
source address is left unchanged. When B is
true the floating point number in the source
will be converted to an integer and stored
in
the destination address in integer memory. The
floating point number will be
rounded up or
down to the nearest integer. When C is true the
integer value of 123
will be placed in the
integer file N7:23.
NOTE: when
a function changes a value, except for inputs and
outputs, the value is
changed immediately.
Consider Figure 15.2, if A, B and C are all true,
then the
value in F8:23 will change before
the next instruction starts. This is different
than
the input and output scans that only
happen before and after the logic scan.
17
Figure 15.2
Examples of the MOV Function
A more complex
example of move functions is given in Figure 15.3.
When A
becomes true the first move statement
will move the value of 130 into N7:0. And,
the
second move statement will move the value of -9385
from N7:1 to N7:2. (Note:
The number is shown
as negative because we are using 2s compliment.)
For the
simple MOVs the binary values are not
needed, but for the MVM statement the binary
values are essential. The statement moves the
binary bits from N7:3 to N7:5, but only
those
bits that are also on in the mask N7:4, other bits
in the destination will be left
untouched.
Notice that the first bit N7:50 is true in the
destination address before and
after, but it
is not true in the mask. The MVM function is very
useful for applications
where individual
binary bits are to be manipulated, but they are
less useful when
dealing with actual number
values.
18
15.2.2 Mathematical Functions
Mathematical functions will retrieve one or
more values, perform an operation
and
store the result in memory. Figure 15.4 shows
an ADD function that will retrieve
values from
N7:4 and F8:35, convert them both to the type of
the destination address,
add the floating
point numbers, and store the result in F8:36. The
function has two
sources labelled source A and
source B. In the case of ADD functions the
sequence
can change, but this is not true for
other operations such as subtraction and division.
A
list of other simple arithmetic function
follows. Some of the functions, such as the
negative function are unary, so there is only
one source.
19
Figure 15.4 Arithmetic Functions
An
application of the arithmetic function is shown in
Figure 15.5. Most of the
operations provide
the results we would expect. The second ADD
function
retrieves a
value from N7:3, adds
1 and overwrites the source - this is normally
known as an
increment operation. The first DIV
statement divides the integer 25 by 10, the result
is
rounded to the nearest integer, in this
case 3, and the result is stored in N7:6. The
NEG instruction takes the new value of -10,
not the original value of 0, from N7:4
inverts
the sign and stores it in N7:7.
20
Figure 15.5 Arithmetic
Function Example
A list of more advanced
functions are given in Figure 15.6. This list
includes
basic
trigonometry functions,
exponents, logarithms and a square root function.
The
last function CPT will accept an
expression and perform a complex calculation.
21
Figure 15.6
Advanced Mathematical Functions
Figure
15.7 shows an example where an equation has been
converted to ladder
logic. The first step in
the conversion is to convert the variables in the
equation
to unused memory locations in the
PLC. The equation can then be converted using the
most nested calculations in the equation, such
as the LN function. In this case the
results
of the LN function are stored in another memory
location, to be recalled later.
The other
operations are implemented in a similar manner.
(Note: This equation could
have been
implemented in other forms, using fewer memory
locations.)
22
Figure 15.7 An Equation in Ladder Logic
The same equation in Figure 15.7 could have
been implemented with a CPT
function as shown
in Figure 15.8. The equation uses the same memory
locations
chosen in Figure 15.7. The
expression is typed directly into the PLC
programming
software.
Figure 15.8
Calculations with a Compute Function
Math
functions can result in status flags such as
overflow, carry, etc. care must
be
taken
to avoid problems such as overflows. These
problems are less common
when using floating
point numbers. Integers are more prone to these
problems
because they are limited to the range
from -32768 to 32767.
23
15.2.3 Conversions
Ladder logic conversion
functions are listed in Figure 15.9. The example
function
will retrieve a BCD number from
the D type (BCD) memory and convert it to a
floating point number that will be stored in
F8:2. The other function will convert from
2s
compliment binary to BCD, and between radians and
degrees.
Figure 15.9 Conversion Functions
Examples of the conversion functions are
given in Figure 15.10. The functions
load in a
source value, do the conversion, and store the
results. The TOD
conversion to BCD could
result in an overflow error.
24
Figure 15.10 Conversion
Example
15.2.4 Array Data Functions
Arrays allow us to store multiple data values.
In a PLC this will be a sequential
series of
numbers in integer, floating point, or other
memory. For example,
assume we are measuring
and storing the weight of a bag of chips in
floating point
memory starting at #F8:20 (Note
the ’#’ for a data file). We could read a weight
value
every 10 minutes, and once every hour
find the average of the six weights. This
section will focus on techniques that
manipulate groups of data organized in arrays,
also called blocks in the manuals.
15.2.4.1 - Statistics
Functions are
available that allow statistical calculations.
These functions are
25
listed in Figure 15.11. When A becomes true
the average (AVE) conversion will
start at
memory location F8:0 and average a total of 4
values. The control word R6:1
is used to keep
track of the progress of the operation, and to
determine when the
operation is complete. This
operation, and the others, are edge triggered. The
operation may require multiple scans to be
completed. When the operation is done the
average will be stored in F8:4 and the R6:1DN
bit will be turned on.
Figure 15.11
Statistic Functions
Examples of the
statistical functions are given in Figure 15.12
for an array of
data
that starts at F8:0
and is 4 values long. When done the average will
be stored in
F8:4, and the standard deviation
will be stored in F8:5. The set of values will
also be
sorted in ascending order from F8:0 to
F8:3. Each of the function should have their
own control memory to prevent overlap. It is
not a good idea to activate the sort and
the
other calculations at the same time, as the sort
may move values during the
calculation,
resulting in incorrect calculations.
26
15.2.4.2 - Block
Operations
A basic block function is shown in
Figure 15.13. This COP (copy) function will
copy an array of 10 values starting at N7:50
to N7:40. The FAL function will perform
mathematical operations using an expression
string, and the FSC function will
allow two
arrays to be compared using an expression. The FLL
function will fill a
block of memory with a
single value.
27
Figure 15.13 Block Operation Functions
Figure 15.14 shows an example of the FAL
function with different addressing
modes. The
first FAL function will do the following
calculations N7:5=N7:0+5,
N7:6=N7:1+5,
N7:7=N7:2+5, N8:7=N7:3+5, N7:9=N7:4+5. The second
FAL
statement does not have a file ’#’ sign in
front of the expression value, so the
calculations will be N7:5=N7:0+5, N7:6=N7:0+5,
N7:7=N7:0+5, N8:7=N7:0+5,
N7:9=N7:0+5. With a
mode of 2 the instruction will do two of the
calculations for
every scan where B is true.
The result of the last FAL statement will be
N7:5=N7:0+5,
N7:5=N7:1+5, N7:5=N7:2+5,
N7:5=N7:3+5, N7:5=N7:4+5. The last operation
would seem to be useless, but notice that the
mode is incremental. This mode will do
one
calculation for each positive transition of C. The
all mode will perform all five
calculations in
a single scan. It is also possible to put in a
number that will indicate the
number of
calculations per scan. The calculation time can be
long for large arrays and
trying to do all of
the calculations in one scan may lead to a
watchdog time-out fault.
28
15.3 LOGICAL FUNCTIONS
15.3.1 Comparison of Values
Comparison
functions are shown in Figure 15.15. Previous
function blocks were
outputs, these replace
input contacts. The example shows an EQU (equal)
function that compares two floating point
numbers. If the numbers are equal, the
output
bit B3:51 is true, otherwise it is false. Other
types of equality functions are
also listed.
29
Figure 15.15
Comparison Functions
The example in Figure
15.16 shows the six basic comparison functions. To
the
right of the figure are examples of the
comparison operations.
Figure 15.16
Comparison Function Examples
The ladder
logic in Figure 15.16 is recreated in Figure 15.17
with the CMP
function
that allows text
expressions.
30
Figure 15.17 Equivalent Statements Using CMP
Statements
Expressions can also be used to do
more complex comparisons, as shown in
Figure
15.18. The expression will determine if F8:1 is
between F8:0 and F8:2.
Figure 15.18 A
More Complex Comparison Expression
The LIM and
MEQ functions are shown in Figure 15.19. The first
three
functions will compare a test value to
high and low limits. If the high limit is above
the low limit and the test value is between or
equal to one limit, then it will be true. If
the low limit is above the high limit then the
function is only true for test values
outside
the range. The masked equal will compare the bits
of two numbers, but only
those bits that are
true in the mask.
31
Figure 15.19 Complex Comparison Functions
Figure 15.20 shows a numberline that helps
determine when the LIM function
will be true.
32
Figure 15.20 A
Number Line for the LIM Function
File to
file comparisons are also permitted using the FSC
instruction shown in
Figure 15.21. The
instruction uses the control word R6:0. It will
interpret the
expression 10 times, doing two
comparisons per logic scan (the Mode is 2). The
comparisons will be F8:10
output
A will then be true. The mode could have also been
All to execute all the
comparisons in one
scan, or Increment to update when the input to the
function is true
- in this case the input is a
plain wire, so it will always be true.
Figure 15.21 File Comparison Using Expressions
15.3.2 Boolean Functions
Figure 15.22
shows Boolean algebra functions. The function
shown will obtain
data words from bit memory,
perform an and operation, and store the results in
a
new location in bit memory. These functions
are all oriented to word level operations.
The
ability to perform Boolean operations allows
logical operations on more than a
single bit.
33
Figure 15.22
Boolean Functions
The use of the Boolean
functions is shown in Figure 15.23. The first
three
functions require two arguments, while
the last function only requires one. The AND
function
will only turn on bits in the
result that are true in both of the source words.
The OR
function will turn on a bit in the
result word if either of the source word bits is
on. The XOR
function will only turn on a bit
in the result word if the bit is on in only one of
the source words.
The NOT function reverses
all of the bits in the source word.
34