描述
题目描述:
使用状态机实现时钟分频,要求对时钟进行四分频,占空比为0.25
信号示意图:

clk为时钟
 rst为低电平复位
 clk_out 信号输出
 Ps 本题题解是按照1000的状态转移进行的,不按照此状态进行,编译器可能报错但没有影响。
波形示意图:

输入描述:
clk为时钟
 rst为低电平复位
输出描述:
clk_out 信号输出
`timescale 1ns/1ns
module huawei7(
	input wire clk  ,
	input wire rst  ,
	output reg clk_out
);
//*************code***********//
reg [2:0] state_r = 3'd0, state_s;
always @(posedge clk, negedge rst) begin
	if (~rst) begin
		state_r <= 3'd0;
	end else begin
		state_r <= state_s;
	end
end
always @(*) begin
	case (state_r)
	0: state_s = 1;
	1: state_s = 2;
	2: state_s = 3;
	3: state_s = 0;
	default: state_s = 0;
	endcase
end
always @(posedge clk, negedge rst) begin
	if (~rst) begin
		clk_out <= 1'b0;
	end else begin
		case (state_s)
		default: clk_out <= 1'b0;
		1: clk_out <= 1'b1;
		endcase
	end
end
//*************code***********//
endmodule



















