UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
5,605 Views
Registered: ‎06-28-2008

ERROR——square root of CORDIC 4.0

Jump to solution

Hello,everybody,I have a problem about square root of CORDIC 4.0 ip core。

 

ISE 13.1,ISIM simulator,CORDIC 4.0 ip core。

My configuration is

square root,  

parallel,

pipelining mode:  maximum

data format:  unsigned integer

phase format:  radians

synchronization enable:  no overide

pin selection: ce, rdy, sclr, X_out

round mode : nearest even

register inputs,  register outputs

input width:  29,  output width:  15

layout:  create RPM

no scale compensation

latency:  17

----------------------------------------------------

This is my design file。

module test_sqrt(
input wire [28 : 0] x_in,
input wire clk,  
input wire ce,
input wire sclr,

output wire [14 : 0] x_out,
output wire rdy
);

 

sqrt_2048 my_sqrt_2048 (
 .x_in(x_in), // input [28 : 0] x_in
 .x_out(x_out), // ouput [14 : 0] x_out
 .rdy(rdy), // ouput rdy
 .clk(clk), // input clk
 .ce(ce), // input ce
 .sclr(sclr)); // input sclr

 

endmodule

 

This is my testbench

module t1_sqrt;

 // Inputs
 reg [28:0] x_in;
 reg clk;
 reg ce;
 reg sclr;

 // Outputs
 wire [14:0] x_out;
 wire rdy;

 // Instantiate the Unit Under Test (UUT)
 test_sqrt uut (
  .x_in(x_in),
  .clk(clk),
  .ce(ce),
  .sclr(sclr),
  .x_out(x_out),
  .rdy(rdy)
 );

reg [11:0] cnt;
 initial begin
  // Initialize Inputs
  x_in = 0;
  clk = 0;
  ce = 0;
  sclr = 1;
       cnt = 0;
  // Wait 100 ns for global reset to finish
  #100 ce =1;
           sclr = 0;
  // Add stimulus here

 end
 always #10 clk = !clk;

always @(posedge clk)
if(cnt%18 == 0)
begin
x_in <= x_in + 1;
cnt <= cnt + 1;
end
else
begin
cnt <= cnt + 1;
end


endmodule

----------------------------------------------------------------------

 

I ran behavioral ,post-translate , post place and route simulation,

and got the same result。

 

x_in——  1, 2

x_out——  1

 

x_in——  3, 4, 5, 6, 7

x_out——  2

 

x_in——  8, 9, 10, 11,12

x_out——  3

 

x_in——  13 to 22

x_out——  4

 

For example,  sqrt(7)= 2.6458, the x_out should be 3.

sqrt(21)= 4.5826, the x_out should be 5.

 

Why I got the wrong result ??

Could anyone help me ???

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
6,659 Views
Registered: ‎11-28-2007

Re: ERROR——square root of CORDIC 4.0

Jump to solution

I think this how the "rounding to nearest even" works:

 

For 15-bit output, the core truncates the internal result to 17-bit with 15 integer bits and 2 fractional bits. It then compares the 2 fractional bits to see if it's =0.5 (.10),  <0.5, or >0.5. The comparison result is then used for rounding.

 

For sqrt(7)= 2.6458, the first 17 bits are 000000000000010.10 or 2.5 decimal. It's then rounded down to 2 (nearest even number).

 

For sqrt(21)= 4.5826, , the first 17 bits are 000000000000100.10 or 4.5 decimal. It's then rounded down to 4 (nearest even number).

 

If this rounding mode doesn't work for your application, you can use "unsigned fractional" for "data format", use larger output width than 15 and then do the rounding yourself.

 


@jlqsczw_2007 wrote:

Hello,everybody,I have a problem about square root of CORDIC 4.0 ip core。

 

ISE 13.1,ISIM simulator,CORDIC 4.0 ip core。

My configuration is

square root,  

parallel,

pipelining mode:  maximum

data format:  unsigned integer

phase format:  radians

synchronization enable:  no overide

pin selection: ce, rdy, sclr, X_out

round mode : nearest even

register inputs,  register outputs

input width:  29,  output width:  15

layout:  create RPM

no scale compensation

latency:  17

 

I ran behavioral ,post-translate , post place and route simulation,

and got the same result。

 

x_in——  1, 2

x_out——  1

 

x_in——  3, 4, 5, 6, 7

x_out——  2

 

x_in——  8, 9, 10, 11,12

x_out——  3

 

x_in——  13 to 22

x_out——  4

 

For example,  sqrt(7)= 2.6458, the x_out should be 3.

sqrt(21)= 4.5826, the x_out should be 5.

 

Why I got the wrong result ??

Could anyone help me ???




Cheers,
Jim
3 Replies
Teacher rcingham
Teacher
5,598 Views
Registered: ‎09-09-2010

Re: ERROR——square root of CORDIC 4.0

Jump to solution
Look on the bright side - at least all the simulation results are the same!

But I agree with you - that is some weird rounding...

------------------------------------------
"If it don't work in simulation, it won't work on the board."
0 Kudos
Explorer
Explorer
5,590 Views
Registered: ‎06-28-2008

Re: ERROR——square root of CORDIC 4.0

Jump to solution

Can Anyone Help Me?

0 Kudos
Xilinx Employee
Xilinx Employee
6,660 Views
Registered: ‎11-28-2007

Re: ERROR——square root of CORDIC 4.0

Jump to solution

I think this how the "rounding to nearest even" works:

 

For 15-bit output, the core truncates the internal result to 17-bit with 15 integer bits and 2 fractional bits. It then compares the 2 fractional bits to see if it's =0.5 (.10),  <0.5, or >0.5. The comparison result is then used for rounding.

 

For sqrt(7)= 2.6458, the first 17 bits are 000000000000010.10 or 2.5 decimal. It's then rounded down to 2 (nearest even number).

 

For sqrt(21)= 4.5826, , the first 17 bits are 000000000000100.10 or 4.5 decimal. It's then rounded down to 4 (nearest even number).

 

If this rounding mode doesn't work for your application, you can use "unsigned fractional" for "data format", use larger output width than 15 and then do the rounding yourself.

 


@jlqsczw_2007 wrote:

Hello,everybody,I have a problem about square root of CORDIC 4.0 ip core。

 

ISE 13.1,ISIM simulator,CORDIC 4.0 ip core。

My configuration is

square root,  

parallel,

pipelining mode:  maximum

data format:  unsigned integer

phase format:  radians

synchronization enable:  no overide

pin selection: ce, rdy, sclr, X_out

round mode : nearest even

register inputs,  register outputs

input width:  29,  output width:  15

layout:  create RPM

no scale compensation

latency:  17

 

I ran behavioral ,post-translate , post place and route simulation,

and got the same result。

 

x_in——  1, 2

x_out——  1

 

x_in——  3, 4, 5, 6, 7

x_out——  2

 

x_in——  8, 9, 10, 11,12

x_out——  3

 

x_in——  13 to 22

x_out——  4

 

For example,  sqrt(7)= 2.6458, the x_out should be 3.

sqrt(21)= 4.5826, the x_out should be 5.

 

Why I got the wrong result ??

Could anyone help me ???




Cheers,
Jim