FPGA_VerilogHDL 計數器

posedge 和 negedge 間的分界

posedge CLK :由 0→1 的正緣觸發為 CLK==1 時

negedge RST:由 1→0 的負緣觸發為 RST==0 時

程式碼:

module Counter( CLK, RST, Cnt_Num, Cnt_Data );

    parameter Cnt_Num_Size = 2;
    parameter Cnt_Data_Size = 16;

    input   CLK, RST;
    input   [Cnt_Num_Size-1:0] Cnt_Num;
    output reg [Cnt_Data_Size-1:0] Cnt_Data;

    always @( posedge CLK , negedge RST) begin
		  if( !RST )
				Cnt_Data <= 0;
		  else
            Cnt_Data <= Cnt_Data + Cnt_Num;				
    end
	 
endmodule 

模擬波形:

參考資料:數位電路設計