题解 | #占空比50%的奇数分频#
占空比50%的奇数分频
https://www.nowcoder.com/practice/ccfba5e5785f4b3f9d7ac19ab13d6b31
以三分频为例,时钟1在第一个时钟周期的上升沿翻转,时钟2在第2个时钟周期下降沿翻转,时钟1和时钟2都是每隔3周期重复上述翻转。最后时钟1和时钟2异或。
类比到7分频,假设计数从0到6循环,则时钟1在第6个计数周期上升沿翻转,时钟2在第3个计数周期下降沿翻转。最后异或。
`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; assign clk_out7 = clk1 ^ clk2; always @ (posedge clk_in or negedge rst) begin if(!rst) cnt <= 0; else if(cnt == 6) cnt <= 0; else cnt <= cnt + 1'b1; end always @ (posedge clk_in or negedge rst) begin if(!rst) clk1 <= 0; else if(cnt == 6) clk1 <= ~clk1; else begin clk1 <= clk1; end end always @ (negedge clk_in or negedge rst) begin if(!rst) clk2 <= 0; else if(cnt == 3) clk2 <= ~clk2; else clk2 <= clk2; end //*************code***********// endmodule