mux code

R

Ralf Hildebrandt

rajan said:
I want to ask you if the following code written is correct:

process (in_1, in_2, in_3, in_4, in_5, in_6, in_7, in_8)
begin
if (sel = '1') then
out_1 <= in_1;
out_2 <= in_2;
out_3 <= in_3;
out_4 <= in_4;
else
out_5 <= in_5;
out_6 <= in_6;
out_7 <= in_7;
out_8 <= in_8;
end if;
end process;

"sel" is not in sensitivity list, therefore in simulation nothing will
happen, if no input, but sel changes.

What you have done is modelling 8 Latches (out_1 to out_8). Let me
describe, what I mean with the example out_1: out_1 is driven with in_1,
when sel='1'. If sel='0' nothing will happen to out_1. This means, out_1
holds its old value. This is a "level sensitive register" aka Latch.

The following code describes 4 two-to-one muxes (out_1 to out_4):

process (sel, in_1, in_2, in_3, in_4, in_5, in_6, in_7, in_8)
begin
if (sel = '1') then
out_1 <= in_1;
out_2 <= in_2;
out_3 <= in_3;
out_4 <= in_4;
else
out_1 <= in_5;
out_2 <= in_6;
out_3 <= in_7;
out_4 <= in_8;
end if;
end process;


Ralf
 
R

rajan

Hi,

I want to ask you if the following code written is correct:

process (in_1, in_2, in_3, in_4, in_5, in_6, in_7, in_8)
begin
if (sel = '1') then
out_1 <= in_1;
out_2 <= in_2;
out_3 <= in_3;
out_4 <= in_4;
else
out_5 <= in_5;
out_6 <= in_6;
out_7 <= in_7;
out_8 <= in_8;
end if;
end process;

I would appreciate your help.

Thank you.

rajan
 
R

rajan

Hi Ralf,

Thank you for your great help. Is there a better way to write this so that
it synthesizes well (or synthesizes without latches).
 
A

anupam

Hi Rajan,
Pl add the "sel" in sensitivity list and assign the value to
out_5,....,out_8 at sel = '1' and value to out_1,....,out_4 at sel = '0'
 
R

Ralf Hildebrandt

rajan said:
Thank you for your great help. Is there a better way to write this so that
it synthesizes well (or synthesizes without latches).

Then let us know, what do you really want! Which input signals (plural -
not singular!) should be muxed to which output (singular, not plural)?

(You did not describe any mux so I can only guess, what your intention was.)

In all cases - the solution I've posted, should be a good template to
adopt it to you own requirements:

f'up comp.lang.vhdl

Ralf
 
V

valentin tihomirov

Pl add the "sel" in sensitivity list and assign the value to
out_5,....,out_8 at sel = '1' and value to out_1,....,out_4 at sel = '0'

Is'nt it what he is doing now? It was mentioned that latches will be
incured.
 
K

Klaus Falser

Hi,

I want to ask you if the following code written is correct:

process (in_1, in_2, in_3, in_4, in_5, in_6, in_7, in_8)
begin
if (sel = '1') then
out_1 <= in_1;
out_2 <= in_2;
out_3 <= in_3;
out_4 <= in_4;
else
out_5 <= in_5;
out_6 <= in_6;
out_7 <= in_7;
out_8 <= in_8;
end if;
end process;

I would appreciate your help.

Thank you.

rajan

IMHO the simplest way to write a 2-way multiplexer for switching
between 2 signals is :

MuxedOut <= SignalA when sel= '1' else SignalB;

This is short and there is no need to worry about sensitivity
lists.

The second recommandation for you is to learn to use
vectors.
It is much more readable and less error prone if you
write

out(4 downto 1) <= input(4 downto 1);

instead of writing 4 single assignments.

Best regards
 
V

valentin tihomirov

IMHO the simplest way to write a 2-way multiplexer for switching
between 2 signals is :

MuxedOut <= SignalA when sel= '1' else SignalB;

This is short and there is no need to worry about sensitivity
lists.



Will these internal muxes be supported in VHDLXX

MuxedOut <= A when S1 else (B when S2 else C);


???
 
T

Thomas Stanka

valentin tihomirov said:
Will these internal muxes be supported in VHDLXX

MuxedOut <= A when S1 else (B when S2 else C);

Yes, at least if you remove the brackets.

You have two conccurent muxes with some different behavior. Both could
be used to build simple 2-to-1 Muxes.

1)
WITH Mux_selector SELECT
output<=A WHEN '0',
B WHEN '1';
2)
output<=A WHEN Cond1 ELSE
B WHEN Cond2 ELSE
C;

bye Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top