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 

转载请注明出处,谢谢!

猜你喜欢

转载自blog.csdn.net/weixin_38621214/article/details/84147056