+ Post New Thread
Results 1 to 20 of 23

25th January 2011, 08:24 #1
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
How to create lookup table for sin(4(pi)x) in VHDL?
hi,
how to create lookuptable for sin(4(pi)x) and cos(20(pi)x) in VHDL, The x range is 4 :1/32:4... i.e., 256 values..Anyone help me...

25th January 2011, 08:42 #2
Re: How to create lookup table for sin(4(pi)x) in VHDL?
Mostly MATLAB is used in such cases.....you write a simple MATLAB code to get these sin & cos values then in Xilinx (hope you are using xilinx) instantiate LUT or Block RAM to store these values.
"Doubt grows with knowledge."
"The best way to have a good idea is to have a lot of ideas"....Linus Pauling

25th January 2011, 09:10 #3
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 40,388
 Helped
 12337 / 12337
 Points
 233,774
 Level
 100
Re: How to create lookup table for sin(4(pi)x) in VHDL?
One possible way is to calculate the table in VHDL at compile time, as shown in the below example. (It's a 0..pi sine table, not the solution for your problem).
Code:TYPE SINTAB IS ARRAY(0 TO ROMSIZE1) OF STD_LOGIC_VECTOR (NNCO2 DOWNTO 0); SIGNAL SINROM: SINTAB; BEGIN GENROM: FOR idx in 0 TO ROMSIZE1 GENERATE CONSTANT x: REAL := SIN(real(idx)*MATH_PI/real(ROMSIZE)); CONSTANT xn: UNSIGNED (NNCO2 DOWNTO 0) := CONV_UNSIGNED(INTEGER(x*real(ROMMAX)),NNCO1); BEGIN SINROM(idx) <= STD_LOGIC_VECTOR(xn); END GENERATE;

25th January 2011, 09:38 #4
 Join Date
 Jun 2010
 Posts
 6,276
 Helped
 1832 / 1832
 Points
 34,260
 Level
 45
Re: How to create lookup table for sin(4(pi)x) in VHDL?
Why not do similar to FvM's idea, but do the setup inside a function, that way you can assign a constant instead of a signal.
Also, have a look into the fixed point packages so you dont have to keep remembering where the fractional bits are when you store the values in an unsigned.

25th January 2011, 09:38

25th January 2011, 09:55 #5
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 40,388
 Helped
 12337 / 12337
 Points
 233,774
 Level
 100
Re: How to create lookup table for sin(4(pi)x) in VHDL?
but do the setup inside a function, that way you can assign a constant instead of a signal
The difference between a signal and a constant doesn't matter for the actual LUT implementation. My example will usually cause ROM inference, when supported by the respective hardware, and not explicitely prohibited in the compiler settings, and a LUT in logic cells otherwise. The same can be expected for a functions supplying constant values.
You don't necessarily need a full fixed point package, but you should understand how the sine range of 1.0 .. + 1.0 can be represented by integer numbers. It's mostly a question of your overall design, what the table values are used for.

26th January 2011, 12:18 #6
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
hi,
Thanks for all ....
 Post added at 12:18  Previous post was at 12:09 
actually, the equation is f(x) = 21.5 + x sin(4πx) + x cos(20πx). the x range is 4 to +4, find the maximum value of this equation ...The maximum value is 28.25... shall write vhdl code for this equation ...is it posssible to show 28.25 in an output(xilinx)?

28th January 2011, 09:45 #7
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
sorry..How 28.25 represented in binary? what method use?

28th January 2011, 09:45

28th January 2011, 09:50 #8
 Join Date
 Jun 2010
 Posts
 6,276
 Helped
 1832 / 1832
 Points
 34,260
 Level
 45
Re: How to create lookup table for sin(4(pi)x) in VHDL?
You can use whatever representation you want  usually people stick with floating or fixed point. You could use that equation to generate a look up table in VHDL quite easily, but you have to decide if you want fixed point or floating point for the output. The input (X) will have to be fixed point.

1st February 2011, 12:02 #9
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4

1st February 2011, 12:02

1st February 2011, 12:06 #10
 Join Date
 Jun 2010
 Posts
 6,276
 Helped
 1832 / 1832
 Points
 34,260
 Level
 45
Re: How to create lookup table for sin(4(pi)x) in VHDL?
Output yes.
Input  you cannot do full precision (32 bit) floating point as this would require a 4GB look up table. You can reduce exponent and mantissa width to something more sensible to reduce the look up table size (total max 20 bits on large expensive FPGA devices). But generally, no. Its easier to stick with fixed point.

1st February 2011, 12:38 #11
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
In theroetically, for input X= 3.6563 coresponding to output y is 28.25..How is show this output in xilinx and FPGA KIT?
 Post added at 12:38  Previous post was at 12:29 
is it possible in VHDL?

1st February 2011, 14:01 #12
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 40,388
 Helped
 12337 / 12337
 Points
 233,774
 Level
 100
Re: How to create lookup table for sin(4(pi)x) in VHDL?
It seems to me, that a 8Bit fixed point representation is already suggested by the exercise text, e.g. 3.5 for x and 6.2 for y. The objective is apparently to show the principle method, not to achieve high accuracy.

1st February 2011, 15:03 #13
 Join Date
 Jun 2010
 Posts
 6,276
 Helped
 1832 / 1832
 Points
 34,260
 Level
 45
Re: How to create lookup table for sin(4(pi)x) in VHDL?
both values can easily (or very closly) be represented in 8 bit fixed point.

1st February 2011, 16:42 #14
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
ok.. for x is 1 and 1 ..the value of sin(4(pi)x) is '0'...sinn(pi)is '0'.for all value of x ..sin value '0'.. then how proceed?

1st February 2011, 16:51 #15
 Join Date
 Jun 2010
 Posts
 6,276
 Helped
 1832 / 1832
 Points
 34,260
 Level
 45
Re: How to create lookup table for sin(4(pi)x) in VHDL?
create a look up table.

1st February 2011, 17:13 #16
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 40,388
 Helped
 12337 / 12337
 Points
 233,774
 Level
 100
Re: How to create lookup table for sin(4(pi)x) in VHDL?
A fixed point table for sin(4 pi x) with 8 bit fixed point signed values would look like this
Code:xi x sin(4pi x) sin_4pix_i 128 4.000 0 0 127 3.969 0.098 13 ... 112 3.500 1.000 127 (saturated) ... 1 0.031 0.098 13 0 0.000 0.000 0 ... +127 3.969 0.098 13

3rd February 2011, 09:13 #17
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
How did calculate? how did take range?

3rd February 2011, 10:07 #18
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 40,388
 Helped
 12337 / 12337
 Points
 233,774
 Level
 100
Re: How to create lookup table for sin(4(pi)x) in VHDL?
The scaling for x is already suggested in the original post. The y scaling is obvious by the sin() range.

3rd February 2011, 10:07

5th February 2011, 18:55 #19
 Join Date
 Nov 2010
 Posts
 10
 Helped
 2 / 2
 Points
 423
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
Here is how I do it using Python to generate the table, using an initialized Xilinx RAM64X1S to hold the values. It is in Verilog, but converting it to VHDL should be easy.
RAM64X1S as a sine wave ROM

7th February 2011, 12:12 #20
 Join Date
 Oct 2010
 Posts
 26
 Helped
 1 / 1
 Points
 497
 Level
 4
Re: How to create lookup table for sin(4(pi)x) in VHDL?
Thanks..How to convert 3.9688 into 8bit binary number?
+ Post New Thread
Please login