Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

VHDL - CASE related question

Hello,

This is probably a very fundamental question but I'm a little confused as I am new to this.

In VHDL (I'm sure it the same for others too), if I have such a PROCESS:

PROCESS(clk)

if RISING_EDGE(clk)

CASE state IS

WHEN stateA THEN

state <= stateB;

a <= x"0111";

........

WHEN stateB THEN

state <= stateC;

b <= "0101";

....

....

....

END CASE

END IF

In this, if the state=stateA when it the CASE statement was started, will the state signal be changed fom stateA->stateB-> and so on in each CASE statement when the execution flow down through the CASE statement?? If so, how many statements will excute during that clock period? Is there a limit? or only ONE statement will be exceuted in the clock period?

If only one statement will be excuted, within each statement, how many assignment operators can be performed within that CASE statement?? Is there a limitation?

Thank you very much.

P.S: If anybody knows a good text for learning this typ of issues please let me know.

16 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Thank you very mcuh Tricky, mmTsuchi.

    Looks like a have long way to go.

    One thing that I can't understand is,

    A GENERATE block and a PROCESS block, 'how many' instructions can a FPGA perform? It ofcourse depends on the model, but as a programmer, how would you know that a block of code can be executed within a clock cycle? Or is it not like that? Is possible for a block of PROCESS to take several clock cycles to execute completely?

    Thank you.

    --- Quote End ---

    an FPGA has no instructions, only logic gates and registers, so thats not a correct question to ask. You could write a CPU using VHDL and then you could ask your question about your CPU, not the FPGA.

    A clocked Process will ALWAYS complete all code lines in a single clock cycle (assuming the FPGA can meet timing requirements), but thats may not be what you understand.

    for example:

    
    signal a, b : std_logic;
    process(clk)
    begin
      if rising_edge(clk) then
        a <= input
        b <= a;
        output <= b;
      end if;
    end process;
    

    The code inside the process executes on every single clock cycle. The process discribed 3 registers connected. So it would take 3 clock cycles to get the input to the output. This is a 3 stage register pipeline.

    The output would produce a new value every single clock cycle, delayed by 3 clocks.

    I could put a generate block around this process like this:

    
    multi_pipeline_gen : for i in 0 to 3 generate
      --put process from before here
    end generate multi_pipeline_gen;
    

    and you get 4 parallel pipelines. Basically a process describes one bit of hardware, a generate tells you to replicated that hardware n times.

    It sounds like you dont have a great understanding of digital electronics. Forget about VHDL for now and go and read up about digital logic.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    an FPGA has no instructions, only logic gates and registers, so thats not a correct question to ask. You could write a CPU using VHDL and then you could ask your question about your CPU, not the FPGA.

    --- Quote End ---

    Thank you Tricky!

    I get that now. When you compile it will create whatever we want in digital logic. So as long as there are enough of those parts I can do any amount of assignments inside. Thank you very much.

    Yes I do have a long way to go before I really start coding. Thank you for the help Tricky.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I should add that

    you will learn by (good) VHDL examples and tutorials on the web (Altera and others).

    They represent many "basic" VHDL codes that you can understand very well.

    port type in entities :

    only std_logic(_vector) : Yes, conversions are annoying but more re-usable. I think about "design re-use".

    I will study that question : I have wanted to keep a certain rigor in VHDL designing. Thanks for your opinion.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    port type in entities :

    only std_logic(_vector) : Yes, conversions are annoying but more re-usable. I think about "design re-use".

    I will study that question : I have wanted to keep a certain rigor in VHDL designing. Thanks for your opinion.

    --- Quote End ---

    With Quartus (and other tools) supporting other things other than std_logic there is no reason to write what you mean. Doing all the type conversions just kills the whole point of types in VHDL, which are there for code readability. Adding in coversions all over the place makes the code more obscure.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You are right.

    I began writing with other types (you had said) for port. And I finally adopt this method.

    This is less obscure, simpler to "debug"....

    Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Looks like you have received lots of good help on the mechanics of your target HDL code. As far as a book recommendation goes, I found that the designer's guide to vhdl by Ashenden is an excellent book to learn VHDL from. I believe that it is currently in the 3rd edition.