2020年1月3日 星期五

Clock Dividers Counters and their use in clock dividers

Clock Dividers Counters and their use in clock dividers







module MOD_10(
  clk_in, //輸入的訊號
  cnt_enb,//count enable, 0開始count
  ck_out //除過的訊號輸出
  );

  input clk_in;
  input cnt_enb;
  output ck_out;

  reg ck_out;

  //internal var
  reg [7:0] cnt; //計數暫存器,最多255

  always @(posedge clk_in) //正緣觸發
  begin
    if(!cnt_enb) //還沒開始,歸0
    begin
      cnt <= 0;
      ck_out <= 0;
    end
    else //開始計數
    begin
      if(cnt >= 5) //修改這裡可以決定除頻值
      begin
        cnt <= 0; //重新計算
        ck_out <= ~ck_out; //原本的波形取反向
      end
      else
      begin
        cnt <= cnt+1; //計數
      end
    end
  end
endmodule



// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps    
module Test_bench;

// Inputs
reg clk_in; //輸入的訊號
reg cnt_enb;//count enable, 0開始count

// Outputs
wire ck_out; //除過的訊號輸出

// Instantiate the Unit Under Test (UUT)
//module MOD_10( 
// clk_in, 輸入的訊號 
//cnt_enb,//count enable, 0開始count 
//ck_out //除過的訊號輸出  );

MOD_10 UUT (
  .clk_in(clk_in), //輸入的訊號
  .cnt_enb(cnt_enb),//count enable, 0開始count
  .ck_out(ck_out) //除過的訊號輸出
  );


   initial begin
    $monitor(clk_in,cnt_enb,ck_out);
    // Initialize Inputs
    clk_in <= 1'b1;
cnt_enb<= 1'b1;
    #400 $finish();
   end

    always #10 clk_in=~clk_in;

endmodule

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...