题解 | #序列发生器#

序列发生器

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

`timescale 1ns/1ns

module sequence_generator(
	input clk,
	input rst_n,
	output reg data
	);

parameter idle=0,s1=1,s2=2,s3=3,s4=4,s5=5,s6=6;

reg [3:0] state,n_state;
always@(*)
case(state)
idle:   n_state = s1;
s1:		n_state = s2;
s2:		n_state = s3;
s3: 	n_state = s4;
s4:		n_state = s5;
s5:		n_state = s6;
s6:		n_state = s1;
endcase

always@(posedge clk or negedge rst_n)
if(!rst_n)
state <= 0;
else
state <= n_state;

always@(posedge clk or negedge rst_n)
if(!rst_n)
data <= 0;
else if(n_state==s1 | n_state==s2 | n_state==s4)
data <= 0;
else if(n_state==s3 | n_state==s5 | n_state==s6)
data <= 1;

endmodule

全部评论

相关推荐

怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
05-11 20:45
门头沟学院 Java
有担当的灰太狼又在摸...:零帧起手查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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