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: 
Explorer
Explorer
9,114 Views
Registered: ‎10-01-2007

CORDIC square root gives wrong output

Jump to solution

Hello all.

I have created test projectin EDK. I have generated squere CORDIC root pcore with CoreGen. Options of this pcore: Square Root, Parallel, No Pipelining, Unsigned Fraction, Radians, No Override, RDY, X_Out, CE, ND, Round Pos Inf, Input width 32-bits, Output width 17-bits. This pcore I connected with "Create or Import Peripheral wizard", did FSL bus. In attached file you can see VHDL code. Port map is such:

 

x_in => FSL_S_Data, nd => FSL_S_Exists, x_out => data_from_sqrt, rdy => FSL_M_Write, clk => FSL_Clk, ce => FSL_S_Exists);

 It's correct?

In C application I put variable and try to get result from this core, but result is incorrect or possible I display in false. I need to operate with floating point. In this example I put and get integer number, but if I operate with float numbers, result is allways zero.

Bellow you can see output results and C code:

 

int val = 27, res; //float val2=0.34f, res2; printf("Input value is: %d\n\r", val); putfslx(val, 0, FSL_NONBLOCKING); getfslx(res,1,FSL_NONBLOCKING); printf("Result is: %d\n\r", res);

 

 

 

Input  Output

11      4

23      7

27      7...

  1. Advice me please if vhd file is correct;
  2. Does my c code is correct?
Thank you very much!
 

 

Best Regards,
Vytautas
0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
8,153 Views
Registered: ‎11-28-2007

Re: CORDIC square root gives wrong output

Jump to solution

Does this AR http://www.xilinx.com/support/answers/32072.htm match what you were seeing?

 

Cheers,

Jim


vytautas wrote:

Hello.

I have downloaded your project. Unfortunately, project is created with ISE 11. I’m using 10.1.3, CORDIC version is 4. My version is CORDIC 3. I have used your sqr_tb.vhd file. In attached file you can find some simulation pictures with corresponding test bench files. Signals of data are in hexadecimal format.

2_test.vhd is almost the same as your test bench and 2_diagram.jpeg is corresponding diagram. Please take look at this diagram. Output is changing just 4 times:

IN x0 -> OUT x0

IN x100000 -> OUT x400

IN x80040F -> OUT xB50

IN x4 -> OUT x2

IN x20 -> OUT0 ????

Result by this input (2_test.vhd) is not so bad. But please look at 3_diagram.jpeg and 3_test.vhd. If input value first time is small output is zero always too!

Most interest is 5_diagram.jpeg. This diagram corresponds your send project, but value changes just one time.

Also, I attaché full project (almost the same as your just for version 10).

Please explain what I'm doing wrong?


 

 

Cheers,
Jim
0 Kudos
34 Replies
Explorer
Explorer
9,108 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution
I attache my full design. Please help, because I cannot find right way by searching required info...
Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
9,088 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

You say it goes wrong with floating point numbers,

 

I think that is the clue, I dont' think the cordic understands IEEE floating point numbers.

 

the cordic is expecting unsigned fractional numbers, not floating point numbers.

  you need to stay to fixed pint numbers ( i.e. integers with an imaginary decimal point )

 

Explorer
Explorer
9,082 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Floating point numbers is another questions, most important are integer numbers, because posted result I think is not right.

Maybe sequence of connected port numbers in vhd is not right? ((0 to 15)...(15 downto 0)...)

Thanks!

Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
9,059 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Big endian, little endian is a good question,

 

Would a simulation be possible to give you more visibility ?

 

Explorer
Explorer
9,024 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hi,

thank you for your reply.

to change the range of signals of square root pcore I use this one:

FSL_M_Data <= data_from_sqrt'reverse_range & "000000000000000";

before was:

FSL_M_Data <=  "000000000000000" & data_from_sqrt;

But EDK doesnt understand attribute reverse_range

Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
9,020 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

 

I don't have EDK on this machine, 

 

but

 

I was wondering, your cordic number is  unsigned I assume. ( Sqrt of a negative number not easy ) so should it not be natural not integer ?

 

Your example, if it's VHDL, what is meant by "000000000000000", do you not have to put a 'b' in front to make it binnary. may be I just do it out of habit.

FSL_M_Data <=  B"000000000000000" & data_from_sqrt ;

 

 

what's the simulation say is happening ? is your data coming out of the cordic, this would answer is it the sending the data or receiving it.

  I also assume the cordic is not instantanious, so you are handeling the hand shaking else where.

     sorry, as I say no EDK on this machine so could be way off mark here.

 

0 Kudos
Explorer
Explorer
9,001 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hello.

Thank you for your help! This sqrt pcore should replace mathematical operation in C application (from math.h library), Actually I operate with floating point numbers, so that target would be not integer numbers, but for discovers integer range is enough.

I did some simulations with ISE. Bellow are my results.

 Version 1 (more simple version):

signal data_from_sqrt : std_logic_vector(0 to 16);

begin

your_instance_name : saknis_1 port map ( x_in => FSL_S_Data, nd => FSL_S_Exists, x_out => data_from_sqrt, rdy => FSL_M_Write, clk => FSL_Clk, ce => FSL_S_Exists);

FSL_S_Read <= FSL_S_Exists;

FSL_M_Data <= B"000000000000000" & data_from_sqrt;

FSL_M_Control <= '0';

 if you see here FSL_S_Data input is connected directly to sqrt pcore (x_in). FSL_M_Data allways is zero. But if I send x_in => B"00000000000000000000000000011111", FSL_M_Data gives 6. (sqrt(31)~6  -round POS Inf).

 Version 2:

 

signal dataA : std_logic_vector(31 downto 0);
begin
The_SW_accelerator : process (FSL_Clk) is
begin
for i in FSL_S_Data'reverse_range loop
dataA(i) <= FSL_S_Data(i);
end loop;
end process The_SW_accelerator;
...-- no changes

x_in => dataA,
...--no changes

hereI have added one process to do revers. Result is this:

 FSL_S_Data  FSL_M_Data

       31                 57124

       23                 29108

 Result is very bad. Also, no matter what to use reverse_range or range attribute.

What is incorrect in this code?

Thank you

 

 

Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
8,998 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Sorry don't have EDK, but have you tried an ISE or modelsim simulation of the cordic, to see what it's doing ?

 

0 Kudos
Explorer
Explorer
8,997 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution
Exactly I'm talking about ISE. All simulations was done with ISE. These results is given from ISE.
Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
8,076 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

do you have the waveforms ? what is the timing form writting into the cordic till the answer gets out ?

0 Kudos
Explorer
Explorer
8,074 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

In attache file is wave form.

Delay of processing data is ~ 425 ns

Best Regards,
Vytautas
cordic_wform.JPG
0 Kudos
Scholar drjohnsmith
Scholar
8,069 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

 

my limited knowledge of the FSL bus , and this waveform looks strange.

 

I understand FSL is a single direction  bus.  data goes into it on the master side, out on the slave side.

  also read and write are active high.

 

So looking at your diagram,  you have data on the _s before the _m, your write is active after your read, and the write comes part way through what you indicate is your cycle.

 

Can I make a suggestion, try a simple register or ram on the FSL bus in stead of the cordic, and compare how that simulates. 

 

The FSL spec is here, look at page 5  for the read and write operatinos you would expect to see.

 

http://www.xilinx.com/support/documentation/ip_documentation/fsl_v20.pdf

 

0 Kudos
Explorer
Explorer
8,056 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

 Hmmz, I'm a bit confused now. FSL interface is generated of EDK wizard and looks so:

 

FSL_Clk : in std_logic; FSL_Rst : in std_logic; FSL_S_CLK : out std_logic; FSL_S_READ : out std_logic; FSL_S_DATA : in std_logic_vector(0 to C_INPUT_DWIDTH-1); FSL_S_CONTROL : in std_logic; FSL_S_EXISTS : in std_logic; FSL_M_CLK : out std_logic; FSL_M_WRITE : out std_logic; FSL_M_DATA : out std_logic_vector(0 to C_OUTPUT_DWIDTH-1); FSL_M_CONTROL : out std_logic; FSL_M_FULL : in std_logic

 As you see_M and _S ports are given in different way: some of then are input, some are output, no matter either _M or _S.

To understand more about FSL and MB I have read this link.In this project FSL interface is in attached file.

 

 

 

Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
8,054 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

So, not having EDK or Impluse, I'm at a bit of a loos end,

 

but I see in your vhdl you have two FSL bus's, 

 

p_cpu_proc_output_stream_if and p_cpu_proc_input_stream_if.

 

so the signals to them are ? 

 

I'd expect the p_cpu_proc_output to be the data written to the cordic, and some time later when the cordic is ready, then the p_cpu_proc_input to read the cordic's output data. I can't see that in the diagram you posted.

 

 

I'm just about on the limit of what I can do for you here, I might well be pointing you in the wrong direction, 

 

0 Kudos
Explorer
Explorer
8,027 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hello.

I have read several times fsl datasheet. FSL bus is one direction. One FSL bus has to be conencted to MB master and pcore slave, second FSL bus has to be connected to pcore master and MB slave. Letters _M and _S in definition of signals (in FSL datasheer) means master and slave device. For example FSL_S_Data is output for MB, but is input for pcore. Because need to connect pcore to FSL FSL_S_Data is input for pcore. and the same is with other ports.

Please correct me if I lie... :).

So, my diagram is correct, one question is why do I get input just after reverse of data input (also this input generates not correct result, because it's reversed) otherwise result is zero

Best Regards,
Vytautas
0 Kudos
Explorer
Explorer
8,022 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Also, I cannot believe that FSL bus is so complicate question. Cordic and another pcores are standart products of CoreGen tools, FSL bus is recomended of Xilinx to be use, and now we discuss about signal waveforms. I hoped to achieve fast results and now 1 month try to create wrapper of CORDIC, FFT and multiplier generated with CoreGen. Could somebady maybe send me to email complete simple project this topic about. I need to use correct CORDIC, multiplier of FFT?

Thank you very much

Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
8,007 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

HI

 

please remeber I have no contact with Xilinx, just an understanding employer,

 

the reason I ask for waveforms is they are the actual hardware.

 

Although it's well hidden, you are creating hardware in CoreGen so looking at the hardware is a good sanity check.

 

As for a month to learn, not bad going, where did you start from. 

 

Big suggestion is if you are having this much problem, go on a course for coregen, there are many , including some on the web, which are at  a price you might accept.

 

 

0 Kudos
Explorer
Explorer
7,990 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hello again.

I have simulated alone sqrt CORDIC without any FSL. I don't understand exaclty why, but result in output Cordic get then if value of input achieve  "100000000000000" (input[14]='1') (>16384 in decimal). If input have such or higher value, CORDIC gives correct result. What does it mean??

Best Regards,
Vytautas
simulationsqrt.JPG
0 Kudos
Explorer
Explorer
7,975 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hi.

Looks like CORDIC square root has bug...

How could I send incorect input data if this pcore has just X_IN, ND and RESET. ND I send allways, but pcore just "ignore" X_in less than "100000000000000".

Please help me

Best Regards,
Vytautas
0 Kudos
Scholar drjohnsmith
Scholar
9,308 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

 

Ok, so I looked at cordic in core builder, and cordic is configurable by you ,

 

how have you configured it ?

 

unsigned or signed inputs ? fractional or integer ? what is the pipe line delay specified ?

   and for future interest, what is the maximum clock speed it will work at .

 

I'd like to see the traces in hex, and the clock also.

 

BTW: have you checked the polarity of the enables etc ?

 

 

 

 

0 Kudos
Explorer
Explorer
9,298 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hi.

I use such configuration:

  • Square Root
  • Parallel
  • Pipelining Mode->No Pipelining
  • Data Format -> Unsigned Integer
  • Phase format -> Radians
  • Optional Pin Selection: ACLR, CE, ND, RDY, X_OUT
  • Round Mode: Round Pos Inf
  • Register Inputs/Outputs: Width 32/17

I don't use pipe line, so that no delay is specified.

I work with ML402 board and MicroBlaze is specified to use 100 MHz clock.

Also, attached is diagram

Best Regards,
Vytautas
sqrt_diagram.JPG
0 Kudos
Scholar drjohnsmith
Scholar
9,293 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

 

even with no pipe lining, there is still a latency through the cordic of  2 with the input and output registers.

 

 I don't know about your Aclr, I only have sclr as an option.

 

 I presume the phase format is greyed out for you as well,as obviously sqr does not have phase.

 

I presume A is Xin and B is Xout. 

  but I must admit I'm a bit stumped. 

 

try putting in only one data sample , the number 32 is a good one,  i.e. only newdata high for one clock. I'd expect to see ready high for one clock also, alligned to the data out.

 

0 Kudos
Explorer
Explorer
9,277 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hi.

You are right: A is X_IN, B is X_OUT. I did SCLR like you said you are using.

I attache diagram where you can see that trashold of sensitive of sqrt pcore is >4000 (hexadecimal) (14th bit is 1).

What does it mean? I can give full project

Best Regards,
Vytautas
sqrt_diagram2.JPG
0 Kudos
Scholar drjohnsmith
Scholar
9,254 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

 

OK, now give cordic time to start up.

 

i.e. give it clock etc, with CE active

 

Wait a few clocks, and hit it with a reset.

 

wait a few more clocks and give it your one clocks worth of data. and wait for the ready to come out.

 

 

0 Kudos
Explorer
Explorer
9,224 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hi.

I did some difference in the simulation file. You can see it bellow. But it looks like no matter what  to send and when to send:

Best Regards,
Vytautas
sqrt_diagram3.JPG
0 Kudos
Scholar drjohnsmith
Scholar
9,209 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

well I got a few minutes to myself, and thought I'd put the cordic design to a quick test.

 

 

All numbers in base 10, unsigned decimal

 

I put in 1048576, and I get out 1024, 

I put in 1048575, and I get out 1023

I put in 1048577, and I get out  1024

 

I put in  16928, and I get out 130

 

all as expected. 

 

 

I think you just need to look at what number base you are looking at in the simulation.

 

BTW: How did you paste those wave pictures in ?

 



 

0 Kudos
Explorer
Explorer
9,201 Views
Registered: ‎10-01-2007

Re: CORDIC square root gives wrong output

Jump to solution

Hi.

but please try put small numbers like 4, 32,100..

base of this topic is that cordic doesnt work with small numbers. It gives output values if input (in binary form) is greater than b"10000000000000"

Best Regards,
Vytautas
0 Kudos
Highlighted
Scholar drjohnsmith
Scholar
9,199 Views
Registered: ‎07-09-2009

Re: CORDIC square root gives wrong output

Jump to solution

Hi

 

sorry , yep I did that also

 

I put in decimal 3, I get out decimal 1

I put in decimal 4, I get out decimal2

 

I put in decimal 8, I get out decimal 2

i put in decimal 9, I get out decimal 3

 

I put in decimal 32, I get out decimal 5

 

 

as expected, 

 

 

Could I ask, What format / radiux are you viewing the numbers in on the simulator ?


If you look at your example, you put in I think 4220 hex ( which is 16928 unsigned decinal ) . sqrt of 16928 is 130.1 in decimal, which in hex is 82. You  have 83, which I think is the way you have rounding set ( pos inf ).

 

 

 

 

Message Edited by drjohnsmith on 01-09-2009 09:30 PM
Message Edited by drjohnsmith on 01-09-2009 09:44 PM
Tags (5)
0 Kudos
Xilinx Employee
Xilinx Employee
9,182 Views
Registered: ‎11-28-2007

Re: CORDIC square root gives wrong output

Jump to solution

You need to save your snapshot as a file and then click "Add Attachment" link at the bottom of the message window.

 

Cheers,

Jim

 

 


drjohnsmith wrote:

 

BTW: How did you paste those wave pictures in ?

 



 


 

 

Cheers,
Jim
ScreenHunter_01 Sep. 02 11.27.gif
0 Kudos