分别采用上升沿进行一个占空比为2/3的始终,在次用下降样设计同样的占空比,最后将两者进行相与,得到占空比为50%的三分频电路。
// Code your design here
`timescale 1ns/1ps
module div3_half(
input Sys_clk,
input Sys_reset,
output div3 ,
output clk1,
output clk2
);
reg clk1;//2/3 is high posedge
reg clk2;//2/3 is high negedge
//counter
reg [1:0]count;
always @ (posedge Sys_clk )
if(!Sys_reset)
count <= 2'b0;
else if(count ==2'd2)
count <= 2'b0;
else
count <= count +1'b1;
always @(posedge Sys_clk )
if(!Sys_reset)
begin
clk1 <=1'b1;
end
else if(count == 2'd1 | count == 2'd2)
clk1 <= ~clk1;
always @(negedge Sys_clk )
if(!Sys_reset)
begin
clk2 <=1'b1;
end
else if(count == 2'd2 | count ==2'd1)
clk2 <= ~clk2;
//------------------------------------------------
assign div3 =clk1 & clk2;
endmodule