题解 | #状态机与时钟分频#

状态机与时钟分频

https://www.nowcoder.com/practice/25d694a351b748d9808065beb6120025

`timescale 1ns/1ns

module huawei7(
	input wire clk  ,
	input wire rst  ,
	output reg clk_out
);
parameter	s0 	=	4'b0001,
			s1	=	4'b0010,
			s2	= 	4'b0100,
			s3  =	4'b1000;

reg	[3:0]	cur_state;					
reg	[3:0]	nxt_state;

always@(posedge	clk or negedge rst)
	if(!rst)
		cur_state	<=	s0;
	else
		cur_state	<=	nxt_state;

always@(*)
	case(cur_state)		
		s0:
			begin
				nxt_state	<=	s1;
			end
		s1:
			begin
				nxt_state	<=	s2;
			end
		s2:
			begin
				nxt_state	<=	s3;
			end	
		s3:
			begin
				nxt_state	<=	s0;
			end
		default:
			begin
				nxt_state	<=	s0;
			end	
	endcase	

always@(*)
	case(cur_state)	
		s0,s2,s3:
			begin
				clk_out	<=	1'b0;
			end	
		s1:
			begin
				clk_out	<=	1'b1;
			end

		default:
				clk_out	<=	1'b0;
	endcase

endmodule

全部评论

相关推荐

hso_:哈哈哈哈哈哈我没offer一样在同一道题开喷了
投递深圳同为数码等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-26 15:46
已编辑
字节国际 电商后端 24k-35k
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务