logo资料库

自动售货机VHDL实现.doc

第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
资料共7页,全文预览结束
设计题目:简易自动售货机设计 目的与任务: 1)巩固和运用所学课程,理论联系实际,提高分析、解决数字电路系统设计的实 际问题的独立工作能力。 2)进一步加深对 FPGA 以及数字电路应用技术方面的了解与认识。 3)进一步熟悉数字电路系统设计、制作与调试的方法和步骤。 4)深入学习 EDA 技术,更好地掌握本专业知识。 内容和要求: 某自动售货机中有两种饮料可以出售,售价分别为 2 元和 3 元。售货机可以识别 1 元,5 元两种货币。如果投入金额总值等于或超过售价就可以将饮料放出,并具有相应 的找零钱功能。 (1)用户可多次选择购买的饮料种类,某次饮料种类选定后等待投币。如等待时 间超过 10 秒钟,则认为用户放弃选购,售货机自动回到等待状态,等待新的交易。 若在 10 秒内,再次选中饮料,则再次等待。 (2)每次交易完成,售货机自动回到等待状态,等待新的交易。 (3)用按键模拟投入 1 元,5 元两种货币,可连续投币,同时显示投入的金额和还 应投入的金额。若某次投币后金额不足,且一定时限内不再投币(10 秒左右),则交易 失败,并退币,显示退还金额。 (4)具有指示电路,分别指示购买成功、交易取消(交易失败)和找零。 (5)相应显示有延时和时控功能。
选择 2 元商品,不再投币, 10 秒后,交易失败,延时显示后,回到初始状 态。 选择 2 元商品后,在 10 秒内,再次选择 3 元商品;此后,不再投币,10 秒 后,交易失败,延时显示后,回到初始状态。 选择 2 元商品后,在 10 秒内,再次选择 3 元商品;此后,在一定时限内投 入 5 元,交易成功,不找零,延时显示后,回到初始状态。
选择 2 元商品后,在 10 秒内,再次选择 3 元商品;此后,在一定时限内先 后投入 1 元和 5 元,交易成功,找零 1 元,延时显示,其后回到初始状态。 显示连续交易。 选择 2 元商品后,在 10 秒内,再次选择 3 元商品;此后,在一定时限内投 入 1 元,其后,等待再次投币,若超过一定时限(10 秒)不再投币,认为放弃, 交易失败,并退币;延时显示后,回到初始状态。
选择 2 元商品后,在 10 秒内,再次选择 3 元商品;此后,在一定时限内投 入 1 元,其后,在等待再次投币的时限(10 秒)内,再次投入 1 元,金额不足, 等待下次投币,超过一定时限内(如图 12 秒)不再投币,认为放弃,交易失败, 并退币;延时显示后,回到初始状态。
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity shouhuojioriginal is clk: in std_logic; port( coin1:in std_logic; coin5:in std_logic; price2:in std_logic; price3:in std_logic; paid:out std_logic_vector(3 downto 0); needed:out std_logic_vector(3 downto 0); success:out std_logic; failure:out std_logic; showmoneyout:out std_logic; moneyout:out std_logic_vector(3 downto 0)); end shouhuojioriginal; architecture behav of shouhuojioriginal is type state_type is (qa,qb,qe,qc,qg,qd,qf); signal current_state :state_type:=qa; signal q:integer range 0 to 100; begin process(clk) variable paidtemp:std_logic_vector(3 downto 0); variable neededtemp: std_logic_vector(3 downto 0); variable backmoney: std_logic_vector(3 downto 0); variable pricetemp:std_logic_vector(3 downto 0); begin if clk'event and clk='1' then case current_state is when qa =>paidtemp:="0000";neededtemp:="0000"; backmoney:="0000";pricetemp:="0000";q<=0; showmoneyout<='0';moneyout<="0000";paid<="0000"; needed<="0000";failure<='0';success<='0'; if price2='1' or price3='1' then current_state<=qb; if price2='1' then pricetemp:=pricetemp+2; neededtemp:=pricetemp; else pricetemp:=pricetemp+3; neededtemp:=pricetemp; end if; end if; paid<=paidtemp; needed<=neededtemp; when qb=>if coin1='1'or coin5='1' then
if coin1='1' then paidtemp:=paidtemp+1; else paidtemp:=paidtemp+5; end if; if paidtemp>=pricetemp then backmoney:=paidtemp-pricetemp; neededtemp:="0000";current_state<=qd; else neededtemp:=pricetemp-paidtemp;backmoney:="0000"; urrent_state<=qc;q<=0; end if; paid<=paidtemp; needed<=neededtemp; end if; if q<8 then q<=q+1; if price2='1' or price3='1' then q<=0; if price2='1' then pricetemp:=pricetemp+2; neededtemp:=neededtemp+2; else pricetemp:=pricetemp+3; neededtemp:=neededtemp+3; end if; paid<=paidtemp; needed<=neededtemp; end if; else current_state<=qe; q<=0; end if; when qe=>failure<='1'; if q<4 then q<=q+1; else current_state<=qa;q<=0; end if; when qc=> if coin1='1' or coin5='1' then if coin1='1' then paidtemp:=paidtemp+1; else paidtemp:=paidtemp+5; end if; if paidtemp>=pricetemp then neededtemp:="0000"; backmoney:=paidtemp-pricetemp; current_state<=qd; else neededtemp:=pricetemp-paidtemp; backmoney:="0000"; current_state<=qc; end if; paid<=paidtemp; needed<=neededtemp; end if;
if coin1/='1' and coin5/='1' then if q<10 then q<=q+1; else current_state<=qg; end if; else q<=0; end if; when qg=> failure<='1'; showmoneyout<='1';moneyout<=paidtemp; current_state<=qf;q<=0; when qd=> success<='1'; if backmoney>"0000" then showmoneyout<='1'; moneyout<=backmoney; end if; current_state<=qf;q<=0; when qf=> if q<4 then q<=q+1; else current_state<=qa;q<=0; end if; end case; end if; end process; end behav;
分享到:
收藏