EmbDev.net

Forum: FPGA, VHDL & Verilog VHDL SELECT statement with variable number of cases


von Применко Л. (Company: SFedU) (p_k)


Rate this post
useful
not useful
I want to implement multiplexer in VHDL, with number of inputs as 
parameter like this:
1
ENTITY Multiplexer IS
2
  GENERIC (
3
    CONSTANT WORD_COUNT : INTEGER := 16;
4
  );
5
  PORT (
6
    d  : IN STD_LOGIC_VECTOR (WORD_COUNT-1 DOWNTO 0);
7
    sel: IN STD_LOGIC_VECTOR (7 DOWNTO 0);
8
    q  : OUT STD_LOGIC
9
  );
10
END Multiplexer;

If number of inputs is constant I can simply use select statement like 
this:
1
    with sel select q <=
2
        d(0) when b'00',
3
        d(1) when b'01',
4
        d(4) when b'10',
5
        d(3) when b'11',
6
         '0' when others;

But I can't do the same with variable number of inputs.
It seems to be easy to do something like this:
1
    with sel select q <= 
2
    M:  FOR i IN 0 TO WORD_COUNT-1 GENERATE
3
      d(i) when conv_std_logic_vector(i, sel'LENGTH),
4
        END GENERATE M;
5
            '0' when others;

But it doesn't work. I don't see any troubles why vhdl couldn't do 
something similar.

von PittyJ (Guest)


Rate this post
useful
not useful
Keep it simple.
The first code you will understand, if you look 2 years later on it.

And I thought, that the number of cases have to be defined at 
'synthesize'-time, because hardware has to be generated. How should it 
work with the second code?
But I might be wrong.

von Применко Л. (Company: SFedU) (p_k)


Rate this post
useful
not useful
"And I thought, that the number of cases have to be defined at
         'synthesize'-time"

    Yes. But it will be.

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Применко Леонидович wrote:
1
 with sel select q <=
2
     M:  FOR i IN 0 TO WORD_COUNT-1 GENERATE
This is not a place where a generate loop can be placed, because here 
it is in the very midst of the select statement.

von Iaaq Z. (isaaq_zakkari)


Rate this post
useful
not useful
Hi people,

i am a beginner in the world of vhdl and ModelSim and i need ur help..

i am trying to compile the following code but i doesnt work

(
...

architecture rsff1 of RSFF is


  begin

        process  is

        begin


      Q <= not(set and Q_quer) after 5 ns ;

      Q_quer <= not(reset and Q);

 --end if;
      wait;

end process;


  end architecture delta_delay;)



and i get alwayes the error: Cannot read output "Q_quer".
                   Cannot read output "Q".

is there any setting in the modelsim to make the code work?

I read sth about delta-delay..

von fpgakuechle (Guest)


Rate this post
useful
not useful
Iaaq Zakkari wrote:


> architecture rsff1 of RSFF is
>
>   begin
>
>         process  is
>
>         begin
>
>       Q <= not(set and Q_quer) after 5 ns ;
>
>       Q_quer <= not(reset and Q);
>
>  --end if;
>       wait;
>
> end process;
>
>   end architecture delta_delay;)
>
> and i get alwayes the error: Cannot read output "Q_quer".
>                    Cannot read output "Q".
>
> is there any setting in the modelsim to make the code work?
>
> I read sth about delta-delay..

The cause of the error messages lies in the lines of code hidden in the 
"...". I assume there is a ENTITY with a PORT list in which Q_quer and Q 
are OUTPUTs. You cannot use outputs as source of a assignment. You have 
to use signals for this.

Best regards

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Iaaq Zakkari wrote:
> and i get alwayes the error: Cannot read output "Q_quer".
>                    Cannot read output "Q".
This is a fairly clear message: you cannot read an output signal.How do 
others cope up with this kind of problem?

> is there any setting in the modelsim to make the code work?
You could do it in a quick and very dirty version this way:
1
port (Q      : buffer std_logic;
2
      Q_quer : inout std_logic; ...
Try it and think about my statement "qiuck and very dirty". And then use 
a local signal for those internal calculations...

> I read sth about delta-delay..
Lots of people read lots of things about something. Most of it has 
nothing to do with particular problems. This is also the case with the 
"delata delay" and your specific problem.

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.