반응형

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;

 

반응형
반응형

VHDL 연산자

VHDL에서 제공하는 연산자는 다음과 같은 주요 범주로 분류할 수 있습니다.

• 할당 연산자

• 논리 연산자

• 관계 연산자

• 산술 연산자

• 연결 연산자

 

할당 연산자

연산자 ":="

초기 값 할당에 연산자 ":="를 사용하거나 상수 또는 일반 변수에 값을 할당합니다.

":="는 초기 값 할당을 위한 신호 개체에만 사용됩니다. 다른 경우에는 신호 개체에 사용되지 않습니다.

 

signal my_signal: integer :=10; -– 초기값 할당

my_signal <=30; -- 값 할당

 

variable my_signal: integer :=10; –- 초기값 할당

my_signal := 40; -- 값 할당

 

constant my_number: natural := 214; -– 초기 값 할당

 

Operator "<="

"<=" 연산자를 사용하여 신호 개체에 값을 할당합니다.

 

signal my_signal: bit_vector(3 downto 0):= “10011”; -– 초기값 할당

my_signal<= “11011”; -- 값 할당

 

Operator “=>” and “others” keyword

"=>" 연산자를 사용하여 벡터 요소에 값을 할당합니다. 연산자 "=>"는 일반적으로 할당되지 않은 벡터 요소의 인덱스 값을 나타내는 예약어 others와 함께 사용됩니다.

 

signal x_vec : std_logic_vector(5 downto 1) := (4|3=> ‘1’, others=> ‘0’);
결과는 x_vec=“01100”

x_vec<=(1 to 3=>‘1’, others=>‘0’);
결과는 x_vec=“00111”

 

variable x_vec : std_logic_vector(0 to 10) := (1|3|5=> ‘1’, 2=> ‘Z’, others=>‘0’);
x_vec= “01Z10100000”

x_vec := (1 to 5=>‘0’, others=>‘Z’);
x_vec=“Z00000ZZZZZ”,

 

논리 연산자와 시프트 연산자

논리 연산자는 데이터 유형 bit, std_logic, std_logic_vector, std_ulogic, std_ulogic_vector Boolean에 사용됩니다. 논리 연산자는 구현 조합 논리 회로에 사용됩니다.

 

다음 표는 논리연산자와 시프트연산자를 나타내고 있습니다.

Logical operators and, or, nand, nor, xor, xnor, not
Shift operators sll, srl, sla, sra, rol, ror

 

논리적 시프트 연산자에 대해 간단히 설명하겠습니다.

시프트 연산자

 

SLL: Shift Left Logical

비트는 왼쪽으로 이동하고 새 위치는 0으로 채워집니다.

 

x <=”10101111”

y <= x sll 2

결과 : y <= “10111100”

 

SLA: Shift Left Arithmetic

비트는 왼쪽으로 이동하고 새 위치는 맨 오른쪽 비트의 값으로 채워집니다.

 

x <=”10101111”

y <= x sla 2

결과 : y <= “10111111”

 

SRL: Shift Right Logical

비트는 오른쪽으로 이동하고 새 위치는 0으로 채워집니다.

 

x <=”10101111”

y <= x srl 2

결과 : y <= “00101011”

 

SRA: Shift Right Arithmetic

비트는 오른쪽으로 이동하고 새 위치는 맨 왼쪽 비트 값으로 채워집니다.

 

x <=”10101111”

y <= x sra 2

결과 : y <= “11101011”

 

ROL: Rotate Left

비트는 왼쪽으로 이동하고 오른쪽의 새 위치는 왼쪽 가장자리에서 떨어진 비트로 채워집니다.

 

ROR: Rotate Right

비트는 오른쪽으로 이동하고 왼쪽의 새 위치는 오른쪽 가장자리에서 떨어진 비트로 채워집니다.

 

관계 연산자

관계 연산자는 비교 목적으로 사용됩니다. VHDL 프로그래밍에서 사용할 수 있는 관계 연산자는 다음과 같습니다.

 

산술 연산자

산술 연산자는 정수 또는 숫자 값에 대한 산술 연산을 수행하는 데 사용됩니다. VHDL 프로그래밍에서 사용할 수 있는 산술 연산자는 다음과 같습니다.

 

 

다음 예제는 z = abs(x) + abs(y)를 코딩하였습니다.

 

library ieee;
use ieee.numeric_std.all;
-- Note that "numeric_std" package includes "std_logic_1164" package in its implementation


entity abs_sum_circuit is
port(
x: in signed(7 downto 0);
     y: in signed(7 downto 0);
     z: out signed(8 downto 0) );
end entity;

architecture logic_flow of abs_sum_circuit is
begin
    z<=abs(x)+abs(y);
end architecture;

 

연결 연산자 "&"

연결 연산자는 논리 또는 비트 벡터를 병합하여 더 긴 논리 벡터를 얻는 데 사용됩니다. 연결 연산자는 bit_vector, std_logic_vector, std_ulogic_vector, signed, unsigned, string, integer vector, boolean-vector 데이터 유형을 병합하는 데 사용할 수 있습니다.

 

entity merger_two_vectors is
port
( x_vec: in bit_vector(4 downto 0);
     y_vec: in bit_vector(6 downto 0);
     z_vec: out bit_vector(11 downto 0) );
end entity;

architecture logic_flow of merger_two_vectors is
begin
    z_vec<=x_vec & y_vec;
end architecture;

 

generic

제네릭 키워드는 VHDL 프로그램을 통해 사용할 수 있는 제네릭 매개변수를 선언하는 데 사용됩니다. 이런 식으로 VHDL 프로그램을 다른 응용 프로그램에 적용하는 것이 더 쉬워집니다. 일반 선언은 포트 섹션 이전의 엔터티 부분에서 수행됩니다. 일반 선언의 구문은 다음과 같습니다.

 

generic(parameter name - 1 : data type - 1 := initial value - 1;
parameter name - 2 : data type - 2 := initial value - 2;
. . .
parameter name - N : data type  N := initial value – N);

 

다음은 generic 선언의 사용 예를 보여주고 있습니다.

 

entity example_generic is
generic (
N : natural:=8;
        M: natural:=16 );
port
( x_vec: in bit_vector(N-1 downto 0);
     y_vec: in bit_vector(M-1 downto 0);
     z_vec: out bit );
end entity;

반응형
반응형

아키텍처

VHDL 프로그램의 아키텍처 부분은 전자 회로의 내부 동작을 설명합니다. 전자 회로의 포트에서 수신된 데이터는 아키텍처 부분 내부에서 처리되고 출력 데이터를 얻습니다. 생성된 출력 데이터는 전자 회로의 출력 포트로 전송됩니다.

 

architecture architecture_name of entity_name is
Declarations

begin
Statements

end [architecture] [architecture_name];

 

아키텍처의 마지막 줄은 "end architecture" 또는 "end architecture_name" 또는 "end architecture architecture_name" 또는 "end"일 수 있습니다.

다음 그림은 디지털 회로의 블랙박스 표현하였습니다.

 

 

위의 회로를 구현하기 위한 VHDL 프로그램을 작성하면 다음과 같습니다.

주어진 블랙박스의 엔터티 부분은 다음과 같이 쓸 수 있습니다.

entity example_1_5 is
port
( a, b, c: in bit;
      f1, f2: out bit );
end entity;

 

다음으로 아키텍쳐 부분에서 부울 함수 f1 = ab’+c f2 = abc’ VHDL 구현을 추가합니다.

architecture example_arc of example_1_5 is
begin
    f1<= (a and not (b)) or c;
    f2<= a and b and (not(c));
end example_arc;

 

전체 코딩은 다음과 같습니다.

entity example_1_5 is
port
( a, b, c: in bit;
      f1, f2: out bit );
end entity;

 

architecture example_arc of example_1_5 is
begin
    f1<= (a and not (b)) or c;
    f2<= a and b and (not(c));
end example_arc;

 

아래 디지털 회로를 엔터티와 아키텍쳐를 구현하면 다음과 같습니다.

 

library IEEE;
use IEEE.std_logic_1164.all;
entity
logic_circuit is
port
( x: in std_logic;
     y: in std_logic;
     z: in std_logic;
     f: out std_logic );
end logic_circuit;

 

architecture logic_flow of logic_circuit is
signal
g, h: std_logic;
begin
    g<=x and y;
    h<=not(y) and z;
    f<=g or h;
end logic_flow;

 

데이터 객체

VHDL 프로그래밍에는 값을 보유하는 데이터 개체가 있습니다. 데이터 개체에는 이름과 데이터 유형이 있습니다. 데이터 객체를 사용하기 위한 일반적인 구문은 데이터 객체 이름과 같습니다.

 

data object object name : data type := initial value;

 

여기서 데이터 개체는 신호, 변수 또는 상수일 수 있습니다. 개체 이름은 사용자에게 달려 있습니다. 데이터 유형은 bit, std_logic, integer, unsigned, signed, std_logic_vector, bit_vector 등과 같이 VHDL 프로그래밍에서 사용할 수 있는 모든 데이터 유형일 수 있습니다.

 

signal 객체는 아키텍처의 선언적 부분에서 선언할 수 있습니다. 반면에, 변수 객체는 프로세스, 프로시저, 함수와 같은 순차적인 프로그램 세그먼트 내부에서 선언될 수 있습니다.

상수 개체는 일반적으로 아키텍처, 엔터티, 패키지, 프로세스, 프로시저 및 함수의 선언적 부분에서 선언됩니다. 그러나 패키지 본문, 블록, 생성에서도 선언할 수 있습니다.

 

상수 객체

상수 개체의 값은 프로그램을 통해 변경할 수 없습니다. 구문은 다음과 같습니다

 

constant name : data type := initial value;

 

다음은 상수객체의 선언 예제입니다.

constant my_constant: integer:=32;
constant my_flag: std_logic:=’1’;
constant my_vector : std_logic_vector(3 downto 0):= "1010";

 

signal 객체

신호 객체 선언은 초기 값을 포함하거나 포함하지 않을 수 있습니다. 신호 객체는 일반적으로 아키텍처 및 패키지의 선언적 부분에 사용됩니다.

함수, 프로시저 및 프로세스와 같은 순차적인 프로그램 세그먼트 내에서는 신호 선언이 허용되지 않습니다. 그 구문은 다음과 같습니다

 

signal name : data type := initial value;

 

다음 예제는 signal 객체의 선언을 보여주고 있습니다.

 

signal my_number: integer;
signal my_bit: bit:=’1’;
signal my_vector : std_logic_vector(3 downto 0):= "1010";

 

variable 객체

변수 객체 선언은 초기 값을 포함하거나 포함하지 않을 수 있습니다. 변수 객체는 기능, 절차, 프로세스와 같은 순차적인 프로그램 단위에서 사용됩니다. 그 구문은 다음과 같습니다

 

variable name : data type := initial value;

 

다음 에제는 variable 객체의 선언을 보여주고 있습니다.

 

variable my_number: natural;
variable my_logic: std_logic:=’1’;
variable my_vector : std_logic_vector(3 downto 0):= "1110";

반응형
반응형

std_logic

포트에 사용되는 데이터 유형은 IEEE 패키지에 정의된 std_logic입니다. std_logic_1164.all.

std_logic 데이터 유형의 경우 8가지 가능한 값이 있으며 이 값은 다음과 같이 정리되어 있습니다.

 

‘X’ Unknown
‘0’ Logic 0
‘1’ Logic 1
‘Z’ High Impedance
‘W’ Weak Unknown
‘L’ Weak Low
‘H’ Weak High
‘-’ Don’t Care

 

std_logic_vector

std_logic_vector 데이터 유형은 IEEE.std_logic_1164.all 라이브러리에 정의되어 있습니다. I/O 포트의 데이터 유형이 std_logic_vector이면 I/O 포트에 여러 std_logic 값이 있음을 의미합니다.

 

entity FourBit_Circuit is
port
( inp1: in std_logic_vector(3 downto 0)
     inp2: in std_logic_vector(3 downto 0)
     outp1: out std_logic_vector(4 downto 0)
     outp2: out std_logic_vector(4 downto 0) );
end FourBit_Circuit;

 

std_ulogic

데이터 유형 std_ulogic IEEE.std_logic_1164.all 패키지에 정의되어 있습니다. std_ulogic 데이터 유형의 경우 9가지 가능한 값이 있으며 이러한 값은 다음과 같이 정리되어 있습니다.

 

‘U’ Uninitialized
‘X’ Unknown
‘0’ Logic 0
‘1’ Logic 1
‘Z’ High Impedance
‘W’ Weak Unknown
‘L’ Weak Low
‘H’ Weak High
‘-’ Don’t Care

 

std_ulogic_vector

std_ulogic_vector 데이터 유형은 IEEE.std_logic_1164.all 라이브러리에 정의되어 있습니다. I/O 포트의 데이터 유형이 std_ulogic_vector이면 I/O 포트에 여러 std_ulogic 값이 있음을 의미합니다.

 

bit

비트 데이터 유형은 표준 패키지에 정의되어 있습니다. , VHDL 프로그램의 헤더에 추가 패키지를 포함할 필요가 없습니다.

 

entity FourBit_Circuit is
port
( inp1: in bit_vector(3 downto 0);
     inp2: in bit_vector(3 downto 0);
     outp1: out bit_vector(4 downto 0);
     outp2: out bit_vector(4 downto 0) );
end entity;

 

bit_vector

bit_vector 데이터 유형은 표준 패키지에 정의되어 있습니다. , VHDL 프로그램의 헤더에 추가 패키지를 포함할 필요가 없습니다. I/O 포트의 데이터 유형이 bit_vector이면 I/O 포트에 여러 비트 값이 있음을 의미합니다.

 

integer, natural, positive

integer, natural, positive 데이터 유형은 표준 패키지에 정의되어 있습니다. , VHDL 프로그램의 헤더에 추가 패키지를 포함할 필요가 없습니다. 정수 데이터 유형은 231에서 231 - 1 범위의 정수를 나타내는 데 사용됩니다.

자연 데이터 형식은 0에서 231 - 1 범위의 정수를 나타내는 데 사용됩니다. 반면 데이터 형식 양수는 1에서 231 - 1 범위의 정수를 나타내는 데 사용됩니다.

 

entity FourBit_Circuit is
port
( inp1: in integer range 0 to 15;
     inp2: in integer range 0 to 15;
     outp1: out integer range 0 to 31;
     outp2: out integer range 0 to 31 );
end entity;

 

entity FourBit_Circuit is
port
( inp1: in natural range 0 to 15;
     inp2: in natural range 0 to 15;
     outp1: out natural range 0 to 31;
     outp2: out natural range 0 to 31 );
end entity;

 

unsigned, signed

unsigned signed 데이터 유형은 numeric_std std_logic_arith 패키지에 정의되어 있습니다. 엔티티 선언에서 이러한 데이터 유형을 사용할 수 있으려면 이러한 패키지 중 하나가 VHDL 프로그램의 헤더에 포함되어야 합니다. unsigned 데이터 형식은 음수가 아닌 정수를 나타내는 데 사용되며, signed 데이터 형식은 부호 있는 숫자, 즉 정수를 나타내는 데 사용됩니다.

다수의 비트로 구성된 다수의 포트를 갖는 전자 회로는 다수의 등가 방식으로 표현될 수 있다. 이 개념을 예를 들어 설명하겠습니다.

 

library IEEE;
use IEEE.numeric_std.all;

entity FourBit_Circuit is
port
( inp1: in unsigned(3 downto 0);
     inp2: in unsigned (3 downto 0);
     outp1: out unsigned (4 downto 0);
     outp2: out unsigned (4 downto 0) );
end entity;

 

library IEEE;
use IEEE.numeric_std.all;

entity FourBit_Circuit is
port
( inp1: in signed (3 downto 0);
     inp2: in signed (3 downto 0);
     outp1: out signed (4 downto 0);
     outp2: out signed (4 downto 0) );
end entity;

반응형

'프로그래밍 언어 > VHDL' 카테고리의 다른 글

[VHDL 학습] when문, select문, generate문  (0) 2022.03.30
[VHDL 학습] VHDL 연산자  (0) 2022.03.24
[VHDL 학습] Architecture  (0) 2022.03.23
[VHDL 학습] Entity  (0) 2022.03.21

+ Recent posts