基于FPGA自动饮料售货机
- 格式:doc
- 大小:6.55 MB
- 文档页数:9
摘要自动售货机是可以完成无人自动售货,不受任何场地限制,方便快捷,可以每天24h售货,随着自动售货机数量的增加,商品包装的定量化和标准化,出售的商品多样化,自动售货的便利性日益显现。
现在,自动售货机产业正在走向信息化并进一步实现合理化。
例如实行联机方式,通过电话线路将自动售货机内的库存信息及时地传送各营业点的电脑中,从而确保了商品的发送、补充以及商品选定的顺利进行。
本款饮料售货机是基于汽水和咖啡的自动售货设计的,采用PLC编程控制技术。
关键词自动售货机;PLC编程控制技术ABSTRACTSubject to any place is limited, convenient and quick, every day, with 24h vending vending machine, the increase in the number of commodity packaging quantitative and standardization, selling goods, diversification, vending convenience is becoming increasingly obvious. Now, the vending machine industry is on her way to the information and further achieve rationalization. For example implements online mode, through telephone lines will vending machine in inventory information timely transmission each outlet in the computer, thus ensuring the goods delivered and supplement of goods, and selected smoothly. This drink vending machine is based on soda and coffee vending design, adopting PLC programmable control technology.Key words The vending machine;PLC programmable control technology目录1 设计简介 (3)1.1 设计任务 (3)1.2 功能要求说明 (3)1.3 工作原理 (3)2 硬件系统设计 (4)2.1 硬件系统各模块功能简要介绍 (4)3 软件系统设计 (5)3.1 系统输入输出设计 (5)3.2 PLC的选择 (5)3.3 I/O 器件安排表 (6)3.4 PLC输入输出电路 (6)3.5 软件系统各模块设计简要介绍 (7)3.6 程序流程框图 (8)3.7 程序清单 (9)4 仿真、测试及设计总结 (13)4.1 自动售货机的仿真结果 (13)4.2 仿真分析 (14)4.3 自动售货机找钱数据分析 (15)参考文献 (16)致谢 (16)1 设计简介1.1 设计任务1.用PLC控制该自动售货机,设计PLC控制程序,画出I/O电气接口图。
IC设计面试笔试题目集合分类笔试/面试题目集合分类--IC设计基础1、我们公司的产品是集成电路,请描述一下你对集成电路的认识,列举一些与集成电路相关的内容(如讲清楚模拟、数字、双极型、CMOS、MCU、RISC、CISC、DSP、ASIC、FPGA等的概念)。
(仕兰微面试题目)2、FPGA和ASIC的概念,他们的区别。
(未知)答案:FPGA是可编程ASIC。
ASIC:专用集成电路,它是面向专门用途的电路,专门为一个用户设计和制造的。
根据一个用户的特定要求,能以低研制成本,短、交货周期供货的全定制,半定制集成电路。
与门阵列等其它ASIC(Application Specific IC)相比,它们又具有设计开发周期短、设计制造成本低、开发工具先进、标准产品无需测试、质量稳定以及可实时在线检验等优点模拟电路1、基尔霍夫定理的内容是什么?(仕兰微电子)2、平板电容公式(C=εS/4πkd)。
(未知)3、最基本的如三极管曲线特性。
(未知)4、描述反馈电路的概念,列举他们的应用。
(仕兰微电子)5、负反馈种类(电压并联反馈,电流串联反馈,电压串联反馈和电流并联反馈);负反馈馈的优点(降低放大器的增益灵敏度,改变输入电阻和输出电阻,改善放大器的线性和非线性失真,有效地扩展放大器的通频带,自动调节作用)(未知)6、放大电路的频率补偿的目的是什么,有哪些方法?(仕兰微电子)7、频率响应,如:怎么才算是稳定的,如何改变频响曲线的几个方法。
(未知)8、给出一个查分运放,如何相位补偿,并画补偿后的波特图。
(凹凸)9、基本放大电路种类(电压放大器,电流放大器,互导放大器和互阻放大器),优缺点,特别是广泛采用差分结构的原因。
(未知)10、给出一差分电路,告诉其输出电压Y+和Y-,求共模分量和差模分量。
(未知)11、画差放的两个输入管。
(凹凸)12、画出由运放构成加法、减法、微分、积分运算的电路原理图。
并画出一个晶体管级的运放电路。
自动贩卖机制作方法自动贩卖机是一种便捷的自助销售设备,可以满足人们在各种场合的购买需求。
制作一台自动贩卖机的方法可以简单地分为以下几个步骤:1. 确定机器类型:首先需要确定自动贩卖机的类型,例如饮料、零食、烟酒等。
根据产品种类的不同,制作过程会有所差异。
2. 设计外观和结构:根据自动贩卖机的类型和使用场合,设计机器的外观和结构。
外观设计要吸引顾客的注意,结构设计要方便货物的存放和取出,并且保证机器的稳定性和安全性。
3. 制作机箱:根据设计图纸,选择合适的材料制作机箱。
常用的材料有金属、塑料、玻璃等。
机箱要具有足够的强度和耐久性,以保证机器的使用寿命。
4. 内部结构和装置:根据机器类型,设计内部结构和各种装置。
例如,饮料自动贩卖机需要设计好饮料存放和取出的通道、传感器、货道等;零食自动贩卖机需要设计好储存零食的仓库、出货机构等。
5. 电气控制系统:自动贩卖机需要一个电气控制系统来控制机器的运行。
电气控制系统包括电源、主控制板、显示屏、键盘、传感器等组成。
6. 选择合适的货道和货物:根据机器的尺寸和型号,选择合适的货道和货物。
货道的设计要考虑到各种不同尺寸和形状的产品,并确保货物的稳定性和易取性。
7. 安装货道和货物:根据设计图纸,安装机器的货道和货物。
货物要安排得整齐,方便顾客选择和取用。
8. 安装电气控制系统:安装好电气控制系统,确保各个部件和传感器的正常运行。
测试机器的整体运行情况,确保其顺畅、稳定。
9. 完善功能和设计:对自动贩卖机进行测试和调试,修正可能出现的问题。
确保货物的准确出货和退款等功能正常运行。
10. 保养与维护:完成自动贩卖机的制作后,需要定期维护和保养。
包括清洁机器、更换电池、更新商品信息等。
定期检查机器的运行状况,确保机器的正常使用。
以上是制作自动贩卖机的一般步骤。
当然,具体的制作方法还会受到市场需求、技术条件和预算等各种因素的限制和影响。
需要根据具体的情况,采取适当的方法和措施来完成每一步骤。
电子类公司笔试题精选一、模拟电路1基尔霍夫定理的内容是什么?〔仕兰微电子〕基尔霍夫电流定律是一个电荷守恒定律,即在一个电路中流入一个节点的电荷与流出同一个节点的电荷相等.基尔霍夫电压定律是一个能量守恒定律,即在一个回路中回路电压之和为零.2、平板电容公式(C=εS/4πkd)。
〔未知〕3、最基本的如三极管曲线特性。
〔未知〕4、描述反馈电路的概念,列举他们的应用。
〔仕兰微电子〕5、负反馈种类〔电压并联反馈,电流串联反馈,电压串联反馈和电流并联反馈〕;负反馈的优点〔降低放大器的增益灵敏度,改变输入电阻和输出电阻,改善放大器的线性和非线性失真,有效地扩展放大器的通频带,自动调节作用〕〔未知〕6、放大电路的频率补偿的目的是什么,有哪些方法?〔仕兰微电子〕7、频率响应,如:怎么才算是稳定的,如何改变频响曲线的几个方法。
〔未知〕8、给出一个查分运放,如何相位补偿,并画补偿后的波特图。
〔凹凸〕9、基本放大电路种类〔电压放大器,电流放大器,互导放大器和互阻放大器〕,优缺点,特别是广泛采用差分结构的原因。
〔未知〕10、给出一差分电路,告诉其输出电压Y 和Y-,求共模分量和差模分量。
〔未知〕11、画差放的两个输入管。
〔凹凸〕12、画出由运放构成加法、减法、微分、积分运算的电路原理图。
并画出一个晶体管级的运放电路。
〔仕兰微电子〕13、用运算放大器组成一个10倍的放大器。
〔未知〕14、给出一个简单电路,让你分析输出电压的特性〔就是个积分电路〕,并求输出端某点的rise/fall时间。
(Infineon笔试试题)15、电阻R和电容C串联,输入电压为R和C之间的电压,输出电压分别为C上电压和R 上电压,要求制这两种电路输入电压的频谱,判断这两种电路何为高通滤波器,何为低通滤波器。
当RC18、说说静态、动态时序模拟的优缺点。
〔威盛VIA 2003.11.06 上海笔试试题〕19、一个四级的Mux,其中第二级信号为关键信号如何改善timing。
- 15 -高 新 技 术1 自动售货机控制系统硬件设计1.1 PLC选型对比各类型的PLC,该设计选用三菱FX2N-48MR 系列PLC,综合其系统功能,其能够很好的满足设计要求,模块化的结构可以根据实际需要灵活组装。
PLC 最多有4 096个输入和输出点,内部存储程序容量可以达到252K 步,扩展后可以达到32M,主命令处理速度可以达到34 ns,甚至Q 系列PLC 可以在一块板上组装多个CPU 模块。
CPU 模块之间的通信可以立即或定期进行。
其分别通过命令控制和自动更新来实现,系统处理速度得到了进一步提高[1]。
1.2 输入输出I/O点定义I/O (输入/输出)单元是PLC 系统的重要组成部分。
输入/输出单元是PLC 与工业领域之间的接口。
现场信号通过I/O 单元连接PLC。
PLC 控制器通过端口I 从系统中接收传感器信号,并通过端口O 将各种命令发送到驱动器。
表1显示了I/O 模块的具体分布情况。
表1 输入输出I/O 口分配名称地址说明输入信号假币传感器SQ0X0识别假币1元传感器SQ1X1检测1元硬币数量5元传感器SQ2X2检测5元的数量10元传感器SQ3X3检测10元的数量矿泉水按钮SB0X4选择矿泉水可乐按钮SB1X5选择可乐茶π按钮SB2X6选择茶π咖啡按钮SB3X7选择咖啡找钱按钮SB4X10找钱输出信号假币指示灯L0Y0识别结果为假币矿泉水指示灯L1Y1投入钱币可购买矿泉水可乐指示灯L2Y2投入钱币可购买可乐茶π指示灯L3Y3投入钱币可购买茶π咖啡指示灯L4Y4投入钱币可购买咖啡找钱指示灯L5Y5钱币不足假币退出继电器KM0Y6控制执行机构退出假币矿泉水出货继电器KM1Y7控制执行机构执行送出矿泉水的动作可乐出货继电器KM2Y10控制执行机构执行送出可乐的动作茶π出货继电器KM3Y11控制执行机构执行送出茶π的动作咖啡出货继电器KM4Y12控制执行机构执行送出咖啡的动作找1元继电器KM5Y13控制找钱机构执行退1元动作找5元继电器KM6Y14控制找钱机构执行退5元动作1.3 系统各模块电路设计1.3.1 主电路接线图设计自动售货机自动控制系统选择三菱FX2N-48MR 系列PLC,其通过TC 变压器的次级绕组供电。
基于PLC的自动售货机控制系统设计AbstractIn recent years, vending machines have become more and more popular due to their convenience and efficiency in providing goods and services. To improve the control and management of vending machines, a new system using programmable logic controller (PLC) technology was designed and implemented. This paper presents the design of a PLC-based vending machine control system, including hardware and software implementation, system architecture, and control algorithms. The proposed system can ensure the accuracy of product dispensing, detect and prevent fraud, and providereal-time monitoring and control of the vending machine's operation. Additionally, the system can be easily integrated with other devices such as payment systems and inventory management tools, to improve overall efficiency and reduce maintenance costs. The experimental results demonstrate the effectiveness and reliability of the proposed system, which has great potential in future vending machine applications.Keywords: vending machine, PLC, control system, hardware design, software implementationIntroductionVending machines have become ubiquitous in our modern society, providing convenient access to a wide range of products and services. Such machines are widely used inpublic places like airports, train stations, shopping malls, and schools. Apart from providing customers with 24/7 self-service convenience, vending machine operations can bemanaged easily and remotely by vendors, retailers, or other stakeholders.However, vending machines face several challenges in terms of control and management. A key issue is ensuring accurate and prompt dispensing of products, as well as detecting and preventing fraud. Additionally, inventory management, payment systems, and maintenance are crucial aspects of vending machine management that require effective control and monitoring. To address these challenges, a new control system for vending machines using programmable logic controller (PLC) technology has been proposed.This paper presents the design and implementation of a PLC-based vending machine control system. The paper includes the hardware and software architecture, control algorithms, and experimental results, aimed at demonstrating the effectiveness of the proposed system.System ArchitectureThe proposed vending machine control system is based on a distributed network of sensors, actuators, and other components, all communicating with the central PLC. Figure 1 shows the overall system architecture, consisting of several system modules: hardware interfaces, product selection, and dispensing control, payment control, fraud detection, and maintenance control.The hardware interfaces module connects the sensors and actuators to the PLC, including product sensors, coin acceptors, display screens, and dispensing mechanisms. The module provides the necessary input/output data for the system's software to perform the various control functions.The product selection and dispensing control module are responsible for managing the selection of products bycustomers and controlling the dispensing mechanism. Customers make their choice by selecting the appropriate product button on the vending machine's interface, which is communicated to the PLC. The PLC then activates the appropriate dispensing motor based on the selected product and the inventory level.The payment control module is responsible for managing the payment process, reading the customer's payment information, and verifying its validity. Coin or bill acceptors, credit card readers, or other payment systems can be integrated with the vending machine and controlled by the PLC through this module.The fraud detection module is responsible for detecting and preventing unauthorized access to the vending machine, fake coins, or other attempts at fraud. This module utilizes various sensors and algorithms to detect and flag any such attempts, and sends alerts to the maintenance control module for appropriate action.The maintenance control module is responsible for monitoring the vending machine's performance, issuing alerts for preventive maintenance, and communicating with the vendor or maintenance staff for repair or replacement.Hardware DesignThe hardware system consists of a programmable logic controller (PLC), sensors, actuators, and product dispensers. Figure 2 shows the block diagram of the hardware system.The PLC used in the system is the SIEMENS SIMATIC S7-1200, which provides reliable and accurate control and monitoring of the vending machine's operation. The sensors used include optical sensors for detecting product selection and delivery status, and ultrasonic sensors for detecting product inventory levels. The actuators used are DC motorsfor product dispense control.The product dispensers are of two types: spiral and conveyer type. Spiral dispensers are used for products like snacks and sweets, while conveyer dispensers are used for products like drinks and cup-noodles. The dispensers are controlled by the DC motors through the PLC, which rotatesthe spirals or conveyor belts to deliver the product to the customer.Software ImplementationThe software implementation of the control system is divided into three parts: the ladder logic program, human-machine interface (HMI) program, and communication protocol.The ladder logic program is developed using Siemens TIA Portal software, which provides an easy-to-use interface for designing and testing the control programs. The program is responsible for managing the product selection and dispensing, payment control, fraud detection, and maintenance control functions.The HMI program is developed using Siemens WinCC software, which provides a user-friendly interface for customers to interact with the vending machine. The HMI displays the available products, product prices, and payment options, and also provides alerts and notifications for customers during the transaction.The communication protocol used in the system is the Modbus RTU protocol, which is a widely used industrial communication protocol for PLC-based systems. The protocol allows the sensors and actuators connected to the PLC to communicate with each other, providing real-time feedback on the vending machine's operation.Experimental ResultsTo evaluate the performance of the proposed vending machine control system, we conducted a series of experiments under different conditions. The experiments focused on evaluating the accuracy and reliability of product dispensing, payment control, and fraud detection.The results showed that the system was able toaccurately dispense products based on customer selection, as well as verify the validity of customer payments in real-time. Additionally, the system was able to detect and prevent fraudulent activities, such as coin or bill fraud, unauthorized access, or product jamming.ConclusionIn this paper, we presented the design andimplementation of a PLC-based vending machine control system. The proposed system demonstrated effective control and management of vending machine operations, ensuring accurate product dispensing, real-time payment verification, and fraud detection. The experimental results showed that the systemwas reliable and accurate, with potential for further integration with other systems like inventory management and remote monitoring. Future research could focus on optimizing the control algorithms and hardware components for higher efficiency and lower maintenance costs.。
电子信息、通信、电类专业将会遇到的面试题大全1模拟电路模拟电路1、 基尔霍夫定理的内容是什么?(仕兰微电子)基尔霍夫电流定律是一个电荷守恒定律,即在一个电路中流入一个节点的电荷与流出同一个节点的电荷相等的电荷相等. .基尔霍夫电压定律是一个能量守恒定律,即在一个回路中回路电压之和为零即在一个回路中回路电压之和为零. .2、平板电容公式、平板电容公式(C=(C=εS/4πkd)kd)。
(未知)。
(未知)。
(未知)3、最基本的如三极管曲线特性。
(未知)4、描述反馈电路的概念,列举他们的应用。
(仕兰微电子)5、负反馈种类(电压并联反馈,电流串联反馈,电压串联反馈和电流并联反馈);负反馈的优点(降低放大器的增益灵敏度,(降低放大器的增益灵敏度,改变输入电阻和输出电阻,改变输入电阻和输出电阻,改变输入电阻和输出电阻,改善放大器的线性和非线性失真,改善放大器的线性和非线性失真,改善放大器的线性和非线性失真,有有效地扩展放大器的通频带,自动调节作用)(未知)6、放大电路的频率补偿的目的是什么,有哪些方法?(仕兰微电子)7、频率响应,如:怎么才算是稳定的,如何改变频响曲线的几个方法。
(未知)8、给出一个查分运放,如何相位补偿,并画补偿后的波特图。
(凹凸)9、基本放大电路种类(电压放大器,电流放大器,互导放大器和互阻放大器),优缺点 ,特别是广泛采用差分结构的原因。
(未知)1010、给出一差分电路,告诉其输出电压、给出一差分电路,告诉其输出电压Y+Y+和和Y-,Y-,求共模分量和差模分量。
(未知)求共模分量和差模分量。
(未知)求共模分量和差模分量。
(未知)1111、画差放的两个输入管。
(凹凸)、画差放的两个输入管。
(凹凸)、画差放的两个输入管。
(凹凸)1212、画出由运放构成加法、减法、微分、积分运算的电路原理图。
并画出一个晶体管级的运放电、画出由运放构成加法、减法、微分、积分运算的电路原理图。
并画出一个晶体管级的运放电路。
目录第1章自售货机控制工艺流程分析 (1)1.1自动售货机控制过程描述 (1)1.2自动售货机控制工艺分析 (1)第2章控制系统总体方案设计 (2)2.1系统硬件组成 (2)2.2控制方法分析 (2)2.3I/O分配、 (3)2.4系统结线图设计 (3)第3章控制系统梯形图程序设计 (5)3.1控制程序流程图设计 (5)3.2控制程序时序图设计 (5)第4章监控系统设计 (7)4.1PLC与上位监控软件通讯 (7)4.2上位监控系统组态设计 (7)4.3实现效果..................................... 错误!未定义书签。
第5章系统调试及结果分析. (9)5.1系统调试及解决的问题 (9)5.2结果分析 (9)课程设计心得 (11)附录 (13)第1章自售货机控制工艺流程分析1.1自动售货机控制过程描述本次设计的题目是基于PLC自动售货机的系统设计,主要是应用三菱FX-2N型PLC的梯形图来设计控制程序,并简单介绍相关的知识,如:PLC的定义、PLC的编程语言、PLC的硬件组成等。
根据设计内容和控制要求画出顺序功能图和梯形图,再根据PLC的相关知识设计出它的外部接线结合梯形图和外部接线图分析说明该设计的控制原理过程。
本次设计的重要部分是第四章的设计部分,即自动售货机梯形图的设计。
根据设计内容和控制要求准确画出它的顺序功能图,再根据所画出的顺序功能图准确设计出它的梯形图,这样才能真正理解自动售货机的系统控制原理。
1.2自动售货机控制工艺分析自动售货机是集声、光、机电一体化的高新智能化产品,在我国也开始得到应用。
在中国人们可以看到现代化的自动售货机摆放在一些大商场门口、繁华街道两旁、公园入口处以及其它热闹的场所。
自动售货机在中国有着广阔的发展前景。
从自动售货机的发展趋势来看,它的出现是由于劳动密集型的产业构造向技术密集型社会转变的产物。
大量生产、大量消费以及消费模式和销售环境的变化,要求出现新的流通渠道;而相对的超市、百货购物中心等新的流通渠道的产生,人工费用也不断上升;再加上场地的局限性以及购物的便利性等这些因素的制约,无人自动售货机作为一种必须的机器便应运而生了。
摘要本论文设计的是基于三菱FX2N系列PLC构成的自动售货机监控系统,本文阐述了自动售货机的来源与发展,以及它在国内外发展的现状,对自动售货机的方案进行了论证,介绍了PLC的基本组成、特点以及工作原理,对基于三菱FX2N 系列PLC构成的自动售货机系统整体设计过程进行较为细致的论述。
文中详尽地介绍了自动售货机的各硬件组成,并完成了PLC外部接线图。
在PLC梯形图的编写时,文中采用的是三菱FX2N的梯形图编译软件FXGPWIN来进行编写。
介绍了自动售货机的基本原理以及工作流程,然后以一次交易过程为例,把交易过程分为几个程序块,然后分别对程序块进行编程。
具体说明了可编程序控制器在自动售货机中的作用。
程序涉及到了自动售货机工作的绝大部分过程。
利用PLC控制的自动售货机提高了系统的稳定性,保证自动售货机能够长期稳定运行。
关键词: PLC;梯形图;I/O点的分配目录摘要 0第1章绪论 (3)1.1 自动售货机的理论背景与实际意义 (3)1.2 自动售货机的主要内容 (4)1.3 自动售货机的设计思路 (4)第2章 PLC概述 (5)2.1 PLC的定义 (5)2.2 PLC的简介 (5)2.3 PLC的工作原理 (5)2.4 PLC的工作方式 (6)2.5 PLC的硬件组成 (7)2.6 PLC的编程语言 (8)2.7 PLC的特点 (8)第3章自动售货机的设计 (9)3.1 系统的硬件设计 (9)3.1-1 PLC的选型 (9)3.1-2 I/O分配表 (9)3.1-3 PLC的外部接线图 (10)3.2 系统的软件设计 (11)3.2-1 主程序流程图 (11)3.2-2 投币、显示子程序流程图 (12)3.2-3 比较币值子程序流程图 (13)3.2-4 饮料选择子程序流程图 (13)3.2-5 退币子程序流程图 (14)3.3 程序梯形图 (15)3.3-1 主程序梯形图 (15)3.3-2 判键、显示子程序P1及比较币值子程序P2 (16)3.3-3 饮料选择子程序P3 (17)3.3-4 退币子程序P4 (18)第4章仿真与调试 (19)4.1 GX Developer的特点 (19)4.2 程序的仿真过程与步骤 (20)第五章总结 (23)参考文献 (23)第1章绪论1.1自动售货机的理论背景与实际意义自动售货机是一种全新的商业零售形式,20世纪70年代自日本和欧美发展起来。
自动饮料售货机
目录
1.前言 (1)
2.设计流程图 (2)
3.源代码编写 (3)
4.仿真时序图 (6)
5.分析与总结 (7)
6.参考文献 (7)
1.前言
本人在本科阶段自学了一部分PLC,并运用PLC完成了本科的毕业设计,同在毕业设计课题组的同学选做基于PLC自动饮料售货机的设计,当时对自动饮料售货机的控制系统了解仅限于基于单片机与PLC的控制没有亲自动手去尝试设计。
在本学期,全新的接触和学习了FPGA课程,正处于一个FPGA的入门阶段,基于以前的兴趣,该次尝试基于FPGA简单设计自动饮料售货机的一部分控制。
本次是采用Quartus II 13.0sp1进行了程序源代码的编写和时序仿真。
图1-1自动饮料售货机内部结构图
图1-2自动饮料售货机内部结构图
2.设计流程图
图2-1自动饮料售货机示意图
图2-2自动饮料售货机流程图
3.源代码编写
/*信号定义:
clk: 表示时钟输入;
rst_n: 为系统复位信号;
half_yuan: 代表投入5角钱币;
one_yuan: 代表投入1元钱币;
half_out: 代表找零信号;
dispense: 代表机器售出一瓶饮料;
collect: 用于提示投币者取走饮料.
seg1: LCDA数码管显示;
seg2: LCDB数码管显示;
seg3: LCDC数码管显示;*/
module SCD(half_yuan ,one_yuan,half_out,collect,dispense,rst_n,clk,seg1,seg2,seg3);
parameter idle=0,half=1,one=2,two=3,three=4; // idle,half,one,two,three代表投入钱币的几种状态
input half_yuan,one_yuan,rst_n,clk;
output collect,half_out,dispense,seg1,seg2,seg3;
reg[2:0]D; //D代表当前时刻投币的状态
reg temp1,temp2;
reg collect,half_out,dispense;
reg [3:0]seg1; reg[3:0]seg2; reg[7:0]seg3;
always @(posedge clk or negedge rst_n)
begin
if (!rst_n)
begin dispense<=0;collect<=0;
half_out<=0;D<=idle;
temp1<=0;temp2<=0;
{seg1,seg2}<=8'b0000_0000;{seg3}<=8'b11111101;end
else
begin temp1<=half_yuan;temp2<=one_yuan; //初始状态赋值
case(D)
idle: if ({temp1,half_yuan}==2'b10) //0元状态下检测下降沿
begin D<=half;
{seg1,seg2}<=8'b0000_0101;{seg3}<=8'b1111_1101; //数码管显示
dispense<=0;collect<=0;half_out<=0;end //循环时输出置0
else if ({temp2,one_yuan}==2'b10)
begin D<=one;
{seg1,seg2}<=8'b0001_0000;{seg3}<=8'b1111_1101;
dispense <=0;collect<=0;half_out<=0;end。