当前位置:文档之家› 数字逻辑实验 8_序列检测器

数字逻辑实验 8_序列检测器

实验八序列检测器的设计与仿真一、实验要求1.用VHDL语言设计一个Mealy机以检测“1101001”序列;2.用VHDL语言设计一个Moore机以检测“1101001”序列;3.在文本编辑区使用VHDL硬件描述语言设计逻辑电路,再利用波形编辑区进行逻辑功能仿真,以此验证电路的逻辑功能是否正确。

二、实验内容用VHDL语言设计各一个mealy和moore状态机测试“1101001”位串的序列检测器,并通过仿真波形验证设计的功能是否正确。

三、实验过程由于在报告1中已经详尽描述了如何使用Quartus 2建立逻辑原理图和使用VHDL语言实现元件功能,所以本次的实验报告中便不再赘述上述内容,报告将主要就VHDL 语言描述实现元件的功能的过程进行阐述。

1.Mealy机选择File→New,弹出新建文本对话框,在该对话框中选择VHDL File并单击OK按钮,进入文本编辑窗口,输入VHDL代码。

library ieee;use ieee.std_logic_1164.all;entity melay isport(clk,rst,d: in std_logic;z: out std_logic);end melay;architecture arc of melay istype state_type is(s0,s1,s2,s3,s4,s5,s6);signal state: state_type;beginprocess(clk,rst)beginif rst= '1' thenstate<=s0;elsif (clk'event and clk ='1') thencase state is --1101001when s0 =>if d='1' thenstate<=s1;elsestate<=s0;end if;when s1=>if d='1' thenstate<=s2;elsestate<=s0;end if;when s2=>if d='0' thenstate<=s3;elsestate<=s2;end if;when s3=>if d='1' thenstate<=s4;elsestate<=s0;end if;when s4=>if d='0' thenstate<=s5;elsestate<=s1;end if;when s5=> --1101001if d='0' thenstate<=s6;elsestate<=s1;end if;when s6=>if d='1' thenstate<=s0;elsestate<=s0;end if;end case;end if;end process;process(state,d)begincase state iswhen s6=>if d='1' thenz<='1';elsez<='0';end if;when others=>z<='0';end case;end process;end arc;保存文件并编译,选择菜单File→New,选择Vector Waveform File新建波形图,添加节点,参数设置为:End Time=2us, Grip size=50ns。

所完成的波形图如下图:波形解释:rst为复位端,高电平有效,返回最初状态;clk为时钟信号输入端口;,state。

s0~s6表示mealy机中各步状态;z表示检测序列为“1101001”时,表示输出高电平。

保存波形文件,并在settings中选择functional功能仿真,绘制网格,仿真可得出如图波形:根据mealy状态表和序列检测器相应功能验证,当rst=‘1’时,不管当前状态为何,都将被初始为最初态s0;当输入d端依次输入“1101001”时,当检测到最后一位输入正确的同时,z端马上跳为高电平,表示所检测序列正确。

其他可看出,当处于时钟上升沿时,state 中各状态依照输入数据依次跳变。

最后mealy机成功检测出相应序列,设计成功。

已知序列检测器的Mealy机状态表为:同样可依次对照上述仿真图形,显然上述序列检测器mealy机功能设计正确。

2.序列检测器moore机选择File→New,弹出新建文本对话框,在该对话框中选择VHDL File并单击OK按钮,进入文本编辑窗口,输入VHDL代码。

library ieee;use ieee.std_logic_1164.all;entity moore isport(clk,rst,d: in std_logic;z: out std_logic);end moore;architecture arc of moore is --moore:输出只和当前状态有关;type state_type is(s0,s1,s2,s3,s4,s5,s6,s7);signal state:state_type;beginprocess(clk,rst)beginif rst= '1' then --1101001state<=s0;elsif(clk'event and clk='1') thencase state is --1101001when s0 =>if d='1' thenstate<=s1;elsestate<=s0;end if;when s1=>if d='1' thenstate<=s2;elsestate<=s0;end if;when s2=>if d='0' thenstate<=s3;elsestate<=s2;end if;when s3=>if d='1' thenstate<=s4;elsestate<=s0;end if;when s4=>if d='0' thenstate<=s5;elsestate<=s1;end if;when s5=> --1101001if d='0' thenstate<=s6;elsestate<=s1;end if;when s6=>if d='1' thenstate<=s7;elsestate<=s0;end if;when s7=>if d='1' thenstate<=s1;elsestate<=s0;end if;end case;end if;end process;process(state,d)begincase state iswhen s6=>if d='1' thenz<='1';elsez<='0';end if;when others=>z<='0';end case;end process;end arc;可看出,moore机的设计和mealy机上大体相同,只有在状态的传递上有细微区别。

保存文件并编译,选择菜单File→New,选择Vector Waveform File新建波形图,添加节点,参数设置为:End Time=3us, Grip size=50ns。

所完成的波形图如下图:图中各端口设置功能同mealy机。

保存波形文件,并在settings中选择functional功能仿真,绘制网格,仿真可得出如图波形:仿真波形分析:由于设计的moore状态机检测序列功能相同,与mealy不同在于当状态跳变判断s7时,z端才跳变为高电平。

根据刚刚对mealy机的仿真分析和下表的状态值变化显然可知,moore 机实现了检测序列“1101001”的功能,设计成功。

已知序列检测器的Mealy机状态表为:四、总结本节实验中,通过对用VHDL语言对mealy状态机和moore状态机进行设计,更加熟练了使用VHDL语言对元件的设计。

也通过用不同的状态机设计序列检测器,而对两种状态机的区别有了更深刻的了解。

Moore状态机输出只和当前状态有关,而mealy机输出和当前状态和输入信号有关,由于moore机没有组合逻辑,所以moore机的状态会多一些。

也对序列检测器的实现使得我对序列检测器的作用和功能了之于心。

一开始没有弄清moore 机和mealy机的区别,导致后来写moore机的时候出现了停滞,不过在弄清他们的区别时候,写出moore机就没什么问题了。

不已然,已经到了数字逻辑的最后一个实验了,回想做实验时,有苦有乐,从开始的对VHDL语言的一窍不通,到现在可以用它设计简单的元件并实现功能,实验中我收获了许多,实验对我成长的帮助必不可少。

虽然马上就要结束实验,不过还有许多VHDL语言的奥妙在可以发挥它的地方等待着我们去探索,我也会继续探索VHDL语言,用它来实现更多好玩好用的东西。

2013/12/23。

相关主题