--
-- VHDL을 이용한 FPGA 디지털 설계
-- 3장. 조합논리 회로의 설계
-- section 02. 전가산기
--
library ieee;
use ieee.std_logic_1164.all;
entity FullAdder1_vhdl is
port (
x, y, z : in std_logic;
S, C : out std_logic
);
end FullAdder1_vhdl;
architecture arc of FullAdder1_vhdl is
signal k : std_logic_vector(2 downto 0);
begin
k <= x & y & z;
process(k)
begin
case k is
when "000" =>
S <= '0';
C <= '0';
when "001" =>
S <= '1';
C <= '0';
when "010" =>
S <= '1';
C <= '0';
when "011" =>
S <= '0';
C <= '1';
when "100" =>
S <= '1';
C <= '0';
when "101" =>
S <= '0';
C <= '1';
when "110" =>
S <= '0';
C <= '1';
when "111" =>
S <= '1';
C <= '1';
end case;
end process;
end arc;
별다른 것은 없고...
27번 라인, &로 signal들을 묶어 vector로 변환이 가능하다.
30번 라인, process는 순차기술문 (sequential statement) 을 제공하기 위한 기본 구조체. sensitivity list 에 포함된 signal (이 경우 k) 의 값이 변할 때마다 process 내의 문장들이 순차적으로 실행된다.
진리표를 옮길 때에는 case~when 구문이 편리하다.
다른 설계.
=========
카르노 맵을 이용하면 S, C는 다음과 같이 간소화 할 수 있다.
S = x'y'z + x'yz' + xy'z' + xyz
C = xy + xz + yz
이를 이용하여 구현.
library ieee;
use ieee.std_logic_1164.all;
entity FullAdder2_vhdl is
port (
x, y, z : in std_logic;
S, C : out std_logic
);
end FullAdder2_vhdl;
architecture arc of FullAdder2_vhdl is
signal nx, ny, nz : std_logic;
begin
nx <= not x;
ny <= not y;
nz <= not z;
--
-- S = x'y'z + x'yz' + xy'z' + xyz
-- C = xy + xz + yz
--
S <= (nx and ny and z) or
(nx and y and nz) or
(x and ny and nz) or
(x and y and z);
C <= (x and y ) or
(x and z) or
(y and z);
end arc;
특이한 점은 없다.
또 다른 구현
===========
--
-- VHDL을 이용한 FPGA 디지털 설계
-- 3장. 조합논리 회로의 설계
-- section 02. 전가산기
-- 코드 3-5
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity FullAdder3_vhdl is
port (
x, y, z : in integer range 0 to 1;
S, C : out std_logic
);
end FullAdder3_vhdl;
architecture arc of FullAdder3_vhdl is
signal sum : std_logic_vector(1 downto 0);
begin
--
-- conv_std_logic_vector 의 사용 예.
-- 참고: conv_integer, conv_unsigned, conv_signed
--
process(x, y, z)
begin
sum <= conv_std_logic_vector(x + y + z, 2);
end process;
S <= sum(0);
C <= sum(1);
end arc;
x, y, z를 integer 로 선언. 그리고 conv_std_logic_vector 함수를 사용하였다.
이를 위해 ieee.set_logic_arith 를 인클루드.
* 변환 함수:
conv_integer : unsigned, signed 또는 std_logic 값을 integer 값으로 변환한다. 이 함수의 범위는 -2147483647 ~ 2147483647 (응?) 로 31비트 unsigned 값 또는 32비트 signed 값에 해당한다.
conv_unsigned : 변환될 비트의 수 (size bit)와 함께 integer, unsigned, signed 또는 std_ulogic을 unsigned 값으로 변환한다.
conv_signed : 변환될 비트의 수와 함께 integer, unsigned, signed 또는 std_ulogic 값을 signed 값으로 변환한다.
conv_std_logic_vector : 변환될 비트의 수와 함께 integer, unsigned, signed 또는 std_ulogic 값을 std_logic_vector 값으로 변환한다.
좀 더 찾아보자.