原創 FPGA編譯生成鎖存器原因與解決辦法

2021-08-28 03:51:18 字數 3814 閱讀 3265

在quartus ii中,編譯工程,報出如下警告:

warning (335093): timequest timing analyzer is analyzing 160 combinational loops as latches.
quartus 官方給出的help如下:

cause: the timequest timing analyzer found latches implemented using non-optimal 

resources (look-up tables (luts) with combinational feedback). the timequest analyzer

replaces the combinational loop with

an equivalent latch. the timequest analyzer treats

this logic as

a synchronous endpoint, and will not analyze the path through the node.

action: you must implement these latches with registers using asynchronous load

and

data signals, or remove them from your design. for more information,

run the check_timing tcl command

inthe

timequest

analyzer.

以上翻譯過來就是,

原因:時序分析發現了 鎖存器(使用了非優化的資源:帶有組合邏輯反饋的查詢表)。時序分析用等效的鎖存器替代了這裡的組合邏輯環路。時序分析會把該處當做同步端點,不會分析通過這個節點的路徑時序。

措施:你必須(注意是必須)用非同步載入資料訊號的暫存器實現這些鎖存器,或者索性從設計中刪除他們。。。

組合電路是乙個真值表,一組輸入對應一組輸出,實時跟蹤變化,這樣也就容易有冒險、競爭之類的問題產生毛刺。而鎖存器就是組合電路的一種。

鎖存器特點:電平敏感

always @ (a,b)

c <= a & b;

只要a或者b變化,條件就被觸發,c被賦值a and b

觸發器特點:邊沿敏感

always

@ (posedgeclk)

c<=a &b;

只有當clk上公升沿到來時,c才被賦值a and b

特別地,如果把c <= a & b;換成q <= d;這就是d觸發器的原始模型了(沒有復位訊號的d觸發器)

(非同步)暫存器特點:由觸發器構成,可以儲存n bit資料

以1 bit暫存器為例

always @ (posedge clk or negedge n_rst)

if (!n_rst)

q <= 0;

else

if (load)

q <= d;

當load訊號有效後的下乙個clk上公升沿,將輸出賦值為d。復位訊號到來,直接清零。其餘情況,保持上次的值不變。

(同步)暫存器特點:由鎖存器構成,可以儲存n bit資料

就是說輸入是位址索引,函式是真值表,儲存的資料就是 f(x), 即 真值表(輸入) = 輸出。認為這裡的輸出是與輸入同步的(雖然存在訊號的傳輸延遲)。小標題寫的儲存n bit資料 應該加引號,因為它並不是真正意義儲存。甚至不能稱其為暫存器,n bit暫存器應該是可以寫入,可以讀取。而組合邏輯電路一旦確定。其真值表也將確定,「儲存的資料」也就確定了。

在以下**中,生成n多鎖存器,

module

decode(input

a,input

b,input

c,output

reg[31:0] edata,output

reg[31:0] ecapdata,input

bcap,output

regcapst,input

n_rst,input [31:0] rstval,input

clk);

reg[1

:0] state;

always@(posedge clk or negedge n_rst)

begin

if(!n_rst)

begin

edata <= rstval;

state <= ;

endelse

begin

state <= ;

edata <= ;

*****此處省略一萬*****

end

原因:生成鎖存器的原因是,表面上我是按照觸發器的方式在寫**,實則不然。在非同步復位**段,我的輸出依然由外界輸入決定,因此綜合之後產生了鎖存器。

將**作如下修改,問題解決

module

decode(input

a,input

b,input

c,output

reg[31:0] edata,output

reg[31:0] ecapdata,input

bcap,output

regcapst,input

n_rst,input [31:0] rstval,input

clk);

reg[1

:0] state;

always@(posedge clk or negedge n_rst)

begin

if(!n_rst)

begin

edata <= 32

'd0;

state <= 2'd0;

endelse

begin

state <= ;

edata <= ;

*****此處省略一萬*****

end

問題解決了,但是我還有乙個問題,就是這樣的改動並不是我想要的,我就是要在n_rst為低的時候,執行edata <= rstval;。可以做如下處理:取消negedge n_rst,在語句內把!n_rst當作是另一種使能訊號,即:

module

decode(input

a,input

b,input

c,output

reg[31:0] edata,output

reg[31:0] ecapdata,input

bcap,output

regcapst,input

n_rst,input [31:0] rstval,input

clk);

reg[1

:0] state;

always@(posedge clk)

begin

if(!n_rst)

begin

edata <= rstval;

state <= ;

endelse

begin

state <= ;

edata <= ;

*****此處省略一萬*****

end

問題解決

FPGA 中的latch 鎖存器

到底什麼是鎖存器,它是怎麼產生的,它到底和暫存器有多少區別,它怎麼消除。為什麼說他不好?一,是什麼 鎖存器是一種在非同步時序電路系統中,對輸入訊號電平敏感的單元,用來儲存資訊。乙個鎖存器可以儲存1bit的資訊,通常,鎖存器會多個一起出現,如4位鎖存器,8位鎖存器。鎖存器在資料未鎖存時,輸出端的訊號隨...

FPGA 中的latch 鎖存器

一直都知道fpga中有latch這麼一回事,但是一直都不太清楚到底什麼是鎖存器,它是怎麼產生的,它到底和暫存器有多少區別,它怎麼消除。為什麼說他不好?一,是什麼 鎖存器是一種在非同步時序電路系統中,對輸入訊號電平敏感的單元,用來儲存資訊。乙個鎖存器可以儲存1bit的資訊,通常,鎖存器會多個一起出現,...

FPGA中鎖存器和觸發器

到底什麼是鎖存器,它是怎麼產生的,它到底和暫存器有多少區別,它怎麼消除。為什麼說他不好?鎖存器是一種在非同步時序電路系統中,對輸入訊號電平敏感的單元,用來儲存資訊。乙個鎖存器可以儲存1bit的資訊,通常,鎖存器會多個一起出現,如4位鎖存器,8位鎖存器。鎖存器在資料未鎖存時,輸出端的訊號隨輸入訊號變化...