讨论使用D触发器设计一个11001序列检测器,讨论序列可交迭(Overlap)检测和不可交迭检测在设计上的区别,讨论分别采用Mealy机设计和采用Moore机设计的区别,讨论未用状态的处理问题。
【要求】给出电路原理图或HDL代码,要求进行仿真,并给出仿真结果。
1.原件介绍D触发器(74LS74)、“与”门(74LS08)、“或”门(74LS32)、“非”门(74LS04),集成电路引脚2.设计思路根据要求,设计的序列检测器有一个外部输入x和一个外部输出Z。
输入和输出的逻辑关系为:当外部输入x第一个为"1",外部输出Z为"0";当外部输入x第二个为"1",外部输出Z为"0";当外部输入第三个x为"0",外部输出Z为"0",当外部输入第四个x为“0”,外部输出Z为0,当外部输入第五个x为“1”,输入X 0 1 1 1 0 0 1 0 1输出Y 0 0 0 0 0 0 1 0 0要判别序列检测器是否连续接收了"11001",电路必须用不同的状态记载外部输入x的值。
假设电路的初始状态为A,x 输入第一个"1",检测器状态由A装换到B,用状态B记载检测器接受了"11001"序列的第一个"1",这时外部输出Z=0;x输入第二个"1",检测器状态由B装换到C,用状态C记载检测器接了“11001”序列的第二个"1",外部输出Z=0;x输入第三个"0",检测器状态由C装换到D,外部输出Z=0;x输入第四个为“0”,检测器状态由D装换到E,外部输出Z=0;x输入第五个为“1”,检测器状态由E装换到F,外部输出Z=1。
然后再根据外部输入及其他情况时的状态转移,写出相应的输出。
以上分析了序列检测器工作,由此可画出原始状态图。
根据原始状态图可列出原始状态表。
状态转换表ABDCEF1\01\00\00\01\10\00\01\01\00\00\0ZZ=A 0'1'2Q Q Q Q2*='01'2'Q Q Q AQ1*=01'202Q Q Q Q AQ +'Q0*='0'1'01'2'210'Q AQ Q Q AQ Q Q Q A ++D2=Q2* D1=Q1* D0=Q0*3.未用状态关于未用状态涉及到了D 触发器自启动的检验:前一状态为 111时,Q3*=A ’; Q2*=0; Q1*=A,下一状态为有效状态。
前一状态为110时,Q3*=A; Q2*=1; Q1*=1,对A 值分类讨论: A=0,下一状态为有效状态;A=1,下一状态为111,再下一个状态为有效状态。
4.实际代码设计与仿真MOORE 机有交迭的程序设计library ieee;use ieee.std_logic_1164.all; entity schk isport(din,clk,rst:in std_logic; sout:out std_logic); end schk;architecture behave of schk istype states is(s0,s1,s2,s3,s4,s5); signal st,nst:states :=s0; begincom: process(st,din) begin case st iswhen s0=> if din='1' then nst <=s1;else nst <= s0; end if;when s1=> if din='1' then nst <=s2;else nst <= s0; end if;when s2=> if din='0' then nst <=s3;else nst <= s0; end if;when s3=> if din='0' then nst <=s4;else nst <= s0; end if;when s4=> if din='1' then nst <=s5;else nst <= s0; end if;when s5=> if din='1' then nst <=s2;else nst <= s0;end if;when others => nst <=s0; end case; end process;reg:process (clk,rst) begin--shixujinchengif rst='1' then st <=s0;elsif clk'event and clk='1' then st <= nst; end if;end process reg;sout <= '1' when st=s5 else '0';end behave;仿真结果小的体现了交迭mealy有交迭的程序设计library ieee;use ieee.std_logic_1164.all;entity schk2 isport(din,clk,rst:in std_logic;sout:out std_logic);end schk2;architecture behave of schk2 istype states is(s0,s1,s2,s3,s4,s5);signal st:states :=s0;beginprocess(clk,rst,st,din) beginif rst='1' then st <=s0; elsif clk'event and clk='1' then case st iswhen s0=> if din='1' then st <=s1; else st <= s0;end if; when s1=> if din='1' then st <=s2; else st <= s0;end if; when s2=> if din='0' then st <=s3; else st <= s0;end if; when s3=> if din='0' then st <=s4; else st <= s0;end if; when s4=> if din='1' then st <=s5; else st <= s0;end if; when s5=> if din='1' then st <=s2; else st <= s0;end if; when others => st <=s0;end case;if(st=s5) then sout<='1'; else sout <= '0';end if ; end if;end process;end behave;实现检测11001的图体现交迭的图Mealy机无交叠的library ieee;use ieee.std_logic_1164.all;entity schk2 isport(din,clk,rst:in std_logic;sout:out std_logic);end schk2;architecture behave of schk2 istype states is(s0,s1,s2,s3,s4,s5);signal st:states :=s0;beginprocess(clk,rst,st,din) beginif rst='1' then st <=s0; elsif clk'event and clk='1' then case st iswhen s0=> if din='1' then st <=s1; else st <= s0; end if;when s1=> if din='1' then st <=s2; else st <= s0; end if;when s2=> if din='0' then st <=s3; else st <= s0; end if;when s3=> if din='0' then st <=s4; else st <= s0; end if;when s4=> if din='1' then st <=s5; else st <= s0; end if;when s5=> if din='1' then st <=s0; else st <= s0; end if;when others => st <=s0;end case;if(st=s5) then sout<='1'; else sout <= '0';end if ; en d if;end process;end behave;体现没有交迭的Moore没有交迭的图library ieee;use ieee.std_logic_1164.all;entity schk isport(din,clk,rst:in std_logic;sout:out std_logic);end schk;architecture behave of schk istype states is(s0,s1,s2,s3,s4,s5);signal st,nst:states :=s0;begincom: process(st,din) begincase st iswhen s0=> if din='1' then nst <=s1;else nst <= s0; end if;when s1=> if din='1' then nst <=s2;else nst <= s0; end if;when s2=> if din='0' then nst <=s3;else nst <= s0; end if;when s3=> if din='0' then nst <=s4;else nst <= s0; end if;when s4=> if din='1' then nst <=s5;else nst <= s0; end if;when s5=> if din='1' then nst <=s0;else nst <= s0; end if;when others => nst <=s0;end case;end process;reg:process (clk,rst) begin--shixujinchengif rst='1' then st <=s0;elsif clk'event and clk='1' then st <= nst; end if;end process reg;sout <= '1' when st=s5 else '0';end behave;5.关于二者设计上的不同Mealy状态机与Moore有限状态机不同,Mealy有限状态机的输出不但与当前状态有关,而且与输入信号的当前值有关,所以在st的赋值上二者会有不同,Moore赋给nst(下一状态的),mealy给st。