module fenpin(
rst_n,
clkin,
clkout
);
input rst_n;
input clkin;
output clkout;
reg clkout;
reg clk0,clk1,clk2;
reg clk0_reg,clk1_reg,clk2_reg;
reg [7:0] c0;
reg [6:0] c1,
reg [6:0] c2;
reg [3:0] c3;
always @(posedge clkin or negedge rst_n)
begin
if (!rst_n)
begin
clk0 <= 1'b0;
clk0_reg <= 1'b0;
c0 <= 8'd0;
end
else
begin
clk0_reg <= clk0;
if(c0 < 8'd200)
c0 <= c0 + 1'd1;
else
begin
clk0 <= ~clk0;
c0 <= 8'd0;
end
end
end
always @(posedge clkin or negedge rst_n)
begin
if (!rst_n)
begin
c1 <= 7'd0;
clk1 <= 1'b0;
clk1_reg <= 1'b0;
end
else
begin
clk1_reg <= clk1;
if(clk0 & (!clk0_reg))
begin
if(c1 < 8'd100)
c1 <= c1+1'b1;
else
begin
clk1 <= ~clk1;
c1 <= 7'd0;
end
end
end
end
always @(posedge clkin or negedge rst_n)
begin
if (!rst_n)
begin
c2 <= 7'd0;
clk2 <= 1'b0;
clk2_reg <= 1'b0;
end
else
begin
clk2_reg <= clk2;
if(clk1 & (!clk1_reg))
begin
if(c2 < 8'd100)
c2 <= c2 + 1'b1;
else
begin
clk2 <= ~clk2;
c2 <= 7'd0;
end
end
end
end
always @(posedge clkin or negedge rst_n)
begin
if (!rst_n)
begin
c3 <= 7'd0;
clk_out <= 1'b0;
end
else
begin
if(clk2 & (!clk2_reg))
begin
if(c3 < 4'd10)
c3 <= c3 + 1'b1;
else
begin
clk_out <= ~clk_out;
c3 <= 4'd0;
end
end
end
end
endmodule |