题解 | #无占空比要去的奇数分频#

无占空比要去的奇数分频

https://www.nowcoder.com/practice/12d0615157a04e43bb7f41debc3cfa5b

`timescale 1ns/1ns

module odd_div (    
    input     wire rst ,
    input     wire clk_in,
    output    wire clk_out5
);
//*************code***********//
reg [2:0] count;
reg clk_out5_reg;
assign clk_out5 = clk_out5_reg;

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

always @(posedge clk_in or negedge rst)begin
    if(!rst)begin
        clk_out5_reg <= 0;
    end
    else begin
        if(count == 3'b000)begin
            clk_out5_reg <= ~clk_out5_reg;
        end
        else if(count == 3'b010)begin
            clk_out5_reg <= ~clk_out5_reg;
        end
        else begin
            clk_out5_reg <= clk_out5_reg;
        end
    end
end

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

全部评论

相关推荐

否极泰来来来来:解约赔多少
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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