题解 | #占空比50%的奇数分频#

占空比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
    );

reg [2:0] cnt;
reg clock1, clock2;

//*************code***********//

always@(posedge clk_in or negedge rst) begin
	if(!rst) begin
		cnt <= '0;
	end
    else
        cnt <= cnt >= 6 ? 0 : cnt + 1;

end

always@(posedge clk_in or negedge rst) begin
	if(!rst) begin
		clock1 <= '0;
	end
    else
        clock1 <= ((cnt == 3) || (cnt == 6)) ? !clock1 : clock1;

end
always@(negedge clk_in or negedge rst) begin
	if(!rst) begin
		clock2 <= '0;
	end
    else
        clock2 <= ((cnt == 3) || (cnt == 6)) ? !clock2 : clock2;
end
//*************code***********//
assign clk_out7 = clock1 || clock2;
endmodule

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务