资源描述
Introductions of PLC and MCUA PLC is a device that was invented to replace the necessary sequential relay circuits for machine control. The PLC works by looking at its inputs and depending upon their state, turning on/off its outputs .The user enters a program, usually via software or programmer that gives the desired results.PLC are used in many “real world” applications. If there is industry present, chances are good that there is a PLC present. If you are involved in machining, packaging, material handling, automated assembly or countless other industries, you are probably already using them. If you are not, you are wasting money and time. Almost any application that needs some type of electrical control has need for PLC.For example, lets assume that when a switch turns on we want to turn a solenoid on for 5 seconds and then turn it off regardless of how long the switch is on for. We can do this with a simple external timer. What if the process also needed to count how many times the switch individually turned on? We need a lot of external counters.As you can see, the bigger the process the more of a need we have for a PLC. We can simply program the PLC to count its inputs and turn the solenoids on for the specified time.We will take a look at what is considered to be the “top 20” PLC instructions. It can be safely estimated that with a firm understanding of there instructions one can solve more than 80% of the applications in existence.Thats right, more than 80%! Of course well learn more than just these instructions to help you solve almost ALL your potential PLC applications.The PLC mainly consists of a CPU, memory areas, and appropriate circuits to receive input/output data, as shown in Fig. 19.1 We can actually consider the PLC to be a box full of hundreds or thousands of separate relays, counters, timer and date storage locations. Do these counters, timers, etc. really exist? No, they dont “physically” exist but rather they are simulated and can be considered software counters, timers, etc. These internal relays are simulated through bit locations in registers.What does each part do?INPUT RELAYS-(contacts) These are connected to the outside world. They physically exist and receive signals from switches, sensors, etc. Typically they are not relays but rather they are transistors.INTERNAL UTILITY RELAYS-(contacts) These do not receive signals from the outside world nor do they physically exist. They are simulated relays and are what enables a PLC to eliminate external relays. There are also some special relays that are dedicated to performing only one task. Some are always on while some are always off. Some are on only once during power-on and are typically user for initializing data what was stored.COUNTERS These again do not physically exist. They are simulated counters and they can be programmed to count pulses. Typically these counters can count up, down or both up and down. Since there are simulated, they are limited in their counting speed. Some manufacturers also include high-speed counters that are hardware based. We can think of these as physically existing. Most timers these counters can count up, down or up and down. TIMERS These also do not physically exist. They come in many varieties and increments. The most common type is an on-delay type. Other include off-delay and both retentive and non-retentive types. Increments vary from 1ms through 1s.OUTPUT RELAYS-(coil) These are connected to the outside world. They physically exist and send on/off signals to solenoids, lights, etc They can be transistors, relays, or triacs depending upon the model chosen.DATA STORAGE-Typically there are registers assigned to simply store data. There are usually used as temporary storage for math or data manipulation. They can also typically be user power-up they will still have the same contents as before power war removed. Very convenient and necessary!A PLC works by continually scanning a program. We can think of this scan cycle as consisting of 3 important steps, as shown in Fig.19.2 There are typically more than 3 but we can focus on the important parts and not worry about the others. Typically the others are checking the system and updating the current and timer values.Step 1-CHECK INPUT STATUS-First the PLC takes a look at each input to determine if it is on or off. In other words, is the sensor connected to the first input on? How about the second input? How about the thirdIt records this data into its memory to be used during the next step.Step 2-EXECUTE PROGRAM-Next the PLC executes your program one instruction at a time. Maybe your program said that if the first input was on then it should turn on the first output. Since is already knows which inputs are on/off from the previous step, it will be able to decide whether the first output should be turned on based on the state of the first input. It will store the execution results for use later during the next step.Step 3-UPDATE OUTPUT STSTUS-Finally the PLC updates the status of outputs. It updates the outputs based on which inputs were on during the first step and the results of executing your program during the second step. Based on the example in step 2 it would now turn on the first output because the first input was on and your program said to turn on the first output when this condition is true.After the third step the PLC goes back to step one and repeats the steps continuously. One scan time is defined as the time is takes to execute the 3 steps listed above. Thus a practical system is controlled to perform specified operations as desired.The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8Kbytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and pin-out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications.The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When is written to port 0 pins, the pins can be used as high-impedance inputs. Port 0 can also be configured to be the multiplexed lowered address/data bus during accesses to external program and data memory. In this mode, P0 has internal pull-ups.Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pull-ups are required during program verification. Port 1 is an 8-bit bidirectional I/O port with internal pullups.The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups.In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX).PLC和微处理器简介PLC(可编程逻辑控制器)是极限控制中为代替必要的继电器时序电路而发明的一种设备。PLC工作时通过查询输入端并根据其状态打开或关闭输出。用户通常用软件或编程器输入程序,从而或得期望的结果。很多实际应用都采用PLC。工业生产中应用PLC的可能性很高。如果你正在进行机械制造,产品包装,材料处理,自动化装配及无数其他工业生产,你可能已经用到了PLC。如果你没有用到,那就是在浪费金钱和时间。几乎所有需要电气控制的地方都需要PLC。例如,假定在开关闭合时我们需要一个线圈接通5秒然后不管开关接通多长时间都将线圈断开。我们可以通过一个简单的外部定时器来实现。但是加入该过程有十个开关和线圈呢?我们就需要十个外部定时器。如果这个过长分别记录每个开关开启的次数呢?我们又需要很多外部计数器。由此可见,系统越大,我们就越需要PLC。我们可以简单地用PLC编程来对输入信号进行技术,并在规定的时间接通线圈。我们考察一下哪些是PLC中最常用的20条指令。保守地估计一下,如果镇长地掌握了这些指令,就能解决80%以上现存的应用问题。是的,80%以上!当然,我们要学习的指令比这些更多,以帮助你解决几乎所有潜在的PLC应用问题。PLC主要由中央处理器(CPU),存储器和输入,输出电路构成,我们可以将PLC看成是一个装满了成百上千个独立的继电器,计数器,定时器,以及数据存储器的盒子。这些计数器,定时器,定时器等是不是真的存在呢?不,它们都是模拟的,物理上并不存在,但可以将它们看长是软计数器,软定时器。这些内部继电器是用寄存器中的单元模拟出来的。各个部分是如何工作的呢?输入继电器(触点)这些继电器连接外部电路。它们是实际存在的,并接受来自开关,传感器等的信号,通常是晶体管而非继电器。内部通用继电器(触点)它们不从外部设备接受信号,也非物理上存在的。它们是模拟的继电器,用以消除PLC的外部继电器。此外还有一些特殊继电器,专门执行一项任务。其中一些是常开的,一些是常闭的。有一些仅在电源上电时导通一次,通常用来初始化存储的数据。计数器 它们也并非物理上存在的,而是模拟的计数器,可通过编程来对脉冲进行计数。通常它们可进行加计数,减计数或同时进行加减计数。因为它们是用软件模拟的,计数速度就有限。一些制造商提供了基于硬件的高速计数器,这样的计数器可以认为是物理上存在的。这些计数器多数情况下可以进行加计数减计数或同时进行加减计数。定时器它们也并非物理上存在的,分为多种类型和定时单位。最常用的一种类型是延时导通型。其他类型还有延时断开型,记忆和非记忆型。定时单位的范围是1MS到1S输出继电器(线圈) 该部分连接到外围电路。它们是物理上存在的,并给线圈,灯等发送开关信号。输出继电器也可以是晶体管,继电器或可控硅,取决于选择的型号。数据寄存器 它们通常是用来存储数据的寄存器,一般作为运算或数据处理的暂存器。在PLC断电时通常还可以用来存储数据。再次接通电源后,其内容与断电前相同,非常方便且必要。PLC是通过连续扫描一个程序来工作的。我们可以认为扫描周期是由三个主要阶段组成的。如图所示。当然有多余三个阶段的情况,但我们可关注重要的环节,忽略其他环节。其他阶段通常正在检查系统及更新内部计数器和定时器的当前值。第一步-检查输入状态-首先PLC检查每一个输入是否接通。换句说就是,与第一个输入端连接的传感器接通了吗?第二哥输入呢?第三个输入呢?PLC将这些数据记录到存储器中,以便在下一个阶段使用。第二步-执行程序-然后PLC一次一条地执行程序。你的程序可能要求第一个输入接通时,接接通第一个输出。因为在上一步已经知道输入端的开关状态,根据上一步输入端的状态,就可以确定是否应该接通第一个输出。PLC将执行结果存储起来,以供下一步使用。第三步-更新输出状态-最后PLC更新输出状态。PLC根据第一步中国接通的输入和第二步中程序执行的结果更新输出转台。由于第一个输入接通了,程序要求在该条件满足时就接通第一个输出,根据第二步的情况,PLC就接通第一个输出。PLC在执行完第三步后就返回到第一步,并反复循环。一次扫描时间定义为执行上面的三步所花的时间。因此,一个实际的系统应根据要求执行特定的操作。AT89S52是一种低功耗、高性能CMOS8位微控制器,具有8K 在系统可编程 Flash 存储器。使用 Atmel 公司高密度非易失性存储器技术制造,与工业 80C51 产品指令和引脚完全兼容。片上Flash允许程序存储器在系统可编程,亦适于常规编程器。在单芯片上,拥有灵巧的 8 位 CPU 和在系统可编程Flash,使得 AT89S52为众多嵌入式控制应用系统提供高灵活、超有效的解决方案。AT89S52具有以下标准功能:8k字节Flash,256字节RAM,32 位 I/O 口线,看门狗定时器,2个数据指针,三个16位定时器/计数器,一个6向量2级中断结构,全双工串行口,片内晶振及时钟电路。另外,AT89S52 可降至 0Hz 静态逻辑操作,支持2种软件可选择节电模式。空闲模式下,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。掉电保护方式下,RAM内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。P0口是一个8位漏极开路的双向I/O口。作为输出口,每位能驱动8个TTL逻辑电平。对P0端口写“1”时,引脚用作高阻抗输入。当访问外部程序和数据存储器时,P0口也被作为低8位地址/数据复用。在这种模式下,P0具有内部上拉电阻。在 flash编程时,P0口也用来接收指令字节;在程序校验时,输出指令字节。程序校验时,需要外部上拉电阻。P1 口:P1 口是一个具有内部上拉电阻的 8 位双向 I/O 口,p1 输出缓冲器能驱动 4 个TTL 逻辑电平。对 P1 端口写“1”时,内部上拉电阻把端口拉高,此时可以作为输入口使用。作为输入使用时,被外部拉低的引脚由于内部电阻的原因,将输出电流(IIL)。此外,P1.0和P1.2分别作定时器/计数器2的外部计数输入(P1.0/T2)和时器/计数器2的触发输入(P1.1/T2EX)。
展开阅读全文