题解 | #占空比50%的奇数分频#
https://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 out7_1,out7_2;
always @(posedge clk_in or negedge rst) begin
if(!rst) cnt<=0;
else if(cnt==3'd6) cnt<=0;
else cnt<=cnt+1'b1;
end
always @(posedge clk_in or negedge rst) begin
if(!rst) out7_1<=0;
else if(cnt==3'd3||cnt==3'd6) out7_1<=~out7_1;
end
always @(negedge clk_in or negedge rst) begin
if(!rst) out7_2<=0;
else if(cnt==3'd3||cnt==3'd6) out7_2<=~out7_2;
end
assign clk_out7 = out7_1|out7_2;
//*************code***********//
endmodule
module odo_div_or
(
input wire rst ,
input wire clk_in,
output wire clk_out7
);
//*************code***********//
reg [2:0] cnt;
reg out7_1,out7_2;
always @(posedge clk_in or negedge rst) begin
if(!rst) cnt<=0;
else if(cnt==3'd6) cnt<=0;
else cnt<=cnt+1'b1;
end
always @(posedge clk_in or negedge rst) begin
if(!rst) out7_1<=0;
else if(cnt==3'd3||cnt==3'd6) out7_1<=~out7_1;
end
always @(negedge clk_in or negedge rst) begin
if(!rst) out7_2<=0;
else if(cnt==3'd3||cnt==3'd6) out7_2<=~out7_2;
end
assign clk_out7 = out7_1|out7_2;
//*************code***********//
endmodule