硬件描述语言上机作业(2)

2019-04-15 18:57

initial begin repeat(6) begin

#10 coin=3'b000; #10 coin=3'b001;

#10 coin=3'b010;#10

coin=3'b001;#10

coin=3'b001;#10 coin=3'b001;#10 coin=3'b001;#10

else

case (current) s0:if(a) current<=s1; else current<=s0; s1:if(a) current<=s1; else current<=s2; s2:if(a) current<=s1; else current<=s3; s3:if(a) current<=s4; coin=3'b010;#10 coin=3'b010;#10 coin=3'b010;#10

coin=3'b010;

#10 coin=3'b101;#10

coin=3'b101;#10 coin=3'b101;#10 coin=3'b101;#10

coin=3'b101; end end always #5 clk=~clk; initial #3000 $finish; initial

$monitor($time,\%b,rst=%b\endmodule

2·状态机

利用状态机设计一个“10011”序列检测器,该检测器具有如下行为:在每一个时钟下降沿检查输入数据,当输入数据序列为“10011”时,输出asm被置为1;其余情况asm为0。 要求:画出fsm(有限状态机) 设计代码:

module status_10011(a,clk,rst,asm); input a,clk,rst; output asm;

parameter [2:0] s0 =3'b000, s1 =3'b001, s2 =3'b010, s3 =3'b011, s4 =3'b100, s5 =3'b101; reg [2:0] current; always @ (negedge clk) begin if(rst) current=s0;

else current<=s0; s4:if(a) current<=s5; else current<=s2; s5:if(a) current<=s1; else current<=s2; endcase end

assign asm = (current == s5) ? 1 : 0; endmodule 仿真代码: `timescale 1ns/1ns module status_10011_tb; reg a,clk,rst; wire asm;

status_10011 U1(.a(a),.clk(clk),.rst(rst),.asm(asm)); initial begin

a=0;clk=1;rst=1; end always #5 clk=~clk; always #21 a=~a; initial begin #30 rst=0; #200 rst=1; end initial

$monitor($time,\endmodule


硬件描述语言上机作业(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:爱提分三年级第三阶数字谜第07讲

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: