0

The answer is clear. Is it a legit programming way in VHDL? For example;

case (i) is
        when 0=>
             process() is begin
                counter:=0;
             end process;
end case;

Thanks in advance for replies.

Edit for Brian Drummond's reply:

I know it can usable selective blocks in cases. But in that blocks, lines are executed in order or simultaneously?

For example;

case (i) is
            when 0=>

                    if reset='1' then

                        giden_data<='0';
                        k:=0;
                        i:=0;
                        s_clk<='0';

                    elsif reset='0' and rising_edge(clk) then

                        giden_data<=CR(k);

                        if k<7 then

                        k:=k+1;

                        elsif k=7 then

                        giden_data<='0';

                        end if;

                        i:=0;

                    end if;
end case;

Is a synchronous process (like used in 'process'es) usable in the case statements or not? ISE gives an error for the code above which says;

Unexpected embedded clock statement in sequential description for signal <giden_data>.

I wonder the error causes from a synchronous code in case statement or something else in the block.

3 Answers3

1

Short answer: no. case ... is is a sequential statement, and must be placed inside a process, not the other way around.

In VHDL-2008, you can put processes inside case ... generate statements, but this may not be what you want. It depends on what you're trying to accomplish.

edit for updated question

You wrote:

case (i) is
  when 0=>
    if reset='1' then
      giden_data<='0';
      k:=0;
      i:=0;
      s_clk<='0';
    elsif reset='0' and rising_edge(clk) then
      giden_data<=CR(k);
      if k<7 then
        k:=k+1;
      elsif k=7 then
        giden_data<='0';
      end if;
      i:=0;
    end if;
end case;

The proper structure for this is:

if reset='1' then
  giden_data<='0';
  k:=0;
  i:=0;
  s_clk<='0';
elsif rising_edge(clk) then
  case (i) is
    when 0=>
      giden_data<=CR(k);
      if k<7 then
        k:=k+1;
      elsif k=7 then
        giden_data<='0';
      end if;
      i:=0;
  end case;
end if;

And that entire block will need to be wrapped in a single process. This may not accomplish what you want, but the structure you're using won't work for various reasons.

Now, with VHDL-2008, you could switch to case ... generate, as I mentioned above, but that will have the consequence of requiring your case evaluation to be static at compile time, so if you're interested in switching your logic at runtime based on a signal value, you will need to expand/modify the above to suit your needs. (see also Brian Drummond's answer)

edit to respond to comment

You wrote:

Ok but i'm asking if i don't use process but use the code which i wrote inside the process in cases, is that lines execute in order or simultaneously?

You cannot use sequential code (case statements, if statements, etc.) outside of a process. Also, synthesized VHDL is not "executed" like software. What happens is that physical logic is inferred from the code, and by nature, they exist and operate simultaneously (physically, not algorithmically). As for how the algorithm effectively operates, it depends on your design.

For what you're trying to accomplish, though, why can't you just use a case statement inside a process?

process
begin
  case i is
    when 0 =>
      -- code that only operates when i = 0
    when 1 =>
      -- code that only operates when i = 1
    ...
  end case;
end process;

In what way does this not accomplish your goal?

fru1tbat
  • 1,605
  • 9
  • 16
  • I want to make run specific blocks when they fit specific conditions. I know processes run simultaneously. I don't want that. I can't find a structure to achieve this. VHDL is becoming my nightmare day by day.. Sometimes it's really hard to see which design method should be used. – Mehmet Salih Cüvelek Oct 25 '14 at 12:32
  • Ok. Process in a case is not legit. What if i don't use process but use program in the process in the case without defining it 'a process', is that legit? Lines in process, processing one by one in order, or the lines are also processing simultaneously? – Mehmet Salih Cüvelek Oct 25 '14 at 12:38
  • 1
    @MehmetSalihCüvelek: As fru1tbat writes, then `case ... is` is a sequential statement, which means that it only can be used **within** a process. – Morten Zilmer Oct 25 '14 at 12:41
  • Ok but i'm asking if i don't use process but use the code which i wrote inside the process in cases, is that lines execute in order or simultaneously? – Mehmet Salih Cüvelek Oct 25 '14 at 13:19
  • "*cannot* use"..."outside of a process" or subprogram (procedure, function). –  Oct 25 '14 at 23:58
1

No. However from your later comment

I want to make run specific blocks when they fit specific conditions.

you might get what you want from a Case statement inside a Process.

Process(clock,reset) is
   variable counter : integer;
begin
   if reset = '1' then
      counter := 0;
   elsif rising_edge(clock) then
      case (i) is
      when 0 =>
         counter := 0;
      when 1 =>
         counter := counter + 1;
      when 2 =>
         counter := counter - 1;
      when others =>
         null;  -- nothing happens to counter
      end case;
   end if;
end process;

In every clock cycle, the current value of i is tested and one of the specific blocks is executed. If that isn't what you are looking for, we'll need a better description.

The code works as if the lines selected by the Case are executed in order, and the process executes all lines in the selected block and completes immediately after the clock edge.

Note that signals and variables behave differently in a process : variables follow the rules you are familiar with if you have written software in a language like C. However signals behave differently, because they are the method for communicating between processes. See this Q&A for more information on how signals and processes work.

Community
  • 1
  • 1
  • I've deleted 'reset = '0' and' but it gives the same error. Is that code seems to a bad description? Overlapping or sth.? – Mehmet Salih Cüvelek Oct 25 '14 at 13:50
  • I hadn't noticed you'd embedded the synch part in one leg of the Case statement. `If reset='1' then ... elsif rising_edge(clk) ... end if` should be OUTERMOST in the process. –  Oct 25 '14 at 13:53
  • Is that mean after making changes that you've pointed out, a synch part can be usable in a case statement? – Mehmet Salih Cüvelek Oct 25 '14 at 13:59
  • 1
    No again, a case statement is usable in a synch part. –  Oct 25 '14 at 14:00
0

VHDL has with concurrent assign, somehow similar to the case as sequential statement, and the may look like:

with i select
  counter <=  0 when 0,
             -1 when others; 
Morten Zilmer
  • 15,586
  • 3
  • 30
  • 49
  • I've heard that, yes. But let's come to my question, i want to 'select' which process must execute. How is it possible by using 'with select' structure? – Mehmet Salih Cüvelek Oct 25 '14 at 12:42
  • Depends on whether `i` is constant or signal; for `i` as constant then the `case ... generate` of VHDL-2008 can be used, and if `i` as signal then either use the `with ... select` or make a `process` with a `case` within. – Morten Zilmer Oct 25 '14 at 12:45