always @(posedge clk_sys or negedge rst_n)
begin
if (!rst_n)
begin
clk_1M <= 0;
Cnt8 <= 8'b0;
end
else if(Cnt8 == 8'd24)
begin
clk_1M <= ~clk_1M;
Cnt8 <= 8'b0;
end
else
Cnt8 <= Cnt8 + 8'b1;
end
always @(posedge clk_1M or negedge rst_n)
begin
if (rst_n ==1'b0)
begin
Cntsh <= 16'b0;
clk_sh <= 1;
end
else if(Cntsh == 16'd20)
begin
clk_sh <= ~clk_sh;
Cntsh <= Cntsh + 16'b1;
end
else if(Cntsh == 16'd10655)
begin
clk_sh <= ~clk_sh;
Cntsh <= 16'b0;
end
else
Cntsh <= Cntsh + 16'b1;
end
always @(posedge clk_sys or negedge rst_n)
begin
if (rst_n ==1'b0)
begin
clk_500k_1A <= 'b1;
clk_500k_2A <= 'b0;
Cnt_A8 <= 8'b0;
end
else if(clk_sh == 0)
begin
if(Cnt_A8 == 8'd49)
begin
clk_500k_1A <= ~clk_500k_1A;
clk_500k_2A <= ~clk_500k_2A;
Cnt_A8 <= 8'b0;
end
else
Cnt_A8 <= Cnt_A8 + 8'b1;
end
else
begin
clk_500k_1A <= 'b1;
clk_500k_2A <= 'b0;
end
end
always @(posedge clk_sys or negedge rst_n)
begin
if(rst_n ==1'b0)
Cnt_delay1 <= 8'b0;
else if(clk_sh==0)
begin
if(Cnt_delay1 == 8'd40)
Cnt_delay1 <= Cnt_delay1;
else
Cnt_delay1 <= Cnt_delay1 + 8'b1;
end
else
Cnt_delay1 <= 8'b0;
end
always @(posedge clk_sys or negedge rst_n)
begin
if(rst_n ==1'b0)
Cnt_delay2 <= 8'b0;
else if(clk_sh==0)
begin
if(Cnt_delay2 == 8'd45)
Cnt_delay2 <= Cnt_delay2;
else
Cnt_delay2 <= Cnt_delay2 + 8'b1;
end
else
Cnt_delay2 <= 8'b0;
end
always @(posedge clk_sys or negedge rst_n)
begin
if (rst_n ==1'b0)
begin
clk_1M_rs <= 1;
Cnt_B8 <= 8'b0;
end
else if(clk_sh == 0 && Cnt_delay1 == 8'd40)
begin
if(Cnt_B8 == 8'd27)
begin
clk_1M_rs <= ~clk_1M_rs;
Cnt_B8 <= Cnt_B8 + 8'b1;
end
else if(Cnt_B8 == 8'd40)
begin
clk_1M_rs <= ~clk_1M_rs;
Cnt_B8 <= Cnt_B8 + 8'b1;
end
else if(Cnt_B8 == 8'd49)
Cnt_B8 <= 8'b0;
else
Cnt_B8 <= Cnt_B8 + 8'b1;
end
else begin
clk_1M_rs <= 1;Cnt_B8 <= 8'b0;end
end
always @(posedge clk_sys or negedge rst_n)
begin
if (rst_n ==1'b0)
begin
clk_1M_cp <= 1;
Cnt_C8 <= 8'b0;
end
else if(clk_sh == 0 && Cnt_delay2 == 8'd45)
begin
if(Cnt_C8 == 8'd36)
begin
clk_1M_cp <= ~clk_1M_cp;
Cnt_C8 <= Cnt_C8 + 8'b1;
end
else if(Cnt_C8 == 8'd48)
begin
clk_1M_cp <= ~clk_1M_cp;
Cnt_C8 <= Cnt_C8 + 8'b1;
end
else if(Cnt_C8 == 8'd49)
Cnt_C8 <= 8'b0;
else
Cnt_C8 <= Cnt_C8 + 8'b1;
end
else begin
clk_1M_cp <= 1;Cnt_C8 <= 8'b0;end
end
endmodule