题解 | #占空比50%的奇数分频#
占空比50%的奇数分频
http://www.nowcoder.com/practice/ccfba5e5785f4b3f9d7ac19ab13d6b31
由于非偶数分频,采用电平计数较为方便
完整代码:
`timescale 1ns/1ns
module odo_div_or
(
input wire rst ,
input wire clk_in,
output wire clk_out7
);
//*************code***********//
reg[2:0] cnt;
reg out;
assign clk_out7 = out;
always@(rst or clk_in)begin
if(~rst)
cnt = 0;
else
cnt = cnt==6? 0: cnt+1;
end
always@(*)begin
if(~rst)
out = 0;
else if(cnt == 0) //过程块是电平触发,要在下个上升沿反转,条件为cnt==0
out = ~out;
end
//*************code***********//
endmodule