plc计数器编程讲解(PLC基本知识--4.2)

Counters / 计数器


A counter is a simple device intended to do one simple thing - count. Using them, however, can sometimes be a challenge because every manufacturer (for whatever reason) seems to use them a different way. Rest assured that the following information will let you simply and easily program anybody's counters.

计数器是一种简单的设备,目的是做一件简单的事情-计数。然而,使用它们有时会是一个挑战,因为每个制造商(无论出于什么原因)似乎都在以不同的方式使用它们。请放心,下面的信息将让您轻松地编写任何制造商的计数器。


What kinds of counters are there? Well, there are up-counters (they only count up 1,2,3...). These are called CTU,(count up) CNT,C, or CTR. There are down counters (they only count down 9,8,7,...). These are typically called CTD (count down) when they are a separate instruction. There are also up-down counters (they count up and/or down 1,2,3,4,3,2,3,4,5,...) These are typically called UDC(up-down counter) when they are separate instructions.

有哪些种类的计数器呢?嗯,有向上计数的计数器(他们只能数1、2、3......),这些被称为CTU(向上计数)、 CNT、C、或者CTR;有向下计数的计数器(他们只能倒数9、8、7......),当它们是单独的指令时,通常称为CTD(向下);也有双向计数器(他们向上或向下计数1、2、3、4、3、2、3、4、5......),当它们是单独的指令时,通常称为UDC(双向计数器)。


Many manufacturers have only one or two types of counters but they can be used to count up, down or both. Confused yet? Can you say "no standardization"? Don't worry, the theory is all the same regardless of what the manufacturers call them. A counter is a counter is a counter...

许多制造商只有一种或两种计数器,但它们可以用来向上计数、向下计数、双向计数。困惑了吗?你可能会说“怎么没有标准化”?别担心,不管制造商怎么称呼它们,理论都是一样的。计数器就是计数器就是计数器......


To further confuse the issue, most manufacturers also include a limited number of high-speed counters. These are commonly called HSC (high-speed counter), CTH (CounTer High-speed) or whatever.

更困惑的问题是,大多数制造商的PLC还包括了有限数量的高速计数器,这些通常被称为HSC(高速计数器)、CTH或其他。


Typically a high-speed counter is a "hardware" device. The normal counters listed above are typically "software" counters. In other words they don't physically exist in the plc but rather they are simulated in software. Hardware counters do exist in the plc and they are not dependent on scan time.

通常高速计数器是一个“硬件”设备。上面列出的普通计数器通常是“软件”计数器,换句话说,它们并不实际存在于PLC中,而是在软件中模拟出来的。在PLC中确实存在硬件计数器,它们不依赖于扫描时间。


A good rule of thumb is simply to always use the normal (software) counters unless the pulses you are counting will arrive faster than 2X the scan time. [i.e. if the scan time is 2ms and pulses will be arriving for counting every 4ms or longer then use a software counter. If they arrive faster than every 4ms (3ms for example) then use the hardware (high-speed) counters].

一个很好的经验法则是总是使用普通的计数器(软件计数器),除非你在计数时的脉冲比2倍的程序扫描时间还要快【例如,如果扫描时间为2ms,每4ms或更长间隔时间计数脉冲才会到达,那么我们使用软件计数器;如果计数脉冲到达的速度超过4ms(例如3ms),则我们使用高速计数器(硬件计数器)】。


To use them we must know 3 things:

  1. Where the pulses that we want to count are coming from. Typically this is from one of the inputs.(a sensor connected to input 0000 for example)
  2. How many pulses we want to count before we react. Let's count 5 widgets before we box them, for example.
  3. When/how we will reset the counter so it can count again. After we count 5 widgets lets reset the counter, for example.

要使用计数器,我们必须知道三件事:

1. 我们想要计数的脉冲来自哪里呢,通常这脉冲信号来自于一个输入(例如连接到输入点0000的传感器)。

2. 在我们做出反应之前,我们要数出多少脉冲呢,例如,在装箱之前,让我们来数5个小部件。

3. 我们要何时或者如何重置计数器以便它能再次重新计数呢,例如,在我们数完5个小部件之后,让我们重置计数器。


When the program is running on the PLC the program typically displays the current or "accumulated" value for us so we can see the current count value.

当程序在PLC上运行时,程序通常会为我们显示当前值或“累计”值,这样我们就可以看到当前的计数值。


Typically counters can count from 0 to 9999, -32,768 to 32,767 or 0 to 65535. Why the weird numbers? Because most PLCs have 16-bit counters. We'll get into what this means in a later chapter but for now suffice it to say that 0-9999 is 16-bit BCD (binary coded decimal) and that -32,768 to 32767 and 0 to 65535 is 16-bit binary.

通常,计数器的计数范围为0到9999、-32,768到 32,767或0到65535。为什么是这些奇怪的数字呢?因为大多数PLC都有16位计数器。我们将在后面的章节中讨论这意味着什么,但现在只要知道0-9999是16位BCD(二进制编码的十进制),-32,768到32767和0到65535是16位二进制就足够了。


Here are some of the instruction symbols we will encounter (depending on which manufacturer we choose) and how to use them. Remember that while they may look different they are all used basically the same way. If we can setup one we can setup any of them.

以下是我们将遇到的一些指令符号(取决于我们选择的制造商)以及如何使用它们。记住,虽然它们看起来可能不同,但它们的用法基本上是相同的。如果我们可以设置一种了,我们就基本上可以设置其他的任何一种。

plc计数器编程讲解(PLC基本知识--4.2)(1)

In this counter we need 2 inputs.

在这个计数器中,我们需要2个输入。

One goes before the reset line. When this input turns ON the current (accumulated) count value will return to zero.
The second input is the address where the pulses we are counting are coming from.

上面那个是复位信号,当复位信号为“真”时,当前(累计)计数值将返回为零。

下面那个是脉冲信号,就是我们正在计数的脉冲来自的地址。


For example, if we are counting how many widgets pass in front of the sensor that is physically connected to input 0001 then we would put normally open contacts with the address 0001 in front of the pulse line.

例如,如果我们正在计算有多少小部件从物理连接到输入0001的传感器前经过,那么我们将在梯形图中把地址为0001的常开触点放在脉冲输入地址的面前。

Cxxx is the name of the counter. If we want to call it counter 000 then we would put "C000" here.

Cxxx是计数器的名称。如果我们想称它为计数器000,那么我们可以在这里写上“C000”。

yyyyy is the number of pulses we want to count before doing something. If we want to count 5 widgets before turning on a physical output to box them we would put 5 here. If we wanted to count 100 widgets then we would put 100 here, etc. When the counter is finished (i.e we counted yyyyy widgets) it will turn ON a separate set of contacts that we also label Cxxx.

yyyyy是我们要计算的某东西数量的脉冲数。如果我们想要在打开一个物理输出之前数5个小部件放到零件盒子里,我们就可以在这里输入5,如果我们想要数100个部件,那么我们就在这里输入100,等等。当计数完成时(例如我们数了yyyy个小部件)计数器会将它自己的一个独立触点置位为“真”(Tuen ON),我们也将这个触点标记为Cxxx

Note that the counter accumulated value ONLY changes at the off to on transition of the pulse input.

注意,计数器的累积值只会在脉冲输入信号由OFF转换到ON(即上升沿)时发生变化。


plc计数器编程讲解(PLC基本知识--4.2)(2)

Here's the symbol on a ladder showing how we set up a counter (we'll name it counter 000) to count 100 widgets from input 0001 before turning on output 500. Sensor 0002 resets the counter.

这是一个梯形图上的符号,显示了我们如何设置一个计数器(我们将其命名为Counter 000),在打开输出0500之前,这个计数器需要从输入0001中计数100个小部件。传感器0002用于复位计数器。


Below is one symbol we may encounter for an up-down counter. We'll use the same abbreviation as we did for the example above.(i.e. UDCxxx and yyyyy)

下面是一个我们可能会遇到的双向计数器的符号,我们将使用与上面例子相同的缩写(即UDCxxx和yyyyy)。

plc计数器编程讲解(PLC基本知识--4.2)(3)

In this up-down counter we need to assign 3 inputs. The reset input has the same function as above. However, instead of having only one input for the pulse counting we now have 2. One is for counting up and the other is for counting down. In this example we will call the counter UDC000 and we will give it a preset value of 1000 (we'll count 1000 total pulses). For inputs we'll use a sensor which will turn ON input 0001 when it sees a target and another sensor at input 0003 will also turn ON when it sees a target. When input 0001 turns ON we count up and when input 0003 turns ON we count down. When we reach 1000 pulses we will turn ON output 0500. Again note that the counter accumulated value ONLY changes at the OFF to ON transition of the pulse input. The ladder diagram is shown below.

在这个双向计数器中,我们需要分配3个输入,其中复位输入具有与前面所讲的相同的功能。然而,我们现在有2个脉冲计数输入而不是只有一个,一个是用来向上( )计数的,另一个是用来向下(-)计数的。在本例中,我们将命名这个计数器为UDC000,并将它的预设值设置为1000(即我们将计算1000个脉冲)。我们将使用一个传感器作为输入,当它探测到目标时,它将打开输入0001,另一个传感器在输入0003,当它探测到目标时,它也会打开。当输入0001打开时,我们向上( )计数;当输入0003打开时,我们向下(-)计数。当计数器的累积达到1000个脉冲时,我们将打开输出0500。再次注意,计数器的累积值只在脉冲输入由OFF转换到ON(即上升沿)时才发生变化。梯形图如下图所示。

plc计数器编程讲解(PLC基本知识--4.2)(4)


plc计数器编程讲解(PLC基本知识--4.2)(5)

In the example above, each time the operator pushes button 0001 the counter accumulated value increases by one. Note that it increases only when the button first turns on. (i.e. the off to on transition). When the accumulated value equals the preset value(i.e. 5), the C000 contacts turn on and output 0500 becomes true. When the operator pushes the reset button (0002) the accumulated value changes back to 0000.

在上面的例子中,操作员每次按下0001按钮,计数器的累积值就增加1。注意,只有当按钮由OFF转换到ON(即上升沿)时,计数器累积值才会增加。当累积值等于预设值时(即5),打开C000触点,输出0500变为“真”(True)。当操作员按下复位按钮(0002)时,累加值将返回到0000。


One important thing to note is that counters and timers can't have the same name (in most PLCs). This is because they typically use the same registers. We haven't learned about timers yet but you might make a note of this for future reference because it's pretty important.

需要注意的重要一点是,计数器和计时器不能使用相同的名称(在大多数PLC中是这样)。这是因为它们通常使用相同的寄存器。我们还没有学过定时器,但是你可以把它记下来,作为以后的参考,因为它很重要。


Well, the counters above might seem difficult to understand but they're actually quite easy once we get used to using them. They certainly are an essential tool. They are also one of the least "standardized" basic instructions that we will see. However, always remember that the theory is the same from manufacturer to manufacturer!

好吧,上面的计数器可能看起来很难理解,但是一旦我们习惯使用它们,它们实际上是非常容易的。它们当然是必不可少的工具。它们也是我们将会看到的最不“标准化”的基本指令之一。但是,请始终记住,不同品牌的PLC中计数器的原理都是相同的!

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页