VHDL test bench, configuration unit - vhdl

I have been trying to use a test bench with a configuration unit. I have the following code:
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY AND_2 IS
PORT (
a,b : IN std_logic;
x : OUT std_logic
);
END ENTITY AND_2;
ARCHITECTURE EX_1 OF AND_2 IS
BEGIN
x <= a and b;
END ARCHITECTURE EX_1;
ARCHITECTURE EX_2 OF AND_2 IS
SIGNAL ab : std_logic_vector(1 DOWNTO 0);
BEGIN
ab <= (a & b);
WITH ab SELECT
x <= '1' WHEN "11",
'0' WHEN OTHERS;
END ARCHITECTURE EX_2;
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY TEST_AND_2 IS
END ENTITY TEST_AND_2;
ARCHITECTURE IO OF TEST_AND_2 IS
SIGNAL a, b, x : std_logic;
BEGIN
G1 : ENTITY work.AND_2(EX_1) PORT MAP ( a => a, b => b, x => x);
a <= '0', '1' AFTER 100 NS;
b <= '0', '1' AFTER 200 NS;
END ARCHITECTURE IO;
CONFIGURATION TESTER1 OF TEST_AND_2 IS
FOR IO
FOR G1 : AND_2
USE ENTITY work.AND_2(EX_1);
END FOR;
END FOR;
END CONFIGURATION TESTER1;
When I compile I kindly receive back the following message:
Error (10482): VHDL error at AND_2.vhd(48): object "AND_2" is used but not declared
The book I am reading from is not to clear in the use of test bench or the configuration unit. Can some one point out the mistake. However obvious it may be.
Many Thanks
D

You cannot use configurations in this way if you are using direct instantiation for your entity. Where you have:
G1 : ENTITY work.AND_2(EX_1) PORT MAP ( a => a, b => b, x => x);
This is direct instantiation, which in general saves typing and duplicated code, but will not allow the architecture to be specified by a configuration. To use configurations, in your declarative region (where the signals are defined), declare a component for your AND_2:
COMPONENT AND_2 IS
PORT (
a,b : IN std_logic;
x : OUT std_logic
);
END COMPONENT;
Then instantiate the AND_2 like this:
G1 : AND_2 PORT MAP ( a => a, b => b, x => x);
Your configuration statement is correct, you should be up and running with these two changes.

Related

node instance instantiates undefined entity error

please I need some help with my VHDL code. I am trying to design a Full adder circuit with 2 half adders. I’m using Max Plus II for my design. I have tried compiling but I keep getting errors(node instance instantiates undefined entity). Please I would appreciate any help I can get. Also, I'm very new to VHDL. Kind regards.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity full_adder is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
cin : in STD_LOGIC;
sum : out STD_LOGIC;
cout : out STD_LOGIC);
end full_adder;
architecture Behavioral of full_adder is
component half_adder is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
sum : out STD_LOGIC;
cout : out STD_LOGIC);
end component;
signal s1, s2 : STD_LOGIC;
signal c1, c2 : STD_LOGIC;
begin
HA1: half_adder port map (a => a, b => b, sum => s1, cout => c1);
HA2: half_adder port map (a => s1, b => cin, sum => s2, cout => c2);
sum <= s2;
cout <= c1 OR c2;
end Behavioral;
I expect to design a full adder using 2 half adders and an OR gate. I would also like to view the Wave simulation.
Though you have a component statement which defines the interface of your half_adder block, you will need an equivalent entity statement (usually found in its own file) to actually define its inner workings.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half_adder is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
sum : out STD_LOGIC;
cout : out STD_LOGIC);
end half_adder;
architecture dataflow of half_adder is
begin
cout <= a and b;
sum <= a xor b;
end dataflow;
The component statement tells your compiler to look for a module that matches a specific description; the entity statement actually defines the workings of the module itself.

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

linking an output from on entity to the input of another entity

I am trying to connect the output of an entity to the input of another entity.
Eventually connect a third entity will be connected,but i want to understand the process of connecting two entity's together.
Do I use a port map? If I do, are they added to both architectures of the different entity's to link them?
I know it wont be as simple as below:
link: transmitter port map (output_e1=>input_e2);
I have tried this but an error returns using ModelSim pointing at components declarations!
update:
ENTITY transmitter is
port(
transmission : out STD_LOGIC_VECTOR (31 downto 0)
);
end transmitter;
architecture Behavioral of transmitter is
end Behavioral;
Entity receiver is
PORT(
rxi:in signed (7 downto 0)
end receiver;
architecture Behavioral of receiver is
end Behavioral;
The above code does not include all the instructions and commands. My program works, but i have two entity and wish to link them as they would be in a communications system.
See the following example, a full adder circuit done using two half adders. You can see how the first half adder output is connected as the input of 2nd half adder.
--top module(full adder) entity declaration
entity fulladder is
port (a : in std_logic;
b : in std_logic;
cin : in std_logic;
sum : out std_logic;
carry : out std_logic
);
end fulladder;
--top module architecture declaration.
architecture behavior of fulladder is
--sub-module(half adder) is declared as a component before the keyword "begin".
component halfadder
port(
a : in std_logic;
b : in std_logic;
sum : out std_logic;
carry : out std_logic
);
end component;
--All the signals are declared here,which are not a part of the top module.
--These are temporary signals like 'wire' in Verilog.
signal s1,c1,c2 : std_logic:='0';
begin
--instantiate and do port map for the first half adder.
HA1 : halfadder port map (
a => a,
b => b,
sum => s1,
carry => c1
);
--instantiate and do port map for the second half adder.
HA2 : halfadder port map (
a => s1,
b => cin,
sum => sum,
carry => c2
);
carry <= c1 or c2; --final carry calculation
end;
See this link for explanation.

Q: VHDL Implementation of 2 simple funcitons

I'm looking to implement the functions y = a and b; y = (a or b) and (c or d).
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity task1_tb is
-- Port ( ); end task1_tb;
architecture Behavioral of task1_tb is
--declaring the component component task1
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
y : out STD_LOGIC); end component;
signal y,a,b: std_logic;
signal counter: unsigned(1 downto 0):="00";
begin
uut: task1 port map(a => a, b => b, y => y );
end Behavioral;
How can I assign a (bit 1) and b (bit 2) so it will test ever possible value and make a 20ns delay between each combination? I've been trying to learn VHDL these past two days for a school project and not even sure if what I have is right.
You're looking to use a wait for <duration> in your stimulus process.
process
begin
for i in 0 to 2**2-1 loop --2**(number of input bits)-1
(a, b) <= to_unsigned(i,2);
wait for 20 ns;
end loop;
wait;
end process;
Credit to user1155120 for refinements.

how to connect output signal of one module to input signal of other module

Suppose my VHDL code is like this:
entity x1:
port(a: out std_logic;
....
....
);
architecture behv1 of x1 is
....
end behv1;
entity y1
port(b: in std_logic;
....
....
);
architecture behv1 of y1 is
begin
m1: x1 port map(a=>b);
end behv1;
So, here a is the output signal of entity x1 which is connected directly to input b of other entity y1.
You're kinda going about it in the wrong way.
entity y1 provides the interface of the y1 entity. It specifies that you have an input to the entity, b. This means that you can read the value of b from inside your architecture declaration. You should then implement what you want your y1 module to do inside architecture behav1.
From what I understand though, you want to instantiate an x1 and a y1, then connect them together. To do this, you need to provide an implementation of x1 and y1, and then instantiate both in a separate top-level and connect them together. Something like this:
entity x1:
port(a: out std_logic;
....
....
);
architecture behv1 of x1 is
-- Do something...
end behv1;
entity y1
port(b: in std_logic;
....
....
);
architecture behv1 of y1 is
begin
-- Do something...
end behv1;
entity toplevel
port (
clk : in std_logic;
...
);
architecture toplevel_arch of toplevel is
signal x1_output : std_logic; -- Temp to connect both modules
begin
m_x1: x1 port map(a => x1_output);
m_y1: y1 port map(b => x1_output);
end toplevel_arch;
The following example analyzes, elaborates and simulates.
It illustrates how to connect inputs and outputs hierarchically.
library ieee;
use ieee.std_logic_1164.all;
entity x3 is
port (
x3in: in std_logic;
x3out: out std_logic
);
end entity;
architecture behv3 of x3 is
begin
x3out <= x3in;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity y3 is
port (
y3in: in std_logic;
y3out: out std_logic
);
end entity;
architecture behv3 of y3 is
begin
y3out <= y3in;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
entity z3 is
port (
z3in: in std_logic;
z3out: out std_logic
);
end entity;
architecture foo of z3 is
component x3 is
port (
x3in: in std_logic;
x3out: out std_logic
);
end component;
component y3 is
port (
y3in: in std_logic;
y3out: out std_logic
);
end component;
signal x3out: std_logic;
begin
u0:
x3
port map (
x3in => z3in,
x3out => x3out
);
u1:
y3
port map (
y3in => x3out,
y3out => z3out
);
end architecture;
The applicable rules can be found in the Language Reference Manual (LRM), IEEE Std 1076-2008 6.5.6.3 Port clauses:
After a given description is completely elaborated (see Clause 14), if a formal port is associated with an actual that is itself a port, then the following restrictions apply depending upon the mode (see 6.5.2), if any, of the formal port:
a) For a formal port of mode in, the associated actual shall be a port of mode in, out, inout, or buffer. This restriction applies both to an actual that is associated as a name in the actual part of an association element and to an actual that is associated as part of an expression in the actual part of an association element.
b) For a formal port of mode out, the associated actual shall be a port of mode out, inout, or buffer.
c) For a formal port of mode inout, the associated actual shall be a port of mode out, inout, or buffer.
d) For a formal port of mode buffer, the associated actual shall be a port of mode out, inout, or buffer.
e) For a formal port of mode linkage, the associated actual may be a port of any mode.

Resources