题解 | #占空比50%的奇数分频#
占空比50%的奇数分频
https://www.nowcoder.com/practice/ccfba5e5785f4b3f9d7ac19ab13d6b31
更简便的方法,通过cnt产生clk_n时钟,然后直接用待分频时钟上升沿对时钟clk_n打半拍得到时钟clk_p,最后将clk_p和clk_n相或就可以得到占空比为50%的7分频时钟
`timescale 1ns/1ns module odo_div_or ( input wire rst , input wire clk_in, output wire clk_out7 ); //*************code***********// reg clk_p, clk_n; reg [2:0] cnt; always@(posedge clk_in or negedge rst) begin if(!rst) cnt <= 0; else if(cnt == 6) cnt <= 0; else cnt <= cnt +1; end always@(negedge clk_in or negedge rst) begin if(!rst) clk_n <= 0; else if(cnt == 3 || cnt == 6) clk_n <= ~clk_n; end always@(posedge clk_in or negedge rst) begin if(!rst) clk_p <= 0; else clk_p <= clk_n; end assign clk_out7 = clk_p | clk_n; //*************code***********// endmodule