基于PLC的自动化制造系统外文翻译、中英文翻译、外文文献翻译_第1页
基于PLC的自动化制造系统外文翻译、中英文翻译、外文文献翻译_第2页
基于PLC的自动化制造系统外文翻译、中英文翻译、外文文献翻译_第3页
基于PLC的自动化制造系统外文翻译、中英文翻译、外文文献翻译_第4页
基于PLC的自动化制造系统外文翻译、中英文翻译、外文文献翻译_第5页
已阅读5页,还剩31页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

届本科毕业设计 (论文 )外文 文献翻译 学 院: 专 业: 姓 名: 学 号: 外文出处: Automating Manufacturing Systems with PLCs 附 件: 1、外文翻译 2、外文原文 1 附录 1:外文资料翻译译文 基于 PLC 的自动化制造系统 15.梯形图逻辑函数 主题: 数据处理、 数学运算 、 数据转换 、 阵列操作 、 统计 、 比较 、 布尔量运算等函数 设计实例 宗旨: 理解基本函数 ,允许计算和比较 了解使用了内存文件的数组函数 15.1 介绍 梯行图逻辑输入触点和输出线圈之间允许简单的逻辑 判断。这些函数把基本的梯形图逻辑延伸到其他控制形式中。例如,附加的定时器和计数器允许基于事件的控制。在下图 15.1 中有一个较长的关于这些函数的表。这包括了组合逻辑和事件函数。 本章将会 研究数据处理和数值的逻辑 。 下一章将介绍表、程序控制和一些输入和输出函数。剩下的函数会在后面的章节中讨论 图 15.1 基本 PLC 函数分类 组合逻辑函数 继电器触点 线圈 事件函数 计时显示 计数显示 数据处理函数 移动 数学运算 转换 数字逻辑函数 布尔量运算 比较 列表函数 转移入栈 /出栈 序列发生器 程序控制函数 分支 /循环 立即输入 /输出 错误 /中断检测 输入输出函数 PID 通讯 高速计数器 字符串函数 2 大多数的函数会使用 PLC 的存储单元获取值 、 储存值和跟踪函 数状态。一般大部分函数当输入值是“真”时,会被激活。但是,有些函数,如延时断开定时器,可以在无输入时,保持激活状态。其它的函数仅当输入由“假”变“真”时,才会被执行,这就是所谓的上升沿触发。想想,一计数器仅仅是输入由“假”变“真”时才会计数,输入为“真”状态的持续时间并不影响函数动作。而下降沿触发函数仅当输入由“真”变“假”时才会触发。多数函数并非边沿触发:除非有规定说明函数不是边沿触发。 标签:我并没有像说明书或者软件里那样准确的画出这些函数。因为 这样会节省空间并且易于阅读,但是所有的必要信息我都给出了 。 15.2 数据处理 15.2.1 传递函数 有两种基本的传递函数; MOV(值 ,操作数 ) -把值传递到指定的存储位置。 MVM(值 ,标号 ,操作数 ) -把值传递到指定的存储位置,但是用标号来指定一个传递的位。 这个 MOV 函数从一个存储空间取出一个值放置到另外一个存储空间里。下图 15.2 给出了 MOV 的基本用法。当 A 为“真”, MOV 函数把一个浮点数从原操作数传递到操作数存储位置。原操作数地址中的数据没有改变。当 B 为“真”时,原操作数中的浮点数将被转换成整数存储在操作数存储区中。浮点数会被四舍五入成整数。当 C 为“真”时,整数“ 123”将被存储在整数文件 N7:23 中。 M O V原 操 作 数 F 8 : 0 7操 作 数 N 7 : 2 3M O V原 操 作 数 1 2 3操 作 数 N 7 : 2 3M O V原 操 作 数 F 8 : 0 7操 作 数 F 8 : 2 3 标签:当函数值改变时,除了输入与输出,其值是瞬间改变的。试想: 3 图 15.2 中,如果 ABC 都为“真”,那么 F8:23 的值将会在下一个指令到来前 就变化。这与输入输出扫描只发生在逻辑扫描之前或者之后不同。 图 15.2 MOV 的基本用法 下图 15.3 给出了更多更复杂的 MOV 函数用法。当 A 为“真”时,第一个模块将会把值“ 123”送入 N7:0,同时第二个模块将会把值“ -9385”从 N7:1 送到 N7:2 中(这个值之所以为负数,是因为我们使用了 2S 的 compliment)。对于基本的 MOV 函数使用中,二进制数值不是必要的;但是在 MVM 函数中,二进制数值却是必要的。这个模块中从 N7:3 移动二进制数值到 N7:5 中。 但是这些“位”在 N7:4 中仍为“ ON”, 操作数的其他位将不会受到影响 。请注意:N7:5 的第一位 N7:5/0 在指令执行前后仍为“ ON” ,但是在 N7:4 中却不同, MVM函数当应用在个别二进制位的处理中时非常有用,但是处理实数却是用处不大了。 M O V原 操 作 数 1 3 0d e s t N 7 : 0M O V原 操 作 数 N 7 : 1d e s t N 7 : 2M V M原 操 作 数 N 7 : 3标 号 N 7 : 4d e s t N 7 : 5M V M原 操 作 数 N 7 : 3标 号 N 7 : 4d e s t N 7 : 6 之前数 据 之后数据 地址 二进制 十进制 二进制 十进制 N7:0 B#0000000000000000 0 B#0000000010000010 130 N7:1 B#1101101101010111 -9385 B#1101101101010111 -9385 N7:2 B#1000000000000000 -32768 B#1101101101010111 -9385 N7:3 B#0101100010111011 22715 B#1101100010111011 -10053 N7:4 B#0010101010101010 10922 B#0010101010101010 10922 N7:5 B#0000000000000001 1 B#00001000101010 2219 N7:6 B#1101110111111111 B#1101110111111111 4 标签:标号的概念非常重要,并且也可以用在其他函数中。标号允许指令改变一个二进制数据的其中四位,而不用改变它的全部数值。当你 使用二进制数据中的位来表示声明,模式或者状态等内容时,你会很希望这么做。图 15.3 是 MOV 和MVM 函数对二进制数值的操作例子 图 15.3MOV 和 MVM 函数的使用实例 15.2.2 数学函数 数学函数将检索一个或多个值 ,执行一个操作然后把结果储存在内存中。图 15.4 展示的是一个 ADD 函数从 N7:4 和 F8:35 中读取数据操,把他们转换成操作数的地址格式,把两个浮点数相加,结果储存在 F8:36 中。该函数有两个原操作数记做“原操作数 A” 、 “原操作数 B”。对于该函数来说原操作数顺序可以改变,但是这对于“减法函数”或 “除法函数”等其他操作来说却不一定正确,下面列出了其他一些基本的数学函数。其中的一些,如“取负”是一元的函数,也就是说它只有一个原操作数。 加原 操 作 数 A N 7 : 0 4原 操 作 数 B F 8 : 3 5操 作 数 F 8 : 3 6 加(值 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,结果四舍五入 5 为最接近的整数,这时,结果被储存在 N7:6 中。 NEG 指令取走了新数“ -10”,而不是源数据“ 0”,从 N7:4 取出的数 据符号被取反,结果存入 N7:7。 地址 之前值 之后值 N7:0 10 10 N7:1 25 25 N7:2 0 35 N7:3 0 1 N7:4 0 -10 N7:5 0 250 N7:6 0 3 N7:7 0 10 N7:8 100 0 F8:0 10.0 10.0 F8:1 25.0 25.0 F8:2 0 2.5 F8:3 0 2.5 图 15.5 数学函数例子 标签:调用,整数范围从 -32768 到 32767 并且没有小数。 图 15.6 列出了更多的高级函数 。这个列表包括基本的三角函数 、 取绝对值函数 、 对数函数 、 取二次方根函数。最后一个函数 CPT 能接受表达式并且可以执行一个复杂的运算。 ACS(值 ,操作数 ) - 反余弦 COS(值 ,操作数 ) - 余弦 ASN(值 ,操作数 ) - 反正弦 SIN(值 ,操作数 ) - 正弦 ATN(值 ,操作数 ) -反正切 TAN(值 ,操作数 ) - 正切 6 XPY(值 1,值 2,操作数 ) - X 的 Y 次幂 LN(值 ,操作数 ) - 自然对数 LOG(值 ,操作数 ) - 以 10 为底的对数 SQR(值 ,操作数 ) - 开二次方根 CPT(操作数 ,表达式 ) - 做运算 图 15.6 高级数学函数 图 15.7 展示的是把表达式转化成梯形图逻辑。转换的第一步是把表达式的变量存入 PLC 中没被使用过的存储区中。接下来拥有很多嵌套运算的方程就可以被转化,例如 LN 函数。这时 LN 函数的运算结果被保存在其他存储空间中,之后会被调用。其它的一些操作会应用在相似的情况下。(注意:这些方程可能应用在其他场合中,占用更少的存储空间。) 给 定 方 程指 定 存 储 图 15.7 用梯形图表示的方程 和图 15.7 中一样的方程被应用于图 15.8 所 示的 CPT 函数中。存储区也和上 7 图使用的一样。该表达式被直接输进了 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 码将会出现“溢出”错误。 8 地址 之前值 之后值 N7:0 0 1793 N7:1 548 548 F8:0 3.141 3.141 F8:1 45 45 F8:2 0 180 F8:3 0 0.785 D9:0 0000 0000 0000 0000 0000 0101 0100 1000 D9:1 0001 0111 1001 0011 0001 0111 1001 0011 图 15.10 转换例子 15.2.4 矩阵函数 矩阵可以储存多列数据。在 PLC 中这将是一系列的整数数字,浮点数或者 其它类型的数 据。例如,假定我们测量和保存一块封装芯片的重量时要使用浮点数存储区 F8:20。每十分钟要读取一次重量数据,并且一小时后找出平均重量。这一节我们将聚焦于矩阵中多组数据的处理技术,也就是说明书中所谓的“块”。 15.2.4.1-统计 这些函数也是可以处理统计数据的。图 15.11 列出了这些函数,当 A 变为“真” AVE 函数的转换操作从存储区 F8:0 开始,并算出四个数的平均值。控制字 R6:1 被用来跟踪运算的进程,并判断运算何时结束。这些运算还有其它的一些是边沿触发的。该次运算可能会需要经过多个扫描周期才能完成。运算结束 后,平均值被储存在 F8:0 中,同时 R6:1/DN 位被置 ON。 图 15.11 统计函数 AVE(开始值 ,操作数 ,控制字 ,长度 ) 求平均值 STD(开始值 ,操作数 ,控制字 ,长度 ) 求标准差 SRT(开始值 ,控制字 ,长度 ) 排列一串值 9 如图 15.12 给出的统计函数例子,它拥有一个有四个字长从 F8:0 开始的数组数据。每次执行平均值运算的结果储存在 F8:4 中,标准差 储存在 F8:5 中。一系列数值被存放在从 F8:0 到 F8:3 的按升序排列的存储区中。为防止出现数据覆盖现象,每个函数都应该有自己的控制存储器。同时触发该函数与其他运算不是一个明智的选择,因为在计算期间该函数会移动数据,这会导致错误的结果。 地址 之前 A 导通后 B 导通后 C 导通后 F8:0 3 3 3 1 F8:1 1 1 1 2 F8:2 2 2 2 3 F8:3 4 4 4 4 F8:4 0 2.5 2.5 2.5 F8:5 0 0 1.29 1.29 图 15.12 统计运算 旁白:这些函 数允许 SPC(统计)数据控制中的实数运算。仅 有的不是这样的 PLC 函数是随机函数,它允许出现随机样本数据。 15.2.4.2-块操作 图 15.13 给出了最基本的块函数。这个 COP 函数将会拷贝从 N7:50 到 N7:40拥有十个数据的数组。 FAL 函数将会通过一个表达式执行数学运算。 FSC 函数通过使用表达式允许数组之间进行比较。 FLL 函数会利用一个数据把块存储区填充起来。 10 COP(开始值 ,操作数 ,长度 ) 拷贝一个数据块 FAL(控制字 ,长度 ,模式 ,操作数 ,表达式 ) 为得到一个多重值而执行基本的数学运算 FSC(控制字 ,长度 ,模式 ,操作数 ,表达式 ) 为得到一个多重值而作一个比较 FLL(值 ,操作数 ,长度 ) 把一个单一值拷贝到一个数据块 图 15.13 块操作函数 图 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个操作一次。 用来指示每次扫描运算的编号,而插入一个号码也是有可能的。由于有较大的数组, 运算时间可能会很长,同时尝试每次扫描时执行所有运算也将会导致看门狗超时错误。 11 图 15.14 文本代数函数例子 15.3 逻辑函数 15.3.1 数值比较 图 15.15 所示为比较函数,先前的函数块是输出,它取代了输入联系。例子展示的是比较两个浮点数大小的函数 EQU。如果数值相当,则输出位 B3:5/1 为真,否则为假。其他形式的相等函数也裂了出来。 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 展示了六个基本的比较函数。图右边是比较函数的操作例子, 12 图 15.16 比较函数例子 图 15.16 中的梯形图程序在图 15.17 中又用 CMP 函数表达了一遍,该函数可以使用文本表达式。 13 图 15.17 使用 CMP 函数的等价表述 表达式可以被用来做许多复杂运算,如图 15.18 所示。表达式将会判断 F8:1是否介于 F8:0 和 F8:2 之间。 图 15.18 一个更加复杂的比较函数 LIM 和 MEQ 函数如图 15.19 所示。前三个函数将会判断待检测值是否处在范围内。如果上限值大于下限值且待测值介于限值之间或者等于限值,那么输出为真。如果下限值大于上限值,则只有待测值在范围之外时输出值才为真。 14 地址 十进制(之前值) 二进制(之前值) 二进制(之后值) N7:0 1 0000000000000001 0000000000000001 N7:0 5 0000000000000101 0000000000000101 N7:0 11 0000000000001011 0000000000001011 N7:0 15 0000000000001111 0000000000001111 N7:0 8 0000000000001000 0000000000001000 N7:0 0 0000000000000000 0000000000001101 图 15.19 复杂的比较函数 上 限下 限 上 限下 限 图 15.20LIM 函数的线段表示 图 15.20 展示的线段可以帮助我们判断待测数值 是否在限值内。 在图 15.21中使用 FSC指令进行文件与文件的比较也是被允许的。该指令使用了控制字 R6:0。它将解释表达式 10次,做两次比较在每次逻辑扫描中(模式 2)。 15 比较为: F8:10F8:0 , F8:11F8:0 然后 F8:12F8:0 , F8:13F8:0 然后 F8:14F8:0 , F8:15F8:0 然后 F8:16F8:0 , F8:17F8:0 然后是 F8:18F8:0 , F8:19F8:0 。函数将会继续执行除非发现一个错误状态或者完成比较。如果比较完成没有 发现错误状态那么输出 A将为“真”。在一个扫描周期中该模式也会一直执行所有比较。或者当函数前面的输入为真时就更新增量 -在这种情况下输入为一条线,而一直为真。 F S C控 制 字 R 6 : 0长 度 1 0位 置 0模 式 2表 达 式 # F 8 : 1 0 F 8 : 0 图 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。非函数将字中所有位取反。 16 附录 2:外文原文 Automating Manufacturing Systems with PLCs 15.LADDER 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. 17 C o m b i n a t o r i a l L o g i c - r e l a y c o n t a c t s a n d c o i l sE v e n t s - t i m e r i n s t r u c t i o n s - c o u n t e r i n s t r u c t i o n sD a t a H a n d l i n g - m o v e s - m a t h e m a t i c s - c o n v e r s i o n sN u m e r i c a l L o g i c - b o o l e a n o p e r a t i o n s - c o m p a r i s o n sL i s t s - s h i f t r e g i s t e r s / s t a c k s - s e q u e n c e r sP r o g r a m C o n t r o l - b r a n c h i n g / l o o p i n g - i m m e d i a t e i n p u t s / o u t p u t s - f a u l t / i n t e r r u p t d e t e c t i o nI n p u t a n d O u t p u t - P I D - c o m m u n i c a t i o n s - h i g h s p e e d c o u n t e r s - A S C I I s t r i n g f u n c t i o n s 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. N O T E : I d o n o t d r a w f u n c t i o n s e x a c t l y a s t h e y a p p e a r i n m a n u a l sa n d p r o g r a m m i n g s o f t w a r e . T h i s h e l p s s a v e s p a c e a n d m a k e s t h e i n s t r u c t i o n ss o m e w h a t e a s i e r t o r e a d . A l l o f t h e n e c e s s a r y i n f o r m a t i o n i s g i v e n . 18 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. N O T E : w h e n a f u n c t i o n c h a n g e s a v a l u e , e x c e p t f o r i n p u t s a n d o u t p u t s , t h e v a l u e i s c h a n g e d i m m e d i a t e l y . C o n s i d e r F i g u r e 1 5 . 2 , i f A , B a n d C a r e a l l t r u e , t h e n t h e v a l u e i n F 8 : 2 3 w i l l c h a n g e b e f o r e t h e n e x t i n s t r u c t i o n s t a r t s . T h i s i s d i f f e r e n t t h a n t h e i n p u t a n d o u t p u t s c a n s t h a t o n l y h a p p e n b e f o r e a n d a f t e r t h e l o g i c s c a n . 19 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:5/0 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. 20 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. 21 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. 22 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. 23 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.) 24 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. 25 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. 26 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 27 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:1/DN 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. 28 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. 29 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. 30 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:5/1 is true, otherwise it is false. Other types of equality functions are also listed. 31 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. 32 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 1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论