2013-03-06 3 views
0
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 

entity Lab3_Adder1 is 
    Port (cin : in STD_LOGIC; 
      a : in STD_LOGIC_VECTOR (3 downto 0); 
      b : in STD_LOGIC_VECTOR (3 downto 0); 
      s : out STD_LOGIC_VECTOR (3 downto 0); 
      cout : out STD_LOGIC); 
end Lab3_Adder1; 

architecture Behavioral of Lab3_Adder1 is 

    SIGNAL c : STD_LOGIC_VECTOR (4 DOWNTO 0); 

begin 
    c(0) <= cin; 
    s <= a XOR b XOR c (3 DOWNTO 0); 
    c (4 DOWNTO 1) <= (a AND b) OR (a AND c(3 DOWNTO 0)) OR (b AND c(3 DOWNTO 0)); 
    cout <= c(4); 
end Behavioral; 

안녕하세요, 저는이 포럼을 처음 사용합니다. VHDL에서 월리스 트리 곱셈을하고 있습니다. 위의 코드는 전체 가산기의 코드입니다. 주 코드에서 함수/컴포넌트를 어떻게 호출하는지 알고 싶습니다. (C 프로그래밍 에서처럼). 내 전체 코드에서이 전체 가산기를 호출 할 것입니다. (실수가있는 경우 영어로 나옵니다. im french)VHDL 승수

답변

5

VHDL에서 함수를 호출 할 때 C에서와 마찬가지로 상수, 신호 또는 변수를 초기화하거나 프로세스 내의 순차 명령문을 호출합니다. 하지만 지금은 그렇게 중요하지 않습니다.

하지만 구성 요소를 호출하지 마십시오! 그것은 C++에서 객체를 호출하는 것과 같습니다. 이것은 전혀 의미가 없습니다!

VHDL에서는 구성 요소를 인스턴스화하거나 (더 간단하게) 엔티티 만 인스턴스화하고 신호를 사용하여 포트를 상호 연결할 수 있습니다. 이것은 객체를 선언하고 객체 지향 언어로 메시지를 보내는 것과 매우 비슷합니다. 이것은 생성 등 CPU, 메모리 인터페이스, FFT 프로세서

같은 상호 연결 구성 요소가 법인을 감안하기 위해, "구조 VHDL"라고 종종 VHDL 디자인의 최상위 수준에 나타납니다

entity Lab3_Adder1 is 
    Port (cin : in STD_LOGIC; 
      a : in STD_LOGIC_VECTOR (3 downto 0); 
      b : in STD_LOGIC_VECTOR (3 downto 0); 
      s : out STD_LOGIC_VECTOR (3 downto 0); 
      cout : out STD_LOGIC); 
end Lab3_Adder1; 

내가 할 수있는 예를 들어 다음과 같이 8 비트 가산기를 구축 :

entity Adder_8bit is 
    Port (cin : in STD_LOGIC; 
      a : in STD_LOGIC_VECTOR (7 downto 0); 
      b : in STD_LOGIC_VECTOR (7 downto 0); 
      s : out STD_LOGIC_VECTOR (7 downto 0); 
      cout : out STD_LOGIC); 
end Adder_8bit; 

architecture Structural of Adder_8bit is 

signal carry_int : std_logic; -- between lower and upper halves 

begin 
-- We need to create and connect up two adders 

LSB_adder : entity work.Lab3_Adder1 
    Port Map( 
      cin => cin, 
      a => a(3 downto 0), 
      b => b(3 downto 0), 
      s => s(3 downto 0), 
      cout => carry_int 
    ); 
MSB_adder : entity work.Lab3_Adder1 
    Port Map( 
      cin => carry_int, 
      a => a(7 downto 4), 
      b => b(7 downto 4), 
      s => s(7 downto 4), 
      cout => cout 
    ); 

end Structural; 
0

당신은 조합 회로를 대체 어디서나 C 함수와 유사한 주요 VHDL 코드에서 호출 할 수있는 VHDL-기능을 정의 할 수 있습니다.

먼저 함수 정의가있는 패키지를 정의해야합니다.

======= myAdders.vhdl ==============

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.std_logic_unsigned.all; 

package myAdders is 

function Lab3_Adder1(cin : in STD_LOGIC; 
a : in STD_LOGIC_VECTOR (3 downto 0); 
b : in STD_LOGIC_VECTOR (3 downto 0); 
s : out STD_LOGIC_VECTOR (3 downto 0)) return std_logic; 
end Lab3_Adder1; 

end myAdders; 

package body myAdders is 


function Lab3_Adder1 (cin : in STD_LOGIC; 
a : in STD_LOGIC_VECTOR (3 downto 0); 
b : in STD_LOGIC_VECTOR (3 downto 0); 
s : out STD_LOGIC_VECTOR (3 downto 0)) return std_logic is 
variable c: std_logic_vector(4 downto 0); 
begin 

c(0) := cin; 
s := a XOR b XOR c (3 DOWNTO 0); 
c (4 DOWNTO 1) := (a AND b) OR (a AND c(3 DOWNTO 0)) OR (b AND c(3 DOWNTO 0)); 
return c(4); 
end Lab3_Adder1; 


end myAdders; 

======= topLevel.vhdl ===== =========

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.std_logic_unsigned.all; 
use work.myAddres.all; 


entity TopLevel is 
    Port ( 
      cin : in STD_LOGIC; 
      a : in STD_LOGIC_VECTOR (3 downto 0); 
      b : in STD_LOGIC_VECTOR (3 downto 0); 
      c : out STD_LOGIC_VECTOR (3 downto 0) 
      ); 
end TopLevel; 

architecture Structural of TopLevel is 

signal carry : std_logic; 

begin 

carry <= Lab3_Adder1(cin, a, b, c); 

... and so on ... 

end Structural;