EmbDev.net

Forum: FPGA, VHDL & Verilog 4-Bit Structural Adder using port map


Author: Jay JA (jboss10)
Posted on:

Rate this post
0 useful
not useful
I have this 4-bit adder that I'm having trouble compiling.
 
--This snippet of code was given to us. From here, we needed to create the structural design with the correct port mapping. 
entity adder is
                port       (Ain,Bin,Cin : in std_logic;
                            Sout,Cout : out std_logic);
end entity adder;
 
architecture adder_arch of adder is
     begin
               Sout <= Ain xor Bin xor Cin;
               Cout <= (Bin and Cin) or (Ain and Bin) or (Ain and Cin);
end architecture adder_arch;
--End of given code

--Start of my code
entity FourBit_Adder is 

 port (          a  : in  std_logic_vector (3 downto 0);
    b  : in  std_logic_vector(3 downto 0);
    c_in  : in  std_logic;
    c_out  : out  std_logic;
    sum  : out  std_logic_vector(3 downto 0)
    );
  
end FourBit_Adder;

architecture FourBit_Adder_arch of FourBit_Adder is

 signal S: std_logic_vector(2 downto 0);

 
 component adder is
     port(
       Ain, Bin, Cin: in std_logic;
       Sout, Cout : out std_logic);
  
end component;
  
 
  
begin

FULLA0: adder port map ( Ain => a(0),Bin => b(0),Cin => c_in,Cout => c_in,Sout => sum(0));
FULLA1: adder port map ( Ain => a(1),Bin => b(1),Cin => S(0),Cout => S(1),Sout => sum(1));
FULLA2: adder port map ( Ain => a(2),Bin => b(2),Cin => S(1),Cout => S(2),Sout => sum(2));
FULLA3: adder port map ( Ain => a(3),Bin => b(3),Cin => S(2),Cout => c_out,Sout => sum(3));          
                             
end architecture FourBit_Adder_arch; 

When compiling, I'm getting the error message "std_logic_vector" is used 
but not declared. Not sure what's up. I appreciate your feedback.
I'm using Altera's Quartus II software version 13.1

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Justin JB wrote:
> --This snippet of code was given to us. From here, we needed to create
> the structural design with the correct port mapping.
In both cases something is missing before the keyword "entity". Just 
have a look how every VHDL description starts...

> --End of given code
Also after this line something is missing. Every VHDL module has the 
same structure:
- libraries/packages
- entity
- architecture
All those keywords must occur in a "usual" VHDL module. Just have a 
look for simple samples about components or type the keywords "vhdl 
structural adder" into google. You will find lots of hits...

Author: Jay JA (jboss10)
Posted on:

Rate this post
0 useful
not useful
My mistake, I just forgot to post with the libraries included. I don't 
need the library statement twice in one VHDL code, correct? You said in 
both cases something is missing before entity unless you just were 
referring to it once.

library ieee;
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all;

entity adder is
                port       (Ain,Bin,Cin : in std_logic;
                           Sout,Cout : out std_logic);
end entity adder;
 
architecture adder_arch of adder is
     begin
          Sout <= Ain xor Bin xor Cin;
               Cout <= (Bin and Cin) or (Ain and Bin) or (Ain and Cin);
        
end architecture adder_arch;


entity FourBit_Adder is 

 port (  a    : in  std_logic_vector(3 downto 0);
      b    : in  std_logic_vector(3 downto 0);
      c_in  : in  std_logic;
      c_out  : out  std_logic;
      sum  : out  std_logic_vector(3 downto 0)
    );
  
end FourBit_Adder;

architecture FourBit_Adder_arch of FourBit_Adder is

 signal S: std_logic_vector(2 downto 0);

 
 component adder is
     port(
       Ain, Bin, Cin: in std_logic;
       Sout, Cout : out std_logic);
  
end component;
  
 
  
begin

        FULLA0: adder port map ( Ain => a(0),Bin => b(0),Cin => c_in,Cout => c_in,Sout => sum(0));
        FULLA1: adder port map ( Ain => a(1),Bin => b(1),Cin => S(0),Cout => S(1),Sout => sum(1));
        FULLA2: adder port map ( Ain => a(2),Bin => b(2),Cin => S(1),Cout => S(2),Sout => sum(2));
        FULLA3: adder port map ( Ain => a(3),Bin => b(3),Cin => S(2),Cout => c_out,Sout => sum(3));          
                             
end architecture FourBit_Adder_arch;



Author: Jay JA (jboss10)
Posted on:

Rate this post
0 useful
not useful
@Lothar Miller

I figured it out! Thank you for your help! I did forget to place the 
library in the correct spot and my port mapping was incorrect.
--Revised edition
library ieee;
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all;

entity adder is
                port       (Ain,Bin,Cin : in std_logic;
                           Sout,Cout : out std_logic);
end entity adder;
 
architecture adder_arch of adder is
     begin
          Sout <= Ain xor Bin xor Cin;
               Cout <= (Bin and Cin) or (Ain and Bin) or (Ain and Cin);
        
end architecture adder_arch;

library ieee;
use ieee.std_logic_1164.all; 

entity FourBit_Adder is 

 port (  c_in    : in  std_logic;
      a  : in  std_logic_vector(3 downto 0);
      b  : in  std_logic_vector (3 downto 0);
      c_out  : out  std_logic;
      sum  : out  std_logic_vector(3 downto 0)
    );
  
end FourBit_Adder;

architecture FourBit_Adder_arch of FourBit_Adder is

 
 component adder is
     port(
       Ain, Bin, Cin: in std_logic;
       Sout, Cout : out std_logic);
  
end component;
  
 signal S: std_logic_vector(2 downto 0);
  
begin

        FULLA0: adder port map ( Ain => a(0),Bin => b(0),Cin => c_in,Cout => S(0),Sout => sum(0));
        FULLA1: adder port map ( Ain => a(1),Bin => b(1),Cin => S(0),Cout => S(1),Sout => sum(1));
        FULLA2: adder port map ( Ain => a(2),Bin => b(2),Cin => S(1),Cout => S(2),Sout => sum(2));
        FULLA3: adder port map ( Ain => a(3),Bin => b(3),Cin => S(2),Cout => c_out,Sout => sum(3));          
                             
end architecture FourBit_Adder_arch;



Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Justin JB wrote:
> Thank you for your help!
Welcome!

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.