All content, diagrams, equations, html and css by Benj Carson, Jeff Mrochuk, Imran Waheed & Eric Tan. Please send any questions, suggestions or other feedback to Benj Carson
This app note describes some peculiarities in compiling designs with Quartus II. The version used at the time of writing was 1.1, although 2.0 has been released.
As an example, say you are designing a 4-bit adder using several single bit adders. Your single bit adder file is called
adder_1.vhd
:
-- adder_1.vhd
library ieee;
use ieee.std_logic_1164.all;
entity adder_1 is
port (
a, b, cin : in std_logic;
sum, cout : out std_logic);
end entity adder_1;
architecture demo of adder_1 is
begin -- architecture demo
sum <= (a xor b) xor cin;
cout <= (a and b) or (cin and a) or (cin and b);
end architecture demo;
And your top level file is called adder_4.vhd
:
-- adder_4.vhd
library ieee;
use ieee.std_logic_1164.all;
entity adder_4 is
port (
a, b : in std_logic_vector(3 downto 0);
sum : out std_logic_vector(3 downto 0);
cin : in std_logic;
cout : out std_logic);
end entity adder_4;
architecture demo of adder_4 is
component adder_1
port (
a, b, cin : in std_logic;
sum, cout : out std_logic
);
end component adder_1;
signal carries : std_logic_vector(3 downto 0);
begin -- architecture demo
adder_input_inst : adder_1
port map (
a => a(0),
b => b(0),
cin => cin,
cout => carries(0),
sum => sum(0));
adders_inst: for i in 1 to 3 generate
begin -- generate adders_inst
adder_1_inst : adder_1
port map (
a => a(i),
b => b(i),
cin => carries(i-1),
cout => carries(i),
sum => sum(i));
end generate adders_inst;
end architecture demo;