序列检测器(10010)

这是夏宇闻老师第十五章的实践。具体内容参看书本。下面是我的实践内容。

//源代码:
module seqdet(clk,x,z,rst);
input clk,x,rst;
output z;
reg z;
reg [7:0] state;
parameter IDLE=8'b0000_0001,A=8'b0000_0010,B=8'b0000_0100,C=8'b0000_1000,D=8'b0001_0000,E=8'b0010_0000,F=8'b0100_0000,G=8'b1000_0000;
always@(posedge clk or negedge rst)
begin
if(!rst) state<=IDLE;
else
casex(state)IDLE:if(x==0) beginstate<=IDLE;z<=0;endelse beginstate<=A;z<=0;endA:if(x==0) beginstate<=B;z<=0;endelse beginstate<=A;z<=0;endB:if(x==0) beginstate<=C;z<=0;endelse beginstate<=F;z<=0;endC:if(x==0) beginstate<=G;z<=0;endelse beginstate<=D;z<=0;endD:if(x==0) beginstate<=E;z<=1;endelse beginstate<=A;z<=0;endE:if(x==0) beginstate<=C;z<=0;endelse beginstate<=A;z<=0;endF:if(x==0) beginstate<=B;z<=0;endelse beginz<=0;state<=A;endG:if(x==0) beginstate<=G;z<=0;endelse beginz<=0;state<=F;enddefault: state<=IDLE;
endcase
end
endmodule 
//测试代码
`timescale 1ns/1ns
`define clockperiod 20
module t;
reg clk,rst;
reg [23:0] data;
wire z,x;
assign x=data[23];
initialbeginclk=0;rst=1;#2 rst=0;#30 rst=1;data=20'b1100_1001_0000_1001_0100;#(`clockperiod*1000) $stop;end
always #(`clockperiod)  clk=~clk;
always@(posedge clk)
#2 data={data[22:0],data[23]};//序列移位
seqdet seqdet0(
.clk(clk),
.x(x),
.z(z),
.rst(rst)
);
endmodule 

在我编写的过程中,遇到了一些问题。
1.在编写源代码是使用了两个always块,并且在两个always块中对同一变量进行赋值,报错this signal is connected to multiple drivers。
在这里插入图片描述
解决办法:切记不要在两个always块中对同一变量赋值,这样容易报错。
复习:夏宇闻第十四章中的原则6)在不同always中,不要为同一个变量赋值。
2.在编写测试文件时,把测试文件名和目标文件名重合。报错信息:Instantiating ‘u_state_machine_pkt_top’ has exceeded the recursion depth limit
解决办法:改名。
网上教程:https://blog.csdn.net/qq_33231534/article/details/104782068
3.在进行联合仿真时,应该编译底层文件(test文件),而不是目标文件。
应该把测试文件设置为顶层文件。
在这里插入图片描述
最终的仿真结果:
在这里插入图片描述

都是一些小白问题,各位大佬不要见笑啊。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部