题解 | #占空比50%的奇数分频#
占空比50%的奇数分频
http://www.nowcoder.com/practice/ccfba5e5785f4b3f9d7ac19ab13d6b31
需要声明一个计数器cnt,计数最大值为7。
另外声明两个寄存器clk1,clk2。
clk1:clk_in上升沿到来时cnt=2|cnt=6时对clk1取反;
clk2:clk_in下降沿到来时cnt=2|cnt=6时对clk1取反;
clk_out7为clk1与clk2取逻辑或。
`timescale 1ns/1ns
module odo_div_or
(
input wire rst ,
input wire clk_in,
output wire clk_out7
);
//*************code***********//
reg [2:0] cnt;
reg clk1;
reg clk2;
always@(posedge clk_in or negedge rst)begin
if(!rst)begin
cnt <= 3'd0;
end
else if(cnt == 3'd6)begin
cnt <= 3'd0;
end
else begin
cnt <= cnt + 1'b1;
end
end
always@(posedge clk_in or negedge rst)begin
if(!rst)begin
clk1 <= 1'b0;
end
else if((cnt == 3'd3) || (cnt == 3'd6))begin
clk1 <= ~clk1;
end
end
always@(negedge clk_in or negedge rst)begin
if(!rst)begin
clk2 <= 1'b0;
end
else if((cnt == 3'd3) || (cnt == 3'd6))begin
clk2 <= ~clk2;
end
end
assign clk_out7 = clk1 | clk2;
//*************code***********//
endmodule
携程公司氛围 125人发布