Electronic – How to implement a tri-state buffer for a vector in VHDL

buffertri-statevhdl

I want to implement a tri-state buffer for a input vector, triggered by an enable vector, where every bit of the enable vector enables the corresponding bit of the input vector.

Something like this but with multiple enable bits:

A 4 bit tri-state buffer but with a single enable bit.

A single tri-state buffer looks like this:

Y <= A when (EN = '0') else 'Z';

(example from: https://startingelectronics.org/software/VHDL-CPLD-course/tut16-tri-state-buffer/ )

It could look like this (but that one doesn't work…):

[...]
signal Y : std_logic_vector(N downto 0);
signal A : std_logic_vector(N downto 0);
signal EN : std_logic_vector(N downto 0);

Y <= A when EN = (others => '1') else (others => 'Z');

Is there a way to declare this in VHDL or do I have to write a buffer for every bit?

Edit:
To clarify I'm searching a short declaration for this:

Y(0) <= A(0) when EN(0) = '1' else 'Z';
Y(1) <= A(1) when EN(1) = '1' else 'Z';
[...]
Y(N) <= A(N) when EN(N) = '1' else 'Z';

Best Answer

If you need enable control for each bit, then the easiest way is to use a generate statement:

tristate : for i in 0 to N generate
begin
    Y(i) <= A(i) when EN(i) = '1' else 'Z';
end generate tristate;

Generate statements with for constraints create multiple circuits which operate in parallel, unlike a for loop in programming where the same code is executed multiple times in series.

Related Topic