基于VHDL的自动售货机的设计与实现

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

自动售货机实验报告

一、设计任务

设计一个自动售货饮料机,设每瓶饮料2.5元,投币口有两个,1元硬币(one)或5角硬币(half),每个时刻可以输入其中一种硬币,自动售货机有找零钱功能,oute为出货,outm为找零。

二、设计过程

1.设计思路:

状态定义:s0表示初态,s1表示投入5角,s2表示投入1元,s3表示投入1元5角,s4表示投入2元,s5表示投入2元5角,s6表示投入3元。

输入信号:state_outputs(0)表示输入货物,comb_outputs(1)表示找5角硬币,输入信号为1 表示投入硬币,输入信号为1表示未投入硬币。

输出信号:comb_outputs(0)表示输出货物,comb_outputs(1)表示找5角零钱,输出信号为1表示输出货物或找零,输入信号为0表示不输出货物或找零。

根据设计要求分析,得到状态转化图如下图所示,其中状态为s0、S1、S2、S3、S4、S5、S6;输入为state_inputs(0,1);输出为comb_outouts(0,1);输入仅与状态有关,因此将输入写在状态圈内部。

2.设计步骤:

(1)创建工程。打开QuartusII ,创建一个新的工程并命名。根据实验室条件,选择的芯片为cyclone 系列中的EP1C6Q240C8芯片。

00

输入VHDL文本文件。新建文本文件VHDL file。输入程序并保存。程序如下:library ieee;

use ieee.std_logic_1164.all;

entity autosell is

port(clk,reset :in std_logic;

state_inputs:in std_logic_vector(0 to 1);

comb_outputs:out std_logic_vector(0 to 1));

end autosell;

architecture be of autosell is

type fsm_st is(s0,s1,s2,s3,s4,s5,s6);

signal current_state,next_state:fsm_st;

begin

reg:process(reset,clk)

begin

if reset='1'then current_state<=s0;

elsif rising_edge(clk)then

current_state<=next_state;

end if;

end process;

com:process(current_state,state_inputs)

begin

case current_state is

when s0=>comb_outputs<="00";

if

state_inputs="00" then next_state<=s0;

elsif state_inputs="01" then next_state<=s1;

elsif state_inputs="10" then next_state<=s2; end if;

when s1=>comb_outputs<="00";

if

state_inputs="00" then next_state<=s1;

elsif state_inputs="01" then next_state<=s2;

elsif state_inputs="10" then next_state<=s3; end if;

when s2=>comb_outputs<="00";

if

state_inputs="00" then next_state<=s2;

elsif state_inputs="01" then next_state<=s3;

elsif state_inputs="10" then next_state<=s4; end if;

when s3=>comb_outputs<="00";

if

state_inputs="00" then next_state<=s3;

elsif state_inputs="01" then next_state<=s4;

elsif state_inputs="10" then next_state<=s5; end if;

when s4=>comb_outputs<="00";

if

state_inputs="00" then next_state<=s4;

elsif state_inputs="01" then next_state<=s5;

elsif state_inputs="10" then next_state<=s6;

end if;

when s5=>comb_outputs<="10";

if

state_inputs="00" then next_state<=s0;

elsif state_inputs="01" then next_state<=s1;

elsif state_inputs="10" then next_state<=s2;

end if;

when s6=>comb_outputs<="11";

if

state_inputs="00" then next_state<=s0;

elsif state_inputs="01" then next_state<=s1;

elsif state_inputs="10" then next_state<=s2; end if;

相关文档
最新文档