Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: VHDL code

  1. #1
    Join Date
    May 2007
    Posts
    27
    Rep Power
    1

    Default VHDL code

    Hello Guys
    I got this Code

    library ieee;
    use ieee.std_logic_1164.all;

    entity NewLUT is
    port
    (
    clk : in std_logic;
    --encoder_a : in std_logic;
    data_in : in integer range 3185 to 4215 ; --std_logic_vector(12 downto 0);
    data_out : out std_logic_vector (30 downto 0);
    out_ready : out std_logic
    );
    end;
    architecture arc_NewLUT of NewLUT is
    signal temp : std_logic;


    begin
    process
    begin
    if CLK'EVENT and CLK = '1' then
    temp <= '1';
    if temp = '1' then
    case data_in is
    when 3185=> data_out <= ("1010101101110111011101110111100");
    when 3186=> data_out <= ("1010101101101001110100000011011");
    when 3187=> data_out <= ("1010101101011100001010001111011");
    when 3188=> data_out <= ("1010101101001110100000011011010");
    when 3189=> data_out <= ("1010101101000000110110100111010");
    when 3190=> data_out <= ("1010101100110011001100110011001");
    when 3191=> data_out <= ("1010101100100101100010111111001");
    when 3192=> data_out <= ("1010101100010111111001001011001");
    when 3193=> data_out <= ("1010101100001010001111010111000");
    when 3194=> data_out <= ("1010101011111100100101100011000");
    when 3195=> data_out <= ("1010101011101110111011101110111");
    when 3196=> data_out <= ("1010101011100001010001111010111");
    when 3197=> data_out <= ("1010101011010011101000000110110");
    when 3198=> data_out <= ("1010101011000101111110010010110");
    when 3199=> data_out <= ("1010101010111000010100011110110");
    when 3200=> data_out <= ("1010101010101010101010101010101");
    when 3201=> data_out <= ("1010101010011101000000110110101");
    when 3202=> data_out <= ("1010101010001111010111000010100");
    when 3203=> data_out <= ("1010101010000001101101001110100");
    when 3204=> data_out <= ("1010101001110100000011011010011");
    when 3205=> data_out <= ("1010101001100110011001100110011");
    when 3206=> data_out <= ("1010101001011000101111110010011");
    when 3207=> data_out <= ("1010101001001011000101111110010");
    when 3208=> data_out <= ("1010101000111101011100001010010");
    when 3209=> data_out <= ("1010101000101111110010010110001");
    when 3210=> data_out <= ("1010101000100010001000100010001");
    when 3211=> data_out <= ("1010101000010100011110101110000");
    when 3212=> data_out <= ("1010101000000110110100111010000");
    when 3213=> data_out <= ("1010100111111001001011000110000");
    when 3214=> data_out <= ("1010100111101011100001010001111");
    when 3215=> data_out <= ("1010100111011101110111011101111");
    when others => data_out <= ("1111111111111111111111111111111");
    end case;
    else
    data_out <= ("0000000000000000000000000000000");
    end if;
    out_ready <= '1';
    wait for 25 ns; -- ERROR
    out_ready <= '0';

    end if;

    --
    -- Add a flag to be used as a clk to the register
    --
    end process;
    end arc_NewLUT ;



    The Error Msg is : Error (10533): VHDL Wait Statement error at NewLUT.vhd(75): Wait Statement must contain condition clause with UNTIL keyword.
    Why is this error i did not want UNTIL all i need to wait for 25 ns evrey time the code uses the case statement.

  2. #2
    Join Date
    Jun 2007
    Location
    Italy
    Posts
    19
    Rep Power
    1

    Post Re: VHDL code

    I think that wait for x ns in uncorrectly (the time is specified only in the testbench)
    in my opinion, you can bind the time at the clock time with a variable, for example

    if clock'event and clock = 1
    count = count +1;

    if (count = 25)
    out_ready = 1

    ---operation----
    out_ready = 0


    and after that in the testbench you specified the clock time...example 10 ns and so your out_ready change every 25*10 ns...

    I think that this is the only thing that you can do...

    i hope that my suggest is useful...

    Stefania

  3. #3
    Join Date
    May 2007
    Posts
    27
    Rep Power
    1

    Default Re: VHDL code

    But i do not want to wait for 25 clk events, i just want to wait for 25ns (this time to load the number in the case statement to the output) every time i enter the case statement and this for to be sure that i did not enter the case statement twice before i load the preview number

  4. #4
    Join Date
    Mar 2007
    Posts
    56
    Rep Power
    1

    Lightbulb Re: VHDL code

    Things happen concurrently in VHDL when executed. Create a counter based off of an available clock, when it hits x number of clock cycles that adds up to 25ns pull an enable high. Recommend to try and simulate to see if you get the intended result.
    Last edited by Justin Bennett; June 12th, 2007 at 10:43 AM.

  5. #5
    Join Date
    Jun 2007
    Location
    Italy
    Posts
    19
    Rep Power
    1

    Default Re: VHDL code

    for what I know about...
    wait for x ns isn't possible in vhdl...but i think that is strange that you have need exactly 25 ns..if you want to do an hysteresis there are other methods...

    bye
    Stefania

  6. #6
    Join Date
    Mar 2007
    Posts
    2,223
    Rep Power
    1

    Default Re: VHDL code

    This falls into the difference between C code and HDL.



    Starting near the top of the process you have:
    temp <= '1';
    temp is a signal, not a variable(which is good. I advise using signals as much as possible as it is closest to hardware). The only place is gets assigned a value is in this one line. There is no conditional on this, so it will basically power up to 1. (It could power up to 0 and go to 1 on the first clock of the design, but I don't believe that is your intent). Next you have the case statement which looks good(I'm not following what you're doing with the integer range, but assume it is necessary. Note that most HDL does not use integer ranges like this...).
    Finally, at the end is:
    out_ready <= '1';
    wait for 25 ns; -- ERROR
    out_ready <= '0';

    Not that all signal updates in a process occur concurrently, i.e. at the same time. You're telling out_ready to get a '1' and a '0' at the same time. The wait for 25ns is purely a simulation symantic. The FPGA has no internal sense of time. It doesn't know what 25ns, as you're providing the clock and it could be any frequency(timing analysis can probably be looked at later). Most people are suggesting you build a counter(although 25ns) is pretty quick. So if you're clock period is 5ns, which is a relatively fast 5ns period , then you would decode when this has counted to 5 and send an output signal to tell out_ready that it can change. Even if synthesis could infer a counter out of this, there are many things it would miss. Would you want an asynchronous output on the counter? Do you want it to count to 4(20ns) and then send a signal so it can be evaluated on the next clock cycle, at time 25ns. Etc.

    This is where you need to understand the target technology, which is LUTs(combinatorial logic), registers, RAMs and in some parts DSP blocks. Most of your code will target the first two. Think of HDL as a low-level description of logic and registers, and remember that registers all occur concurrently, i.e. they can toggle on every clock cycle unless you explicitly tell them not to. To be honest, in learning an HDL I would get a book that shows schematics with every example. I feel that's the best way to get started and learn how what you write translates into the FPGA. Good HDL designers understand the logic they're targeting and mentally have a good image of what their code will map to. If you write HDL from a more algorithmic standpoint(i.e. I know what I want done, but have no idea how it will get synthesized), you can write some good-looking code that gives horrible results.

  7. #7
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    23
    Rep Power
    1

    Default Re: VHDL code

    Hello,

    wait for "time" is not a synthesizable statement. There is no kind of Hardware wich would support this.
    I agree to the others here: If you need the 25 ns timing you can use a enable signal wich is derived from a clock which runs at 40 Mhz and enable the output for one clock cylce.

    When I look at your code, I've got one questions to you and the community, which is a little bit off topic:
    In the case statement you use large bit vectors in binary coding.
    when 3186=> data_out <= ("1010101101101001110100000011011");
    I would use internally a 32 bit vector and code the output vector in this way


    .
    .
    .
    signal data_internal : std_logic_vector(31 downto 0);
    begin
    process
    begin
    if CLK'EVENT and CLK = '1' then
    .
    .
    .
    case...
    .
    .
    .
    when 3186=> data_internal <= x"55B4E81B"
    .
    .
    .
    end case;
    .
    .
    .
    end process;

    data_out <= data_internal(30 downto 0);

    end arch..;


    I think this version has a better "readabiltiy". What do you think? What do the others in here think about this?

    Regards Christian

  8. #8
    Join Date
    Mar 2007
    Posts
    2,223
    Rep Power
    1

    Default Re: VHDL code

    One last thing about the wait for 'time' function is that it doesn't fit into the FPGA view. In generally, you want everything moving as fast as possible. So you usually want a decode value available on the next clock edge, for every clock edge(I'm ignoring multicycle cases). So expect it to always be there, decoded on the next edge. Time shouldn't play much into your coding at first(there often are higher level time issues, like I need the data through the chip in 1us, and I have a latency of 40 clocks, and the clock is running at 100MHz, so... but that's a much higher analysis and often not necessary.

    Whether to use data_internal versus data_out is purely a preference. I actually like the first case better since I don't like I having too many lines that don't do anything, as it can add clutter. The big benefit of what you're doing is that you can use data_internal elsewhere inside the code, while data_out can only go off chip since it's type OUT. (You could make it type BUFFER, which would solve that problem)

    As for how to write up the decode, that's usually a function of how the decode is being written. Maybe it's a look-up table in a data sheet of another part, where it's written as 1's and 0's. Maybe it's the output of a Perl of C script to do a cosine table(which this clearly is not), which might do binary, but might do ASCII. Maybe it's a Matlab output. But with large/complex decodes, there's usually a 'source' that prescribes the syntax, and with HDL you usually have enough flexibility to do whatever that source outputs.

  9. #9
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    23
    Rep Power
    1

    Default Re: VHDL code

    Hi,
    thanks for your reply.
    OK i agree, this isn't the best example and it depends on your source, but personally i like the "Hex" values. A lot of C-Code in our company uses hex-values so its much easier to read for the C-programmers here. (When you have to exchange "tables" between C and VHDL). But a few months ago I had to review such a handcoded LUT with 32 Bit wide vectors, and it was no fun to find the typos...

    Christian

  10. #10
    Join Date
    May 2007
    Posts
    27
    Rep Power
    1

    Default Re: VHDL code

    Thanks u all this is really helped me, bu now i have the question, how can i make a delay in VHDL ?

Similar Threads

  1. Need A Vhdl Code
    By aapatel374 in forum General Altera Discussion
    Replies: 0
    Last Post: September 10th, 2009, 10:54 PM
  2. code vhdl for pulse code modulation
    By RADOUANE in forum General Altera Discussion
    Replies: 3
    Last Post: June 3rd, 2009, 02:15 AM
  3. VHDL Code
    By amirster in forum General Altera Discussion
    Replies: 2
    Last Post: July 16th, 2007, 07:03 AM
  4. Vhdl code
    By amirster in forum Quartus II and EDA Tools Discussion
    Replies: 6
    Last Post: June 11th, 2007, 11:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •