功能是,計(jì)數(shù)記到24,清零,重新計(jì)數(shù)….
第一種寫法:
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
這種寫法是我常用的方式,現(xiàn)在來看看消耗的邏輯單元
; 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個(gè)邏輯單元。
從上面的邏輯單元和RTL圖對比,在用計(jì)數(shù)器實(shí)現(xiàn)相同的功能時(shí),可以看出 == COUNT 消耗的邏輯單元比 < ? COUNT ?消耗的邏輯單元要多。
這只是從例子上看出來的,那具體其他情況是不是,就不知道了。目前我在學(xué)習(xí)中,
以上結(jié)論僅供參考。
仿真波形如下:
-
FPGA
+關(guān)注
關(guān)注
1643文章
21967瀏覽量
614196
發(fā)布評論請先 登錄
?塵埃粒子計(jì)數(shù)器有什么特點(diǎn)
智能雷擊計(jì)數(shù)器的綜合行業(yè)解決方案

Verilog 測試平臺設(shè)計(jì)方法 Verilog FPGA開發(fā)指南
雷擊計(jì)數(shù)器的概述與應(yīng)用分析

74ls163是幾進(jìn)制同步計(jì)數(shù)器
臺式塵埃粒子計(jì)數(shù)器的優(yōu)勢有哪些
臺式塵埃粒子計(jì)數(shù)器的功能優(yōu)勢與應(yīng)用
智能防雷計(jì)數(shù)器行業(yè)應(yīng)用解決方案

評論