+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 23
  1. #1
    Junior Member level 3
    Points: 497, Level: 4

    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...

    •   Alt25th January 2011, 08:24

      advertising

        
       

  2. #2
    Full Member level 5
    Points: 3,271, Level: 13
    Achievements:
    7 years registered
    amitjagtap's Avatar
    Join Date
    Jan 2007
    Posts
    304
    Helped
    42 / 42
    Points
    3,271
    Level
    13

    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



  3. #3
    Super Moderator
    Points: 234,699, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    40,547
    Helped
    12396 / 12396
    Points
    234,699
    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 ROMSIZE-1) OF STD_LOGIC_VECTOR (NNCO-2 DOWNTO 0);
    SIGNAL SINROM: SINTAB;
    
    BEGIN
    
    GENROM:
    FOR idx in 0 TO ROMSIZE-1 GENERATE
    	CONSTANT x: REAL := SIN(real(idx)*MATH_PI/real(ROMSIZE));
    	CONSTANT xn: UNSIGNED (NNCO-2 DOWNTO 0) := CONV_UNSIGNED(INTEGER(x*real(ROMMAX)),NNCO-1);
    BEGIN
    	SINROM(idx) <= STD_LOGIC_VECTOR(xn);	
    END GENERATE;



  4. #4
    Advanced Member level 5
    Points: 34,548, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,332
    Helped
    1845 / 1845
    Points
    34,548
    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.



  5. #5
    Super Moderator
    Points: 234,699, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    40,547
    Helped
    12396 / 12396
    Points
    234,699
    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
    A function is possibly the more flexible way, and doesn't rely on rarely used VHDL constructs that are mostly ignored by text books.

    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.



  6. #6
    Junior Member level 3
    Points: 497, Level: 4

    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)?



  7. #7
    Junior Member level 3
    Points: 497, Level: 4

    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?



  8. #8
    Advanced Member level 5
    Points: 34,548, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,332
    Helped
    1845 / 1845
    Points
    34,548
    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.



  9. #9
    Junior Member level 3
    Points: 497, Level: 4

    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?

    Quote Originally Posted by TrickyDicky View Post
    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.
    is it possible to do in floating point for both input and output?



  10. #10
    Advanced Member level 5
    Points: 34,548, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,332
    Helped
    1845 / 1845
    Points
    34,548
    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.



    •   Alt1st February 2011, 12:06

      advertising

        
       

  11. #11
    Junior Member level 3
    Points: 497, Level: 4

    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?



  12. #12
    Super Moderator
    Points: 234,699, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    40,547
    Helped
    12396 / 12396
    Points
    234,699
    Level
    100

    Re: How to create lookup table for sin(4(pi)x) in VHDL?

    It seems to me, that a 8-Bit 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.



  13. #13
    Advanced Member level 5
    Points: 34,548, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,332
    Helped
    1845 / 1845
    Points
    34,548
    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.



  14. #14
    Junior Member level 3
    Points: 497, Level: 4

    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?



  15. #15
    Advanced Member level 5
    Points: 34,548, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,332
    Helped
    1845 / 1845
    Points
    34,548
    Level
    45

    Re: How to create lookup table for sin(4(pi)x) in VHDL?

    create a look up table.



  16. #16
    Super Moderator
    Points: 234,699, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    40,547
    Helped
    12396 / 12396
    Points
    234,699
    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
    If not utilizing VHDL to calculate it, as previously suggested, use a spread sheet calculator.



  17. #17
    Junior Member level 3
    Points: 497, Level: 4

    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?



  18. #18
    Super Moderator
    Points: 234,699, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    40,547
    Helped
    12396 / 12396
    Points
    234,699
    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.



    •   Alt3rd February 2011, 10:07

      advertising

        
       

  19. #19
    Newbie level 5
    Points: 423, Level: 4

    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



  20. #20
    Junior Member level 3
    Points: 497, Level: 4

    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 8-bit binary number?



--[[ ]]--