반응형

VHDL의 조합 논리 회로 설계 및 동시 코딩

조합 논리 회로는 논리 연산자와 VHDL 문을 사용하여 구현할 수 있습니다. 논리 회로 구현에서 조건식을 사용할 수 있는 경우 VHDL when select가 구현에 사용됩니다. 조합 회로는 동시 코드를 통해 구현됩니다.

 

"when" "select"

VHDL when select는 동시 VHDL 코드에서 사용할 수 있습니다. 이러한 명령문은 순차, , 클록된 프로그램 단위에서 사용되지 않습니다.

 

조합 회로의 구현을 선택할 때 VHDL 문을 사용할 수 있습니다. 이러한 명령문은 논리 회로의 조건부 구현에 사용됩니다. when 문의 구문은 다음과 같습니다.

 

<signal object> <= <statement> when <condition> else

                         <statement> when <condition> else

                                           

                         <statement> when <condition> else

                         <statement>;

 

when select 문은 서로 유사합니다. 구현 구문만 다릅니다. select 문의 구문은 다음과 같습니다.

 

with <condition> select

<signal object> <= <statement> when <condition>,

                         <statement> when <condition>,

                                            

                         <statement> when others;

 

다음 예제는 논리 연산자를 사용하여 부울 함수 f(x, y, z) = x'y' + y'z를 구현합니다.

부울 함수 f(x, y, z) = x'y' + y'z는 다음을 사용하여 구현할 수 있습니다.

f <= (not(x) not(y)) 또는 (not(y) z)와 같은 논리 연산자

부울 함수 f(x, y, z) = x'y' + y'z를 구현하는 VHDL 프로그램은 다음과 같습니다.

 

entity f_function is
port
(

x, y, z: in bit;

f: out bit );
end entity;
architecture
logic_flow of f_function is
begin
  f<=(not(x) and not(y)) or (not(y) and z);
end architecture;

 

다음은 부울함수의 진리표를 보여주고 있습니다.

x y z f (x, y, z)
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 0

 

 

whenwith문을 사용하여 부울함수를 VHDL로 프로그램하면 다음과 같습니다.

 

f <= ‘1’ when(x = ‘0’ and y = ‘0’ and z = ‘0’) else

     ‘1’ when(x = ‘0’ and y = ‘0’ and z = ‘1’) else

‘1’ when(x = ‘1’ and y = ‘0’ and z = ‘1’) else

     ‘0’

 

with(x&y&z) select

f <= ‘1’ when “000”,

     ‘1’ when “001”,

     ‘1’ when “101”,

     ‘0’ when others;

 

아래 함수를 VHDL로 프로그램하면 다음과 같습니다.

entity fx_function is
port
( x: in integer;
     y: out integer range 0 to 4);
end entity;
architecture logic_flow of fx_function is
begin
with
x select
  y <= 2 when 1 | 2,
       4 when 3 to 6,
       0 when others;
end architecture;

 

Generate

VHDLgenerate는 동시 문입니다. 프로그램 세그먼트의 여러 인스턴스를 생성하는 데 사용됩니다. 생성 문에는 무조건 generate과 조건 generate라는 두 가지 다른 형식이 있습니다. 이 양식을 별도로 살펴보겠습니다.

 

무조건 generate

이름에서 알 수 있듯이 무조건 생성에는 조건부 부분이 없습니다. 구문은 다음과 같습니다.

 

Label : for parameter in number  -- range generate

[declarative part

begin]
Statements

end generate[Label] ;

 

Label의 사용은 generate 문에서 필수이며, 단어 begin generate 문에서 선언적 부분을 사용할 수 있는 경우에 사용됩니다.

 

다음은 generate문의 예제입니다.

Label 1 : for indx in 0 to 3 generate

             y(indx) <= x(indx) xor x(indx + 1)

       end generate;

 

위의 generate문을 다음과 같습니다.

y(0) <= x(0) xor x(1);

y(1) <= x(1) xor x(2);

y(2) <= x(2) xor x(3);

y(3) <= x(3) xor x(4);

 

다음 VHDL 문을 사용하여 벡터 x의 내용을 뒤집을 수 있습니다. 여기서 x, y8비트 벡터입니다.

 

entity reverse_vector is
port
( x_vec: in bit_vector(7 downto 0);
     y_rvec: out bit_vector(7 downto 0));
end entity;
architecture logic_flow of reverse_vector is
begin
reverse: for indx in 0 to 7 generate
          y_rvec(indx)<=x_vec(7-indx);
end generate;
end architecture;

 

조건 generate

조건 generate의 구문은 다음과 같습니다.

Label : if condition generate

           [declarative_part

       begin]

           Statement

       end generate[Label];

 

상수 양의 정수를 확인하고 짝수인지 홀수인지 감지하는 VHDL 문을 조건 generate로 작성하면 다음과 같습니다.

 

entity even_odd_detector is
port(
EvenFlag: out bit);
end entity;
architecture logic_flow of even_odd_detector is
constant
number: positive:=10001;   -- 31-bit positive integer
begin
  EvenDetector: if ((number mod 2)=0) generate
    EvenFlag<=1;
  end generate;

OddDetector: if ((number mod 2)=1) generate
EvenFlag<=0;

end generate;

end architecture;

 

반응형

+ Recent posts