XILINX ISE14.7 除法器 IP Divider Generator的使用教程
(一)建立IP核除法器divider generator core
1、右擊頂層模組,選擇"New Source"
2、在彈出的視窗選擇"IP(CORE Generator & Architecture Wizard)",在''File name''下面命名IP核的名字。
3、選擇"Math Functions",然後點選"Dividers"下的"Divider Generator"。
4、設定“Divider Generator”。(a)設定"Algorithm Type",一共兩個選項,“Radix2”和“High Radix”,兩者的區別主要是內部計算方法不同,因此有些特徵不一樣,具體可以檢視XILINX的官方文件《LogicCORE IP Divider Generator v3.0》。
(b)設定被除數和商的資料寬度"Dividend and Quotient Width";這隻除數的資料寬度“Divisor Width”。此處分別設定為16。
(c)設定餘數型別"Remainder Type",兩個選項餘數"Remainder"和商的小數"Fractional"。此處選擇"Remainder"。
(d)設定運算物件的資料型別,無符號“Unsigned”和有符號“Signed”。此處選擇Signed。
設定完成之後,點選“Generate”。
(二)例項化除法器IP核
wire rfd; reg [15 : 0] dividend; reg [15 : 0] divisor; wire [15 : 0] quotient; wire [15 : 0] fractional; math_div math_div_inst ( .clk(clk_50M), // input clk .rfd(rfd), // output rfd .dividend(dividend), // input [15 : 0] dividend .divisor(divisor), // input [15 : 0] divisor .quotient(quotient), // output [15 : 0] quotient .fractional(fractional)); // output [15 : 0] fractional /***************************************************************/ reg win_assign_sig; reg [4:0] cnt_latency;//計算除法器的延遲週期 always @ ( posedge clk_50M or negedge rst_n) if ( !rst_n ) cnt_latency <= 5'd0; else if (cnt_latency==5'd18) cnt_latency <= 5'd0; else if(win_assign_sig&&cnt_latency!=5'd18) cnt_latency <= cnt_latency + 1'b1; /***************************************************************/ //被除數和除數賦值 reg [15:0] h_add_sig; reg [15:0] result; always @ ( posedge clk_50M or negedge rst_n ) if (!rst_n) begin dividend <= 0; divisor <= 0; win_assign_sig <= 0; end else if(!win_assign_sig) begin dividend <= dividend+16'd20; divisor <= divisor+16'd10; win_assign_sig <= 1; end else if(cnt_latency==5'd18&&h_add_sig!=16'd100) win_assign_sig <= 0; /***************************************************************/ //延遲18個週期之後,將商取出賦值給result always @ ( posedge clk_50M or negedge rst_n ) if (!rst_n) result <= 0; else if(cnt_latency==5'd18) result <= quotient; /***************************************************************/ //計數,賦值次數 always @ ( posedge clk_50M or negedge rst_n ) if (!rst_n) h_add_sig <= 0; else if(cnt_latency==5'd18) h_add_sig <= h_add_sig + 1;
1、各個引腳含義
2、需要注意的是,除法器是有延時的,並且延時的週期是可以計算的,一般被除數與商的資料寬度越大,延時週期越長。具體計算方法如下圖。
根據上面的描述,可以計算得到,Latency = 16+2 = 18
(三)功能模擬
模擬程式碼如下:
module main_test; // Inputs reg clk; reg rstin_n; // Outputs wire [3:0] dout; // Instantiate the Unit Under Test (UUT) main uut ( .clk(clk), .rstin_n(rstin_n), .dout(dout) ); initial begin // Initialize Inputs clk = 0; rstin_n = 0; // Wait 100 ns for global reset to finish #100; rstin_n = 1; // Add stimulus here end always #10 clk = ~clk; endmodule
模擬結果圖如下:
通過模擬結果可以看到,某個時鐘,被除數dividend為20,除數divisor為10,18個上升沿之後,得到商quotient為2。
參考資料:
XILINX的官方文件《LogicCORE IP Divider Generator v3.0》
連結:https://pan.baidu.com/s/1u-7X4SNEA9B-Ac-1Rsezbw
提取碼:dtc0
轉載請註明出處,謝謝!