题解 | #序列发生器#

序列发生器

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

仿真波形如下:

全部评论

相关推荐

自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
那一天的Java_J...:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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