题解 | #占空比50%的奇数分频#
占空比50%的奇数分频
https://www.nowcoder.com/practice/ccfba5e5785f4b3f9d7ac19ab13d6b31
奇数分频可以利用上升沿采样的clk1和下降沿采样的clk2,通过与、或、异或三种方式得到,这里仅提供异或产生奇数分频的电路实现方式
`timescale 1ns/1ns
module odo_div_or
(
input wire rst ,
input wire clk_in,
output wire clk_out7
);
//*************code***********//
reg clk1,clk2;
reg [2:0] cnt;
always @(posedge clk_in, negedge rst)
begin
if(!rst) cnt <= 0;
else if(cnt == 6)
cnt <= 0;
else cnt <= cnt + 1;
end
always @(posedge clk_in, negedge rst)
begin
if(!rst) clk1 <= 0;
else if(cnt == 6) clk1 <= ~clk1;
else clk1 <= clk1;
end
always @(negedge clk_in, negedge rst)
begin
if(!rst) clk2 <= 0;
else if(cnt == 3) clk2 <= ~clk2;
else clk2 <= clk2;
end
assign clk_out7 = clk1 ^ clk2;
//*************code***********//
endmodule