Structural description of LUT5 component based on LUT4 component - vhdl

Please tell me how to correctly describe the structural component of LUT5 on the basis of the LUT4 component, the problem is precisely in the correct mapping of ports.
Entity LUT5 is
Port(
A,B,C,D,E : in std_logic;
Z : out std_logic;
);
End LUT5;
Architecture Behaviour of LUT5 is
Component LUT4
Port(
A,B,C,D : in std_logic;
Z : out std_logic;
);
End Component;
Begin
??????
End
End Architecture

You can represent a five input lookup table by using two four input lookup tables with a selector choosing between the outputs based on the fifth bit:
library ieee;
use ieee.std_logic_1164.all;
entity lut5 is
generic (
LUTVAL: std_logic_vector (0 to 31)
);
port (
a, b, c, d, e: in std_logic;
z : out std_logic
);
end entity lut5;
architecture behaviour of lut5 is
component mux2 is
port (
a: in std_logic;
b: in std_logic;
s: in std_logic;
y: out std_logic
);
end component;
component lut4 is
generic (
LUTVAL: std_logic_vector (0 to 15)
);
port (
a, b, c, d: in std_logic;
z: out std_logic
);
end component;
signal z0, z1: std_logic;
begin
LUT4_0:
lut4
generic map (
LUTVAL => LUTVAL(0 to 15)
)
port map (
a => a,
b => b,
c => c,
d => d,
z => z0
);
LUT4_1:
lut4
generic map (
LUTVAL => LUTVAL(16 to 31)
)
port map (
a => a,
b => b,
c => c,
d => d,
z => z1
);
MUX_2_1:
mux2
port map (
a => z0,
b => z1,
s => e,
y => z
);
end architecture;
The generics are a method of delivering the lookup table contents from the top level of the design model.
Add it a small testbench:
library ieee;
use ieee.std_logic_1164.all;
entity lut5_tb is
end entity;
architecture foo of lut5_tb is
signal a, b, c, d, e: std_logic := '0';
signal z: std_logic;
constant LUTVAL: std_logic_vector (0 to 31) := x"A2201000";
signal index: natural;
begin
DUT:
entity work.lut5
generic map (
LUTVAL => LUTVAL
)
port map (
a => a,
b => b,
c => c,
d => d,
e => e,
z => z
);
STIMULI:
process
use ieee.numeric_std.all;
begin
for i in LUTVAL'RANGE loop
(e, d, c, b, a) <= to_unsigned(i,5);
index <= i;
wait for 10 ns;
end loop;
wait;
end process;
end architecture;
And we can see that it performs as a five input lookup table:
You can count the bits across the z output over time using the added index signal and find the output reconstructs the 32 bit LUTVAL (x"A2201000").
Here's the missing bits and pieces:
library ieee;
use ieee.std_logic_1164.all;
entity mux2 is
port (
a: in std_logic;
b: in std_logic;
s: in std_logic;
y: out std_logic
);
end entity;
architecture foo of mux2 is
begin
y <= a when s = '0' else
b;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity lut4 is
generic (
LUTVAL: std_logic_vector (0 to 15)
);
port (
a, b, c, d: in std_logic;
z: out std_logic
);
end entity;
architecture foo of lut4 is
constant lut: std_logic_vector := LUTVAL;
use ieee.numeric_std.all;
begin
LOOKUP:
z <= lut(to_integer(unsigned'(d,c,b,a)));
end architecture;

Related

Why am I getting U in the waveform for F1?

I am getting U in the waveform instead of proper output.I don;t understand the reason it is happening in such a way. Can anyone please correct my mistake. Providing the code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity circuit1 is port (
A, B: in std_logic;
F1 : out std_logic);
end circuit1;
architecture structural of circuit1 is
signal A_B, B_A: std_logic;--internal signal declarations for A_B and B_A
component and_1 is port (--Component declaration for and_1
i1, i2: in std_logic;
o1: out std_logic);
end component;
component nor_1 is port (--Component declaration for nor_1
i1, i2: in std_logic;
o1: out std_logic);
end component;
begin
--Component placement and connections (formally called component instantiations)
C1: and_1 port map (i1 => A, i2 => B, o1 => A_B);
C2: and_1 port map (i1 => B, i2 => A, o1 => B_A);
C3: nor_1 port map (i1 => A_B, i2 => B_A, o1 => F1);
end structural;
Here is my Test bench code. I have tried to assign different values to A and B , and want the simulation to give the output accordingly.
library IEEE;
use IEEE.Std_logic_1164.all;
use IEEE.Numeric_Std.all;
entity circuit1_tb is
end;
architecture bench of circuit1_tb is
component circuit1 port (
A, B: in std_logic;
F1 : out std_logic);
end component;
signal A, B: std_logic;
signal F1: std_logic;
begin
uut: circuit1 port map ( A => A,
B => B,
F1 => F1 );
stimulus: process
begin
-- Put initialisation code here
A<='1';
B<='1';
F1<='1';
-- Put test bench stimulus code here
A<='0';
B<='0';
wait for 100 ns;
A<='0';
B<='1';
wait for 100 ns;
A<='1';
B<='0';
wait for 100 ns;
A<='1';
B<='1';
wait for 100 ns;
wait;
end process;
end;
Waveform:
enter image description here

How to choose one of top architectures in VHDL (from one file)?

I've got 3 main architectures for vhdl top in conf_gate.vhd. In each of architecture I want to choose one of two architecture of instantion (depends on value of constant). Can I choose one of architecture by using configure keywords from the same top (conf_gate.vhd)? Example is listed below (configuration statement is at end of file)
Pastebin 3_architecture_vhdl
-- configuration gate
-- File: conf_gate.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity xor_gate is
generic(
DATA_WIDTH : natural := 3
);
port(
a : in std_logic_vector(DATA_WIDTH-1 downto 0);
b : in std_logic_vector(DATA_WIDTH-1 downto 0);
c : out std_logic_vector(DATA_WIDTH-1 downto 0)
);
end xor_gate;
architecture arch of xor_gate is
begin
c <= a xor b;
end arch;
architecture not_arch of xor_gate is
begin
c <= a xnor b;
end not_arch;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity or_gate is
generic(
DATA_WIDTH : natural := 3
);
port(
a : in std_logic_vector(DATA_WIDTH-1 downto 0);
b : in std_logic_vector(DATA_WIDTH-1 downto 0);
c : out std_logic_vector(DATA_WIDTH-1 downto 0)
);
end or_gate;
architecture arch of or_gate is
begin
c <= a or b;
end arch;
architecture not_arch of or_gate is
begin
c <= a nor b;
end not_arch;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity and_gate is
generic(
DATA_WIDTH : natural := 3
);
port(
a : in std_logic_vector(DATA_WIDTH-1 downto 0);
b : in std_logic_vector(DATA_WIDTH-1 downto 0);
c : out std_logic_vector(DATA_WIDTH-1 downto 0)
);
end and_gate;
architecture arch of and_gate is
begin
c <= a and b;
end arch;
architecture not_arch of and_gate is
begin
c <= a nand b;
end not_arch;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity conf_gate is
generic(
DATA_WIDTH : natural := 3
);
port(
a : in std_logic_vector(DATA_WIDTH-1 downto 0);
b : in std_logic_vector(DATA_WIDTH-1 downto 0);
c : out std_logic_vector(DATA_WIDTH-1 downto 0)
);
end conf_gate;
architecture and_gate_arch of conf_gate is
constant negated : boolean := true ;
begin
negated_gate : if negated = true generate
mod_inst : and_gate(not_arch)
generic map (
DATA_WIDTH => DATA_WIDTH
)
port map (
a => a,
b => b,
c => c
);
end generate negated_gate;
gate : if negated = false generate
mod_inst : entity work.and_gate(arch)
generic map (
DATA_WIDTH => DATA_WIDTH
)
port map (
a => a,
b => b,
c => c
);
end generate gate;
end and_gate_arch;
architecture or_gate_arch of conf_gate is
constant negated : boolean := true ;
begin
negated_gate : if negated = true generate
mod_inst : entity work.or_gate(not_arch)
generic map (
DATA_WIDTH => DATA_WIDTH
)
port map (
a => a,
b => b,
c => c
);
end generate negated_gate;
gate : if negated = false generate
mod_inst : entity work.or_gate(arch)
generic map (
DATA_WIDTH => DATA_WIDTH
)
port map (
a => a,
b => b,
c => c
);
end generate gate;
end or_gate_arch;
architecture xor_gate_arch of conf_gate is
constant negated : boolean := true ;
begin
negated_gate : if negated = true generate
mod_inst : entity work.xor_gate(not_arch)
generic map (
DATA_WIDTH => DATA_WIDTH
)
port map (
a => a,
b => b,
c => c
);
end generate negated_gate;
gate : if negated = false generate
mod_inst : entity work.xor_gate(arch)
generic map (
DATA_WIDTH => DATA_WIDTH
)
port map (
a => a,
b => b,
c => c
);
end generate gate;
end xor_gate_arch;
configuration CONF of conf_gate is
for and_gate_arch
for mod_inst : entity work.and_gate
use entity work.conf_gate;
end for;
end for;
end CONF;
Component binding deferred to a configuration declaration:
configuration conf of conf_gate is
for and_gate_arch
for negated_gate
for mod_inst: and_gate
use entity work.and_gate(not_arch);
end for;
end for;
end for;
end configuration conf;
requires component instantiation:
architecture and_gate_arch of conf_gate is
constant negated: boolean := true ;
component and_gate is
generic ( DATA_WIDTH: natural := 3 );
port (
a: in std_logic_vector(DATA_WIDTH - 1 downto 0);
b: in std_logic_vector(DATA_WIDTH - 1 downto 0);
c: out std_logic_vector(DATA_WIDTH - 1 downto 0)
);
end component;
begin
negated_gate:
if negated = true generate
mod_inst:
-- entity work.and_gate (not_arch)
and_gate
generic map ( DATA_WIDTH => DATA_WIDTH )
port map (
a => a,
b => b,
c => c
);
end generate negated_gate;
gate:
if negated = false generate
mod_inst:
entity work.and_gate(arch)
generic map ( DATA_WIDTH => DATA_WIDTH )
port map (
a => a,
b => b,
c => c
);
end generate gate;
end architecture and_gate_arch;
You should be aware configuration declarations are not widely supported by synthesis vendors. It's worth checking your vendor's supported VHDL constructs (e.g. Xilinx Vivado User Guide 901 for synthesis).
The alternative can be providing the configuration specifications in the enclosing declarative region for the component instantiation.
See IEEE Std 1076-2008 3.4 Configuration declarations and 7.3 Configuration specification. It's also useful to understand the difference between an explicit binding indication (7.3.2 Binding indication) and a default binding indication (7.3.3 Default binding indication).

How to instanciate a component for generation multiple component parallel?

I try to generate a multiple componnt by using the generic map , but i dont know if my code VHDL is correct or no ?
here the programm generate 5 parallel component ( comp) for forming bascule
entity bascule is
Port ( X1,X2,X3,X4,X5: in STD_LOGIC;
Y1,Y2, Y3,Y4,Y5 : in STD_LOGIC;
Z1,Z2,Z3,Z4,Z5 : in STD_LOGIC;
S1,S2,S3,S4,S5 : out STD_LOGIC);
end bascule;
architecture Behavioral of bascule is
component comp
Generic( N: integer :=1);
Port ( X : in STD_LOGIC;
Y : in STD_LOGIC;
Z: in STD_LOGIC;
S : out STD_LOGIC);
end component;
begin
m1 : comp generic map (5)
port map ( X1,Y1,Z1, S1);
m2 : comp generic map (5)
port map ( X2,Y2,Z2, S2);
m3 : comp generic map (5)
port map ( X3,Y3,Z3, S3);
m4 : comp generic map (5)
port map ( X4,Y4,Z4, S4);
m5 : comp generic map (5)
port map ( X5,Y5,Z5, S5);
end Behavioral;
i want to know the way to generate any number of component ?
my best regards
i want to know the way to generate any number of component ?
The key is the word "generate"...
you can use a for..generate loop. In order to do this, you need to express your top entity with the same number of vector inputs as the number of components you expect:
entity bascule is
generic ( number_of_comps : positive)
port ( X,Y,Z: in STD_LOGIC_VECTOR(number_of_comps downto 1);
S : out STD_LOGIC_VECTOR(number_of_comps downto 1));
end bascule;
Then in the architecture you can wire up your components like this:
for i in 1 to number_of_comps generate
inst : entity work.comp
generic map (5)
port map ( X(i),Y(i),Z(i), S(i));
end generate;
I think you may still have a confusion, as you have a generic of 5 on your lower level comp, but it sounds to me like that generic should only be in the top entity, to specify how many comps you want (unless you are then doing the same in the comp entity?)
library ieee;
use ieee.std_logic_1164.all;
-- dummy comp this analyzes and elaborates
entity comp is
Generic( N: integer :=1);
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end entity;
architecture behave of comp is
begin
S <= X and Y and Z;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity bascule is
Port (
-- X1,X2,X3,X4,X5: in STD_LOGIC;
-- Y1,Y2, Y3,Y4,Y5: in STD_LOGIC;
-- Z1,Z2,Z3,Z4,Z5: in STD_LOGIC;
-- S1,S2,S3,S4,S5: out STD_LOGIC
-- and yes, you could pass the number of elements in these as a generic:
X: in std_logic_vector (1 to 5);
Y: in std_logic_vector (1 to 5);
Z: in std_logic_vector (1 to 5);
S: out std_logic_vector (1 to 5)
);
end bascule;
architecture Behavioral of bascule is
component comp
Generic( N: integer :=1);
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end component;
begin
M_gen:
-- and use the same generic as above in the generate iteration scheme:
for i in 1 to 5 generate
M:
comp generic map (5)
port map (
X(i), Y(i), Z(i), S(i)
);
end generate;
-- m1 : comp generic map (5)
-- port map ( X1,Y1,Z1, S1);
-- m2 : comp generic map (5)
-- port map ( X2,Y2,Z2, S2);
-- m3 : comp generic map (5)
-- port map ( X3,Y3,Z3, S3);
-- m4 : comp generic map (5)
-- port map ( X4,Y4,Z4, S4);
-- m5 : comp generic map (5)
-- port map ( X5,Y5,Z5, S5);
end Behavioral;
Using a generic to control a generate statement interation instantiating comp
Because you appear confused about how to use generics to control the number of components, I'll demonstrate:
library ieee;
use ieee.std_logic_1164.all;
-- dummy comp
entity comp is
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end entity;
architecture behave of comp is
begin
S <= X and Y and Z;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity bascule is
generic (MSIZE: natural := 1);
Port (
X: in std_logic_vector (1 to MSIZE);
Y: in std_logic_vector (1 to MSIZE);
Z: in std_logic_vector (1 to MSIZE);
S: out std_logic_vector (1 to MSIZE)
);
end bascule;
architecture Behavioral of bascule is
component comp
Port (
X: in STD_LOGIC;
Y: in STD_LOGIC;
Z: in STD_LOGIC;
S: out STD_LOGIC
);
end component;
begin
Mgen:
for i in 1 to MSIZE generate
M:
comp
port map (
X(i), Y(i), Z(i), S(i)
);
end generate;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
entity bascule_tb is
end entity;
architecture foo of bascule_tb is
constant MSIZE: natural :=5;
signal X: std_logic_vector (1 to MSIZE);
signal Y: std_logic_vector (1 to MSIZE);
signal Z: std_logic_vector (1 to MSIZE);
signal S: std_logic_vector (1 to MSIZE);
begin
DUT: entity work.bascule
generic map (MSIZE)
port map (
X => X,
Y => Y,
Z => Z,
S => S
);
end architecture;
We get MSIZE number of comp components based on the generic MSIZE, which is passed the constant MSIZE where bascule is instantiated in the test bench bascule_tb. This analyzes, elaborates and runs (though it doesn't actually do anything).

create two elements connecting to one mux 41 and 21

I have big problem because i dont uderstand properly how make my homework.
Well i have to make something like this:
http://tomaszewicz.zpt.tele.pw.edu.pl/files/u1/zad4.gif
I have code which create b1 but i dont knwo how to create the second and make them connect to b3.
My code is:
library ieee;
use ieee.std_logic_1164.all;
entity test is
generic(
n : integer := 4
);
port(
a, b, c, d : in std_logic_vector(n-1 downto 0);
s : in std_logic_vector(1 downto 0);
y : out std_logic_vector(n-1 downto 0)
);
end test;
-- przypisanie sekwencyjne - case
architecture arch_mux5 of test is
begin
pr_case: process(a,b,c,d,s)
begin
case s is
when "00" => y <= a;
when "01" => y <= b;
when "10" => y <= c;
when others => y <= d;
end case;
end process;
end arch_mux5;
architecture arch_mux6 of test is
begin
pr_if: process(a,b,c,d,s)
begin
y <= (others => '0'); -- latch jesli zakomentujemy, dlaczego?
if s = "00" then
y <= a;
end if;
if s = "01" then
y <= b;
end if;
if s = "10" then
y <= c;
end if;
if s = "11" then
y <= d;
end if;
end process;
end arch_mux6;
configuration cfg of test is
for arch_mux5
end for;
end cfg;
mux5 and mux6 seems to be the same but in different write method.
You have to instantiate those multiplexers, e.g.:
entity top is
generic (
n: integer:=4
);
port (
a, b, c, d, e, f, g, h: in std_logic_vector(n-1 downto 0);
s: in std_logic_vector(2 downto 0);
y: out std_logic_vector(n-1 downto 0)
);
end entity top;
architecture struct of top is
signal t1, t2: std_logic_vector(n-1 downto 0);
component test is
generic(
n : integer := 4
);
port (
a, b, c, d : in std_logic_vector(n-1 downto 0);
s : in std_logic_vector(1 downto 0);
y : out std_logic_vector(n-1 downto 0)
);
end component test;
component mux2 is
generic(
n : integer := 4
);
port (
a, b : in std_logic_vector(n-1 downto 0);
s : in std_logic;
y : out std_logic_vector(n-1 downto 0)
);
end component test;
begin
b1: test
generic_map (
n => n
);
port map (
a => a,
b => b,
c => c,
d => d,
s => s(1 downto 0),
y => t1
);
b2: test
generic_map (
n => n
);
port map (
e => a,
f => b,
g => c,
h => d,
s => s(1 downto 0),
y => t2
);
b3: mux2
generic_map (
n => n
);
port map (
a => t1,
b => t2,
s => s(2),
y => y
);
end architecture struct;
Of course you still have to write the entity+architecture for mux2. I didn't test this code (don't have a VHDL compiler here) but that should at least lead you into the correct direction.
Yes, your teacher provided two different ways of implementing the same mux. This is probably done for educational purposes only. You will need to instantiate this mux for b1 and b2.
As #bmk points out, your still need to provide an implementation for b3 and instantiate the three muxes in one top level.

VHDL gate basics

I'm learning VHDL and I've come to a halt. I'd like to create a simple gate out of smaller gates (a NAND gate here). Here's the code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity ANDGATE2 is
port(
x,y : in STD_LOGIC;
z : out STD_LOGIC
);
end ANDGATE2;
architecture ANDGATE2 of ANDGATE2 is
begin
z <= x AND y;
end ANDGATE2;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity NOTGATE1 is
port(
x : in STD_LOGIC;
z : out STD_LOGIC
);
end NOTGATE1;
architecture NOTGATE1 of NOTGATE1 is
begin
z <= NOT x;
end NOTGATE1;
library ieee;
use ieee.std_logic_1164.all;
entity NANDGATE2 is
port(
x : in STD_LOGIC;
y : in STD_LOGIC;
z : out STD_LOGIC
);
end NANDGATE2;
architecture NANDGATE2 of NANDGATE2 is
signal c, d: std_logic;
component NOTGATE1
port(
n_in : in STD_LOGIC;
n_out : out STD_LOGIC
);
end component;
component ANDGATE2
port(
a_in1, a_in2 : in STD_LOGIC;
a_out : out STD_LOGIC
);
end component;
begin
N0: ANDGATE2
port map(x, y, c);
N1: NOTGATE1
port map(c, d);
z <= d;
end NANDGATE2;
Here's the code from some tutorial I've been using as a template; it compiles with no problems.
library ieee;
use ieee.std_logic_1164.all;
-- definition of a full adder
entity FULLADDER is
port
(
a, b, c: in std_logic;
sum, carry: out std_logic
);
end FULLADDER;
architecture fulladder_behav of FULLADDER is
begin
sum <= (a xor b) xor c ;
carry <= (a and b) or (c and (a xor b));
end fulladder_behav;
-- 4-bit adder
library ieee;
use ieee.std_logic_1164.all;
entity FOURBITADD is
port
(
a, b: in std_logic_vector(3 downto 0);
Cin : in std_logic;
sum: out std_logic_vector (3 downto 0);
Cout, V: out std_logic
);
end FOURBITADD;
architecture fouradder_structure of FOURBITADD is
signal c: std_logic_vector (4 downto 0);
component FULLADDER
port
(
a, b, c: in std_logic;
sum, carry: out std_logic
);
end component;
begin
FA0: FULLADDER
port map (a(0), b(0), Cin, sum(0), c(1));
FA1: FULLADDER
port map (a(1), b(1), C(1), sum(1), c(2));
FA2: FULLADDER
port map (a(2), b(2), C(2), sum(2), c(3));
FA3: FULLADDER
port map (a(3), b(3), C(3), sum(3), c(4));
V <= c(3) xor c(4);
Cout <= c(4);
end fouradder_structure;
My code compiles with no errors, but with two warnings:
# Warning: ELAB1_0026: p2.vhd : (85, 0): There is no default binding for component "andgate2".(Port "a_in1" is not on the entity).
# Warning: ELAB1_0026: p2.vhd : (87, 0): There is no default binding for component "notgate1".(Port "n_in" is not on the entity).
What gives?
You need to use the same port names on your component and entity declarations.
Right now, for example in your NOTGATE1 entity declaration, you have input port x and output port z, but in the NANDGATE2 architecture, you declare the NOTGATE1 component to have ports n_in and n_out.
This won't cause problems during compilation, since compilation looks at a single unit at a time, and won't see the actual entities. In the elaboration phase, your tools will try to match up the entities to components, but this will fail since the ports don't match.
Not 100% sure, but I think the pins in your component declarations need to match up to the ones in your entity blocks:
component NOTGATE1
port(
x : in STD_LOGIC;
z : out STD_LOGIC
);
end component;
component ANDGATE2
port(
x,y : in STD_LOGIC;
z : out STD_LOGIC
);
Always use explicit port bindings in your port maps, like
port map(a_in1 => x,
a_in2 => y,
a_out => c);
It will make your code also more clear. In big projects it is the first rule of thumb.

Resources