在FPGA設(shè)計(jì)中,復(fù)位電路是非常重要的一部分,它能夠確保系統(tǒng)從初始狀態(tài)開(kāi)始啟動(dòng)并保證正確運(yùn)行。 本文將分別介紹FPGA中三種常用復(fù)位電路:同步復(fù)位、異步復(fù)位和異步復(fù)位同步釋放,以及相應(yīng)的Verilog代碼示例。
異步復(fù)位 or 同步復(fù)位 or 異步復(fù)位同步釋放,真的是“異步復(fù)位同步釋放”更好嗎?
(資料圖片僅供參考)
同步復(fù)位是一種在時(shí)鐘信號(hào)的下降沿或上升沿觸發(fā)的復(fù)位方式,復(fù)位信號(hào)與時(shí)鐘信號(hào)同步。 由于在同步復(fù)位中,復(fù)位信號(hào)和時(shí)鐘信號(hào)是同步的,因此可以確保復(fù)位操作的穩(wěn)定和可預(yù)測(cè)性。 同步復(fù)位通常由一個(gè)或多個(gè)寄存器實(shí)現(xiàn),如下面的實(shí)例:
module sync_reset( input clk, input rstn, input data_in, output reg data_out);always @(posedge clk) begin if(!rstn) begin data_out <= "b0; end else begin data_out <= data_in; endendendmodule
在上述代碼中,rst是同步復(fù)位信號(hào),當(dāng)時(shí)鐘上升沿到來(lái)時(shí),檢測(cè)到復(fù)位信號(hào)為低電平時(shí),計(jì)數(shù)器將被初始化。
綜合后電路圖如下:
從圖中可看出,綜合后,調(diào)用的(D Flip-Flop with Clock Enable and Synchronous Reset帶使能功能的同步清除D觸發(fā)器) FDRE型D觸發(fā)器。
異步復(fù)位是一種在時(shí)鐘信號(hào)之外觸發(fā)的復(fù)位方式,不管時(shí)鐘邊沿信號(hào)有沒(méi)有到來(lái),只要復(fù)位有效信號(hào)到來(lái),即執(zhí)行復(fù)位操作。 以下是異步復(fù)位的基本代碼示例:
module async_reset( input clk, input rstn, input data_in, output reg data_out);always @(posedge clk or negedge rstn) begin if(!rstn) begin data_out <= "b0; end else begin data_out <= data_in; endendendmodule
在異步復(fù)位中,rst信號(hào)不需要和時(shí)鐘信號(hào)同步,并且可以在任何時(shí)候生效。在上述代碼中,rst信號(hào)被用來(lái)異步地清零計(jì)數(shù)器的值,并且不需要等待時(shí)鐘信號(hào)。
綜合后電路如下:
從圖中可看出,綜合后,調(diào)用的(D Flip-Flop with Clock Enable and AsynchronousReset帶使能功能的異步清除D觸發(fā)器) FDCE型D觸發(fā)器。
異步復(fù)位同步釋放通常是這種說(shuō)法,一種結(jié)合了異步與同步復(fù)位優(yōu)點(diǎn)的復(fù)位方式,它使用一個(gè)同步器來(lái)將異步復(fù)位信號(hào)轉(zhuǎn)換為同步的復(fù)位信號(hào),從而確保復(fù)位操作的可控性和穩(wěn)定性。以下是異步復(fù)位同步釋放的基本代碼示例:
module test_reset( input clk, input rstn, input data_in, output reg data_out);reg arstn_r, arstn_s_r;always @(posedge clk or negedge rstn) begin if(!rstn) begin arstn_r <= "b0; arstn_s_r <= "b0; end else begin arstn_r <= "b1; arstn_s_r <= arstn_r; endendalways @(posedge clk or negedge arstn_s_r ) begin if(!arstn_s_r ) begin data_out<= "b0; end else begin data_out<= data_in; endendendmodule
在上述代碼中,rstn是異步復(fù)位信號(hào),在異步復(fù)位條件下,計(jì)數(shù)器會(huì)被清零并重置其他必要的信號(hào)。rstn信號(hào)經(jīng)過(guò)異步和同步兩級(jí)的處理后,生成了一個(gè)同步釋放的復(fù)位信號(hào)arstn_s_r ,它與時(shí)鐘信號(hào)同步并在時(shí)鐘邊緣上生效。然后,同步復(fù)位電路將控制信號(hào)傳遞給其他電路,使其從復(fù)位狀態(tài)轉(zhuǎn)換到正常操作狀態(tài)。
綜合后電路如下:
從圖中可看出,即使復(fù)位信號(hào)通過(guò)兩級(jí)同步處理,也是用的兩個(gè)異步復(fù)位D觸發(fā)器FDCE實(shí)現(xiàn)的,所以實(shí)際上無(wú)需做這種異步復(fù)位同步釋放的處理。
在實(shí)際應(yīng)用中,選擇合適的復(fù)位方式取決于具體的設(shè)計(jì)要求和運(yùn)行環(huán)境,但實(shí)際上我們寫(xiě)verilog代碼常用的是異步復(fù)位的方式,當(dāng)然關(guān)于復(fù)位設(shè)計(jì),真的需要每一個(gè)寄存器都復(fù)位嗎,下一個(gè)文章,我們?cè)賮?lái)嘮嘮。
標(biāo)簽: