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

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

reg clk1, clk2;
reg [2:0]  cnt;

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

always @(posedge clk_in or negedge rst) begin
    if (!rst) clk1 <= 0; 
    else if (cnt == 'd3) clk1 = ~clk1;
    else if(cnt == 'd6) clk1 = ~clk1;
    else clk1 <= clk1;
end

always @(negedge clk_in or negedge rst) begin
    if (!rst) clk2 <= 0; 
    else if (cnt == 'd3) clk2 = ~clk2;
    else if(cnt == 'd6) clk2 = ~clk2;
    else clk2 <= clk2;
end

assign clk_out7 = clk1 || clk2;

//*************code***********//
endmodule

全部评论

相关推荐

在看牛客的社畜很积极:身高体重那一行信息去掉,学校那一行的信息放上面,找半天都没找到你是哪个学校什么专业的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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