vhdl实现自动售货机

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

自动售饮料机

本文基于VHDL语言对自动售饮料机的逻辑电路进行了逻辑设计和仿真。该电路可识别1元和5角硬币,实现购买3种不同价格的饮料并且具有找零功能。

1设计要求的提出和功能的构想[1][2]

①该饮料机能识别0.5元和1.0元两种硬币;

②售出3种不同价格的饮料,饮料价格分别为1.5元、2.0元和2.5元;

③具有找零功能;

④购买者能自主选择所购买的饮料;

⑤饮料机在每卖出一次饮料后能自动复位。

因为饮料的价格最高为2.5元,所以设计饮料机最多可接受3.0元的硬币。2分析设计要求并画出原始状态图

该自动售饮料机设有一个投币孔,通过传感器来识别两种硬币,给出两个不同的信号。在此用half_dollar和one_dollar分别表示投入0.5元和1.0元硬币后电路接收到的两个信号;三个饮料选择按键choose01表示选择价格为1.5元的饮料,choose10表示选择价格为2.0元的饮料,choose11表示选择价格为2.5元的饮料;rest表示复位按键;有2个输出口分别为饮料出口dispense和找零出口out1;用s0表示初始状态,s1表示投入0.5元硬币时的状态,s2表示投入1.0元硬币时的状态,s3表示投入1.5元硬币时的状态,s4表示投入2.0元时的状态;clk 表示时钟信号;机器最多接受的钱币为3.0元。

当投入的钱币到达1.5元或高于1.5元时机器处于出售饮料的状态。当到达1.5元时如果选择购买1.5元的饮料(choose01)则系统给出一个饮料,即dispense 为高电平一次。如果投入的钱币到达2.0元并且选择购买1.5元的饮料则系统显示给出一个饮料并找出1枚0.5元的硬币,即dispense为高电平一次out1为高电平一次。如果选择购买2.0元的饮料(choose10),则系统显示给出一个2.0元的饮料,即饮料输出信号dispense为高电平一次。依次类推。

图1.1为本次设计所构想的状态图。

3程序设计[3][4]

根据上述对自动售饮料机逻辑状态的分析,编写程序如下:library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity auto_selling is

port(clk , rst ,half_dollar ,one_dollar: in std_logic;

choose :in std_logic_vector(1 downto 0);

out1 ,dispense: out std_logic);

end auto_selling;

architecture behave of auto_selling is

type state_values is (s2 , s0 , s1 ,s3 ,s4);

signal state , next_state: state_values;

begin

process (clk , rst)

begin

if rst = '1' then

state <= s0;

elsif (clk’event and clk='1') then

state <= next_state;

end if;

end process;

process (state , half_dollar ,one_dollar ,choose)

begin

out1 <= '0';dispense<='0';

next_state <= s0;

case state is

when s0 =>

if (half_dollar='1') then

next_state <= s1;

elsif (one_dollar='1' )then

next_state <= s2;

else next_state <= s0;

end if;

when s1 =>

if (half_dollar='1') then

next_state <= s2;

elsif( one_dollar='1') then

next_state <= s3;

else next_state <= s1;

end if;

when s2 =>

if (half_dollar='1' )then

if (choose="01") then

dispense<='1';

else next_state <= s3;

end if;

elsif( one_dollar='1')then

if(choose="10") then

dispense<='1';

else next_state <= s4;

end if;

else next_state <= s2;

end if;

when s3 =>

if (choose="01") then dispense<='1';

elsif (choose="10") then

if (half_dollar='1')then

dispense<='1';

elsif(one_dollar='1')then

dispense<=’1’;

out1<=’1’;

else next_state<=s3;

end if;

elsif (choose="11")then

if (half_dollar='1')then

next_state <= s4;

elsif(one_dollar='1')then

dispense<='1';

else next_state<=s3;

end if;

else

next_state <= s3;

end if;

when s4 =>

if(choose="01") then

dispense<='1';

out1<='1';

elsif(choose="10") then

dispense<='1';

elsif (choose="11") then

if (half_dollar='1') then

dispense<='1';

elsif( one_dollar='1') then

out1 <= '1';

dispense<='1';

end if;

else next_state <= s4;

end if;

end case;

end process;

end behave;

4时序仿真

相关文档
最新文档