文档详情

自动售饮料机设计.doc

发布:2017-06-08约3.86千字共7页下载文档
文本预览下载声明
现代电路与系统设计 自动售饮料机设计 自动售饮料机设计 1设计要求的提出和功能的构想[1][2] 该饮料机能识别0.5元和1.0元两种硬币; 售出3种不同价格的饮料,饮料价格分别为2.5元、3.0元和3.5元; 具有找零功能; 购买者能自主选择所购买的饮料; 饮料机在每卖出一次饮料后能自动复位。 因为饮料的价格最高为3.5元,所以设计饮料机最多可接受4.0元的硬币。 2分析设计要求并画出原始状态图 该自动售饮料机设有一个投币孔,通过传感器来识别两种硬币,给出两个不同的信号。在此用half_dollar和one_dollar分别表示投入0.5元和1.0元硬币后电路接收到的两个信号;三个饮料选择按键choose01表示选择价格为2.5元的饮料,choose10表示选择价格为3.0元的饮料,choose11表示选择价格为3.5元的饮料;rest表示复位按键;有2个输出口分别为饮料出口dispense和找零出口out1;用s0表示初始状态,s1表示投入0.5元硬币时的状态,s2表示投入1.0元硬币时的状态,s3表示投入1.5元硬币时的状态,s4表示投入2.0元时的状态;clk表示时钟信号;机器最多接受的钱币为4.0元。 当投入的钱币到达2.5元或高于2.5元时机器处于开始出售饮料的状态。当到达2.5元时如果选择购买2.5元的饮料(choose01)则系统给出一个饮料,即dispense为高电平一次。如果投入的钱币到达3.0元并且选择购买2.5元的饮料则系统显示给出一个饮料并找出1枚0.5元的硬币,即dispense为高电平一次out1为高电平一次。如果选择购买3.0元的饮料(choose10),则系统显示给出一个3.0元的饮料,即饮料输出信号dispense为高电平一次。依次类推。 图1.1为本次设计所构想的状态图。 图1.1 状态图 3程序设计 根据上述对自动售饮料机逻辑状态的分析,编写程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity stmch1 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 stmch1; architecture behave of stmch1 is type state_values is (s0 , s1 , s2 ,s3 ,s4,s5 ,s6 , s7); signal state , next_state: state_values; begin process (clk , rst) begin if rst = 1 then state = s0; elsif (clkevent 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 next_state = s3; elsif( one_dollar=1) then next_state = s4; else next_state = s2; end if; when s3 = if (half_dollar=1) then next_state = s4; elsif( one_dollar=1) then next_state=s5; else next_state = s3; end
显示全部
相似文档