Math Instructions / 运算指令

Let's now look at using some basic math functions on our data. Many times in our applications we must execute some type of mathematical formula on our data. It's a rare occurrence when our data is actually exactly what we needed.

现在让我们看看如何在数据上使用一些基本的数学函数。很多时候,在我们的应用程序中,我们必须对数据执行某种类型的数学公式;但当我们的数据确实是我们所需要的类型的时候,我们也不一定要用到运算指令。

As an example, let's say we are manufacturing widgets. We don't want to display the total number we've made today, but rather we want to display how many more we need to make today to meet our quota. Lets say our quota for today is 1000 pieces. We'll say X is our current production. Therefore, we can figure that 1000-X=widgets left to make. To implement this formula we obviously need some math capability.

举个例子,假设我们在生产小部件,我们不想显示我们今天完成的总数,但是我们想显示我们今天需要完成多少才能达到我们的配额。假设我们今天的配额是1000件,我们当前的产量是X,那么,我们可以计算出我们还需要完成多少才能达到我们的配额,即还需要完成的小部件数量是1000-X。显然,为了实现这个公式,我们需要一些数学运算能力。

In general, PLCs almost always include these math functions:

一般来说,PLC通常包括以下这些数学运算功能:Addition- The capability to add one piece of data to another. It is commonly called ADD.

加法 - 将一段数据与另一段数据相加的功能,它通常被称为ADD。

Subtraction- The capability to subtract one piece of data from another. It is commonly called SUB.

减法 - 从一个数据中减去另一个数据的能力,它通常被称为SUB。

Multiplication- The capability to multiply one piece of data by another. It is commonly called MUL.

乘法 - 将一段数据乘以另一段数据的能力,它通常被称为MUL。

Division- The capability to divide one piece of data from another. It is commonly called DIV.

除法- 将一个数据与另一个数据进行相除的能力,它通常被称为DIV。

As we saw with the MOV instruction there are generally two common methods used by the majority of plc makers. The first method includes a single instruction that asks us for a few key pieces of information. This method typically requires:

正如我们在MOV指令中讲到的,大多数PLC制造商通常使用两种常用的方法。第一个方法包含一条指令,它要求我们提供一些关键信息。这种方法通常需要:Source A - This is the address of the first piece of data we will use in our formula. In other words it's the location in memory of where the first "number" is that we use in the formula.

源A - 这是我们将在我们的公式中使用的第一数据块的地址。换句话说,它是我们在公式中使用的第一个“数字”在内存中的位置。

Source B- This is the address of the second piece of data we will use in our formula. In other words it's the location in memory of where the second "number" is that we use in the formula. -NOTE: typically we can only work with 2 pieces of data at a time. In other words we can't work directly with a formula like 1+2+3. We would have to break it up into pieces. Like 1+2=X then X+3= our result.

源B - 这是我们将在公式中使用的第二数据块的地址。换句话说,它是我们在公式中使用的第二个“数字”在内存中的位置。注意:通常我们一次只能处理2个数据。换句话说,我们不能直接用1+2+3这样的公式,我们得把它拆成碎片,比如1+2=X,然后X+3=结果。

Destination- This is the address where the result of our formula will be put. For example, if 1+2=3, (I hope it still does!), the 3 would automatically be put into this destination memory location.

结果 - 这是我们的计算公式的结果将被存放的地址。例如,如果1+2=3,3将自动放入这个目标内存位置。ADD symbol / ADD指令符号

The instructions above typically have a symbol that looks like that shown above. Of course, the word ADD would be replaced by SUB, MUL, DIV, etc. In this symbol, The source A is DM100, the source B is DM101 and the destination is DM102. Therefore, the formula is simply whatever value is in DM100 + whatever value is in DM101. The result is automatically stored into DM102.

上面的指令通常有一个类似于上面所示的符号。当然,ADD这个指令会被替换为SUB、MUL、DIV等。在这个符号中,源A的地址是DM100,源B的地址是DM101,计算结果的地址是DM102。因此,公式就是DM100中的任何值+ DM101中的任何值,计算结果自动存储到DM102中。

Shown above is how to use math functions on a ladder diagram. Please note that once again we are using a one-shot instruction. As we've seen before, this is because if we didn't use it we would execute the formula on every scan. Odds are good that we'd only want to execute the function one time when input 0000 becomes true. If we had previously put the number 100 into DM100 and 200 into DM101, the number 300 would be stored in DM102.(i.e. 100+200=300, right??)

上图显示的是如何在梯形图上使用数学运算函数。请注意,我们再次使用上升沿指令DIFU。正如我们之前看到的,这是因为如果我们不使用它,程序每次扫描时都会执行一次这个公式。当输入0000为“真”(True)时,我们只希望执行一次这个运算函数,这种功能是很常用的。如果我们预先将数字100放入地址DM100,将数字200放入地址DM101,那么数字300将被存储在地址DM102中。(100+200=300,对吧?)ADD symbol (dual method) / ADD指令符(用于双指令方式)

The dual instruction method would use a symbol similar to that shown above. In this method, we give this symbol only the Source B location. The Source A location is given by the LDA instruction. The Destination would be included in the STA instruction.

双指令方法将使用类似于上图所示的符号。在这个方法中,ADD指令只给出这个符号的源B地址DM101,源A的地置DM100由LDA指令给出,结果的地址DM102将包括在STA指令中。

Shown above is a ladder diagram showing what we mean.

上图是双指令方法的梯形图。

The results are the same as the single instruction method shown above.

其计算结果和上面所讲单指令的计算结果是一样的。

In the example above, data memory 102 (DM102) initially holds the constant (number) 0000. Each time the operator pushes button 0000 the difu instruction will turn on (become true) FOR ONE SCAN. When this happens we load the value(number) in DM100(100) and add it to the value(number) in DM101(200). The result, 300 in this example (100+200=300) is then stored in DM102(300).

在上面的示例中,数据内存102 (DM102)最初保存的常量(数字)是0。每次操作员按下0000按钮,DIFU指令就会打开(变为“真”)一个扫描周期,当发生这种情况时,我们加载DM100中的值(数字)100并将其与DM101中的值(数字)200相加。其结果,本例中的300(100+200=300)存储到DM102中去。

What would happen if we had a result that was greater than the value that could be stored in a memory location?

如果计算结果大于存储器可以存储的最大值,会发生什么情况呢?

Typically the memory locations are 16-bit locations. (more about number types in a later chapter) In plain words this means that if the number is greater than 65535 (2^16=65536) it is too big to fit. Then we get what's called an overflow. Typically the plc turns on an internal relay that tells us an overflow has happened. Depending on the plc, we would have different data in the destination location. (DM102 from example) Most PLCs put the remainder here.

通常,内存地址是16位的地址(关于数字类型的更多内容将在后面的章节中介绍)。简单地说,这意味着如果数字大于65535(2^16=65536),那么它就太大了,寄存器无法容纳。然后我们得到了所谓的溢出。通常,这时候PLC会打开内部继电器,告诉我们发生了溢出。根据PLC的不同,我们在目标地址(比如DM102)会有不同的数据,大多数PLC将其余数放在这里。

Some use 32-bit math which solves the problem. (except for really big numbers!) If we're doing division, for example, and we divide by zero (illegal) the overflow bit typically turns on as well. Suffice it to say, check the overflow bit in your ladder and if its true, plan appropriately.

一些使用32位的运算来解决这个问题(除非是非常大的数字!)。例如,如果我们在做除法,然后除以0(非法),溢出位通常也会打开。我只想说,检查一下你的梯形图上是否有溢出的部分,如果是的话,适当地规划一下,可以设计成报警输出。

Many PLCs also include other math capabilities. Some of these functions could include:

许多PLC还包括其他一些数学运算功能。其中一些功能可能包括:Square roots / 平方根

Scaling

Absolute value / 绝对值

Sine / 正弦

Cosine / 余弦

Tangent / 正切

Natural logarithm / 自然对数

Base 10 logarithm / 以10为底的对数

X^Y (X to the power of Y) / X的Y次方

Arcsine (tan, cos) / 反正弦

and more....check with the manufacturer to be sure. / 还有其他的请查询用户手册

Some PLCs can use floating point math as well. Floating point math is simply using decimal points. In other words, we could say that 10 divided by 3 is 3.333333 (floating point). Or we could say that 10 divided by 3 is 3 with a remainder of 1(long division). Many micro/mini PLCs don't include floating point math. Most larger systems typically do.

一些PLC也可以使用浮点数。浮点数学就是简单地使用小数点,换句话说,我们可以说10除以3等于3.333333(浮点数)或者我们可以说10除以3等于3余数是1(长除法),许多迷你PLC不包括浮点运算,但大多数大型系统通常都会有浮点运算功能。

Understand the theory and we can always learn how our manufacturer of choice does it.

理解这个理论,我们就可以知道如何选择我们所需类型的PLC。

lda指令是什么意思_PLC基本知识 -- 5.1 运算指令 (顺便学英文)相关推荐

  1. 软件测试基础知识面试题目(25题英文题目)

    软件测试基础知识面试题目(25题英文题目) 1. Verification is:  a. Checking that we are building the right system b. Chec ...

  2. 用知识图谱实现可拓学例子

    可拓学例子1: 曹冲年龄五六岁的时候,知识和判断能力如一个成年人.有一次,孙权送来了一头巨象,曹操想知道这象的重量,询问他的属下这件事,但他们都不能说出称象的办法.曹冲说:"把象放到大船上, ...

  3. 电气自动化专业里的计算机知识,为什么说千万别学电气自动化?哪些人适合学电气自动化?...

    选择科目 测一测我能上哪些大学 选择科目 领取你的专属报告 > 选择省份 关闭 请选择科目 确定 v> 随着技术的不断发展,电气工程逐渐有了长足性的发展,各行各业里都涉及到了电气工程,如信 ...

  4. 平面设计基础知识,平面设计入门先学什么:夏雨老师

    平面设计基础知识,平面设计入门先学什么,这两个问题可能困扰着我们很多朋友,因为想学平面设计的朋友都想知道基础知识,和入门先学什么,我就给大家来讲讲这两个问题吧. 平面设计基础知识:平面设计内容的理解是 ...

  5. zrst指令是什么意思_PLC成批复位指令ZRST

    PLC成批复位指令ZRST 2018-11-27 14:29 PLC成批复位指令ZRST 2个指定的软元件之间执行成批复位的指令. 用于在中断运行后从初期开始运行时,以及对控制数据进行复位时. 功能和 ...

  6. lda指令是什么意思_arm指令,我知道ldr是什么 ldrd是什么

    匿名用户 1级 2016-03-12 回答 1,ldr加载指令 LDR指令的格式为: LDR{条件} 目的寄存器, LDR指令用亍从存储器中将一个32位的字数据传送到目的寄存器中.该指令通常用亍从存储 ...

  7. 超强Python入门基础知识总结!是时候学起来了

    图源:unsplash 我们如今的生活离不开手机.电脑和其他一些智能设备了,但你知道它们离不开什么吗?如果没有程序的存在,这些将什么都不是. 计算机编程是一种教计算机执行任务的神奇艺术,这是现代社会最 ...

  8. 小学计算机趣味知识,小学生电脑课上都学哪些知识和操作?

    满意答案 1;作为课程教育阶段的标志:1985年全国24所重点中学开设BAsIC语言课程,并由此引发全国大.中.小幼各级学校的BAsIC浪潮.近年来在中国兴起的中小学生学习计算机热,也同样面对这两个问 ...

  9. 关于MySQL索引知识与小妙招 — 学到了!

    一.索引基本知识 1.1 索引的优点 大大减少了服务器需要扫描的数据量,加快数据库的检索速度 帮助服务器避免排序和临时表 将随机io变成顺序io 1.2 索引的用处 速查找匹配WHERE子句的行 从c ...

最新文章

  1. 【Qt】QtCreator中的单例编程(以ActionManager为例)
  2. 刷新table数据_经典 - 一文轻松看懂数据透视表
  3. Linux网络常用工具分类介绍
  4. 穷学计算机富学金融家里有矿,穷学IT,富学金融?亲身体验告诉你IT真的是一个不用拼爹的行业...
  5. matlab的开方算法_正确的「记事本」打开方式:能渲染3D图像,还能玩贪吃蛇
  6. EXCEL_CLASS
  7. 股市孙子兵法(收藏)
  8. 【设计模式】C++单例模式
  9. android studio发布apk流程
  10. Branch management
  11. python中unicode函数_中文字符 unicode转utf-8函数 python实现
  12. 无法打开文件“libboost_system-vc110-mt-gd-x32-1_68.lib”
  13. javamailsender注入失败_springboot拦截异常信息发送邮件提醒
  14. [导入][转] Eclipse中的快捷键
  15. Unity中Invoke函数基础用法
  16. 初识Hadoop(核心组件与应用)
  17. HTML中的img标签无法显示图片的解决方案
  18. 英特尔AI大会:新版AI芯片
  19. 2023适老用品展、CISSE北京养老展、老年产业博览会
  20. 第三方SDK接入--微信

热门文章

  1. python输入一个五位数、判断是否为回文数_python如何判断是不是回文数
  2. java计算机毕业设计志愿者管理系统演示录像2020源码+mysql数据库+系统+lw文档+部署
  3. 硬盘格式转换不影响数据_ convert命令FAT32转NTFS
  4. Marquee属性详解
  5. 【机器人工具箱学习笔记】第七章 机械臂运动学
  6. 微信开发实战(2)—微信公众平台接口调试工具
  7. 大数据时代下如何保障信息安全?
  8. 如何评价 Richard Stallman?
  9. 精分合并抑郁康复经历分享:如何从死亡边缘回到生的海洋?
  10. 专业订制|软件开发|系统开发|网页设计|做网站|企业建站|网站建设