功能是,計數記到24,清零,重新計數….
第一種寫法:
module count_debug (
clk,
rst_n,
dout
);
input clk;
input rst_n;
output [4:0] dout;
reg [4:0] cnt;
always @(posedgeclk or negedge rst_n) begin
if(rst_n == 1'b0) begin
cnt <= {5{1'b0}};
end else if(cnt == 5'd24)begin
cnt <= {5{1'b0}};
end else begin
cnt <= cnt + 1'b1;
end
end
assign dout = cnt;
endmodule
這種寫法是我常用的方式,現在來看看消耗的邏輯單元
; Family ; Cyclone II ;
; Device ; EP2C8Q208C8 ;
; TimingModels ; Final ;
; Total logicelements ; 9 / 8,256 ( <1 % ) ? ? ? ? ? ? ? ? ? ? ;
; Total combinational functions ; 9 / 8,256 ( < 1 % ) ? ? ? ? ? ;
; Dedicated logic registers ; 5 / 8,256 ( < 1 % ) ? ? ? ? ? ? ? ;
; Totalregisters ; 5 ;
; Total pins ; 7 / 138 ( 5 % ) ;
; Total virtualpins ; 0 ;
; Total memorybits ; 0 / 165,888 ( 0 %) ;
; EmbeddedMultiplier 9-bit elements ; 0 / 36 ( 0 % ) ;
RTL圖如下:
第二種寫法:
module count_debug (
clk,
rst_n,
dout
);
input clk;
input rst_n;
output [4:0] dout;
reg [4:0] cnt;
always @(posedgeclk or negedge rst_n) begin
if(rst_n == 1'b0) begin
cnt <= {5{1'b0}};
end else if(cnt < 5'd24)begin
cnt <= cnt + 1'b1;
end else begin
cnt <= {5{1'b0}};
end
end
assign dout = cnt;
endmodule
消耗的邏輯單元:
; Family ; Cyclone II ;
; Device ; EP2C8Q208C8 ;
; TimingModels ; Final ;
; Met timingrequirements ; Yes ;
; Total logicelements ; 6 / 8,256 ( <1 % ) ? ? ? ? ? ? ? ? ? ? ?;
; Total combinational functions ; 6 / 8,256 ( < 1 % ) ? ? ? ? ? ?;
; Dedicated logic registers ; 5 / 8,256 ( < 1 % ) ? ? ? ? ? ? ? ?;
; Totalregisters ; 5 ;
; Total pins ; 7 / 138 ( 5 % ) ;
; Total virtualpins ; 0 ;
; Total memorybits ; 0 / 165,888 ( 0 %) ;
; EmbeddedMultiplier 9-bit elements ; 0 / 36 ( 0 % ) ;
RTL圖如下:
第一種寫法比第二種寫法多耗了3個邏輯單元。
從上面的邏輯單元和RTL圖對比,在用計數器實現相同的功能時,可以看出 == COUNT 消耗的邏輯單元比 < ? COUNT ?消耗的邏輯單元要多。
這只是從例子上看出來的,那具體其他情況是不是,就不知道了。目前我在學習中,
以上結論僅供參考。
仿真波形如下:
-
FPGA
+關注
關注
1645文章
22050瀏覽量
618738
發布評論請先 登錄
雷電(雷擊)計數器的原理、作用及行業應用解決方案

?塵埃粒子計數器有什么特點
智能雷擊計數器的綜合行業解決方案

Verilog 測試平臺設計方法 Verilog FPGA開發指南
獲取通信事件計數器與獲取通信事件記錄
雷擊計數器的概述與應用分析

74ls163是幾進制同步計數器
臺式塵埃粒子計數器的優勢有哪些
臺式塵埃粒子計數器的功能優勢與應用
智能防雷計數器行業應用解決方案

評論