高手给一个关于奇数分频的verilog代码
有人发了吧
对占空比不做要求就很容易
顶顶顶顶!
5分频 duty=0。5
module fen5(clkin,clkout);
input clkin;
output clkout;
wire sig1;
wire sig2;
reg [2:0] s1;
reg [2:0] s2;
always@(posedge[/email] clkin)begin
case(s1)
3'b000:s1<=3'b001;
3'b001:s1<=3'b010;
3'b010:s1<=3'b011;
3'b011:s1<=3'b100;
3'b100:s1<=3'b000;
default:s1<=3'b000;
endcase
end
always@(negedge[/email] clkin)begin
case(s2)
3'b000:s2<=3'b001;
3'b001:s2<=3'b010;
3'b010:s2<=3'b011;
3'b011:s2<=3'b100;
3'b100:s2<=3'b000;
default:s2<=3'b000;
endcase
end
assign sig1=&{s1[1],s1[0]};
assign sig2=&{s2[1],s2[0]};
assign clkout=s1[2]|s2[2]|sig1|sig2;
endmodule
恩,数上五个上升下降边沿再跳就可以啊,
分频如下即可: clk: ___|----|___|----|____|----|____|----|____|----|____
s1: ____|---------|______________|-----------|_______
s2: ______|---------|_______________|----------|_____
out = S1 | S2 ;
用状态机写
但是占空比不是50%
而是 (x-1)/ 2 / x