题解 | #序列发生器#

序列发生器

https://www.nowcoder.com/practice/1fe78a981bd640edb35b91d467341061

module sequence_generator(
	input clk,
	input rst_n,
	output reg data
	);
reg [2:0] cnt;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
cnt<=3'd0;
end
else
begin
cnt<= cnt== 3'd5 ? 3'd0 :cnt+3'd1;
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
data<=0;
end
else 
begin
case (cnt)
3'd0: begin  data<=1'b0; end
3'd1: begin  data<=1'b0; end
3'd2: begin  data<=1'b1; end
3'd3: begin  data<=1'b0; end
3'd4: begin  data<=1'b1; end
3'd5: begin  data<=1'b1; end
endcase 
end
end
endmodule

`timescale 1ns/1ns

module textbench();
reg clk , rst;
wire data;
sequence_generator u0(
	.clk(clk),
	. rst_n(rst),
	. data(data)
	);
 always #5 clk=~clk;
 initial 
 begin
 rst=0;clk=1;
 #25 rst=1;
 #300;
 $finish;
 end
endmodule

仿真波形如下:

全部评论

相关推荐

一只乌鸦:这不才9月吗,26到明年毕业前能一直找啊,能拿下提前批,转正的,offer打牌的都是有两把刷子的,为什么非要跟他们比。如果别人是9本硕+金牌+好几段大厂实习呢?如果别人是双非通天代呢?如果别人是速通哥呢?,做好自己就行了,我们做不到他们一样提前杀死比赛,但晚点到终点也没啥关系吧
双非应该如何逆袭?
点赞 评论 收藏
分享
LXXXXd:有点杂,想搞自动化的话没必要把法律的经历写上去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务