Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > MUX with generate statement

Reply
Thread Tools

MUX with generate statement

 
 
RADNOR RADNOR is offline
Junior Member
Join Date: Jul 2011
Posts: 4
 
      07-20-2011
Hello,

lets say i have some signal select_signal, and that is one-hot type of a signal, so at any time only one of its bits is 1, others are 0.

The number of bits in that signal depends on the GENERIC statement describing the top entity.

Now i want to create a MUX which will use that select_signal as a control signal, and of course which will also depend on the number of bits defined in top level entity.

now what would be the most compact, nice and efficient method to do that with generate statement?

for example its possible to do in VHDL things like that:
Code:
my_signal <= (127 => '1', others=>'0');
as you see there i am assigning bit #127 value 1, others are zeros.

Now in my problem it has to be vice versa, i must inside the generate statement create such a mux which compares specific bit and makes sure that others are zero..

any thoughts?

thank you
 
Reply With Quote
 
 
 
 
flymolo flymolo is offline
Junior Member
Join Date: Jun 2011
Posts: 10
 
      07-20-2011
Hmm,I think the efficiency of one-hot comes from the fact that You don't need to compare if other bits are zero. Assuming the mux input is an array type and array size matches select_signal size (well not exactly size but index range)
Code:
...
mux_out <= (others => '0') -- default
for i in select_signal'range loop
  if select_signal(i) = '1' then
    mux_out <= mux_in(i);
  end if;
end loop;
...
Which is similar to RAM/ROM description, i don't know if there is any penalty using this vs regular case statement (probally there is as it is priority based), however sometimes I am using this style and i never had a problem with it. What you may didn't know is you can declare entity with unconstrained array ports and use signal attributes to extract range, size etc. instead using generic.
On the second thought it might be more convenient to use generic to unify selector length and mux input array length. Also you said you want to check if one bit is '1' and others are '0', but what if they are not?
 

Last edited by flymolo; 07-20-2011 at 02:01 PM..
Reply With Quote
 
 
 
 
RADNOR RADNOR is offline
Junior Member
Join Date: Jul 2011
Posts: 4
 
      07-20-2011
well thanks for advice, but as you yourself noticed its not gona be that efficient because of its nested comparison nature.

well it actually turns out that i do not need to see if others are zero, once i noticed that any bit of the select_signal is 1, then i take appropriate action which corresponds to that bit.

and select_signal must be controlled by top level GENERIC feature.

and the generate statement inside main body of module must instantiate appropriate structure with this functionality.
 
Reply With Quote
 
RADNOR RADNOR is offline
Junior Member
Join Date: Jul 2011
Posts: 4
 
      07-20-2011
Ok here is my solution. It generates N amount of muxes, and each mux has N inputs. Each input and output is 16 bits, so total width of output from all muxes is N * 16 bits.
Code:
array: for index in N-1 downto 0 generate
begin

single_mux: process(select_signal) -- generating single mux
begin
    for j in N-1 downto 0 loop -- and generating its length
        if select_signal(j) = '1' then
        mux_out(j*16+15 downto j*16) <= ...; -- one data
        else
        mux_out(j*16+15 downto j*16) <= ...; -- another data
        end if;

    end loop;
end process;

end generate;
i think its pretty much something like idea you described.

But actually i do not thing there will be a penalty, because they all are parallel structures.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[how to make?] mux 1x1 128 bits + for generate conradojr VHDL 5 04-26-2007 05:58 PM
Recursive function to generate mux output Edward Watts VHDL 6 01-30-2006 12:48 AM
Propagation delay trought a control signal "SEL" of a MUX Oleg VHDL 1 02-18-2004 07:45 PM
Best way to mux addresses salman sheikh VHDL 0 01-30-2004 09:02 PM
Which method is better ? (about mux) Fano VHDL 0 07-30-2003 12:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57