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

无占空比要去的奇数分频

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

`timescale 1ns/1ns

module odd_div (    
    input     wire rst ,
    input     wire clk_in,
    output    wire clk_out5
);
//*************code***********//
parameter N = 5;
reg clk_p,clk_n;
reg [2:0] cnt_p,cnt_n;

always@(posedge clk_in or negedge rst)
  if(!rst) 
    cnt_p <= 3'd0;
  else if(cnt_p == N-1)
    cnt_p <= 3'd0;
  else
    cnt_p <= cnt_p + 1'b1;


always@(posedge clk_in or negedge rst)
  if(!rst) begin
    clk_p <= 1'b0;
  end
  else if((cnt_p==(N-1)/2)||(cnt_p==0))
    clk_p <= ~clk_p;
  else
    clk_p <= clk_p;

//非50%占空比
assign clk_out5 = clk_p;

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

// always@(negedge clk_in or negedge rst)
//   if(!rst) 
//     cnt_n <= 3'd0;
//   else if(cnt_n == N-1)
//     cnt_n <= 3'd0;
//   else
//     cnt_n <= cnt_n + 1'b1;


// always@(negedge clk_in or negedge rst)
//   if(!rst) begin
//     clk_n <= 1'b0;
//   end
//   else if((cnt_n==(N-1)/2)||(cnt_n==0))
//     clk_n <= ~clk_n;
//   else
//     clk_n <= clk_n;

// //50%占空比
// assign clk_out5 = clk_p | clk_n;
  
endmodule

全部评论

相关推荐

ResourceUt...:楼主有自己的垃圾箱,公司也有自己的人才库
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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