a[0] - 한밭대학교 반도체설계실

Download Report

Transcript a[0] - 한밭대학교 반도체설계실

조합 논리회로 설계 및 검증
Sun, Hye-Seung
Hanbat National University Prof. Lee Jaeheung
반가산기(Half Adder)
2
반가산기 진리표
a
b
cout
sum
0
0
0
0
0
1
0
1
1
0
0
1
1
1
1
0
소스코드 15_2
a
sum
b
cout
반가산기
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
1비트 전가산기
3
전가산기 진리표
집적 회로 설계
a
b
cin
cout
sum
0
0
0
0
0
0
0
1
0
1
0
1
0
0
1
0
1
1
1
0
1
0
0
0
1
1
0
1
1
0
1
1
0
1
0
1
1
1
1
1
Hanbat National University Prof. Lee Jaeheung
1비트 전가산기
a
b
4
s1
sum
c2
cin
cout
c1
반가산기
a
b
cin
Half
Adder
s1
Half
Adder
sum
c2
cout
c1
반가산기 모듈을 이용한 전가산기
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
1비트 전가산기
5
HDL Modeling
module fa_assign (a, b, cin, sum, cout);
input a, b, cin;
output sum, cout;
// assign 문을
assign s1
assign c1
assign c2
assign sum
assign cout
endmodule
집적 회로 설계
소스코드 15_2
사용한 모델링
= a ^ b;
= a & b;
= s1 & cin;
= s1 ^ cin;
= c1 ^ c2;
코드 15.10
Hanbat National University Prof. Lee Jaeheung
1비트 전가산기
6
동작 확인
LED Array
cout
sum
a
b
cin
fa
c
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
1비트 전감산기(Full Subtractor)
7
 반감산기(half subtractor)와 전감산기의 진리표
전감산기 진리표
반 감산기 진리표
a
b
borrow
sub
a
b
bin
borrow
sub
0
0
0
0
0
0
0
0
0
0
1
1
1
0
0
1
1
1
1
0
0
1
0
1
0
1
1
1
1
0
0
0
1
1
1
0
1
0
0
0
1
1
0
1
0
0
1
1
0
0
0
1
1
1
1
1
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
1비트 전감산기
8
HDL Modeling
module fs_?? (a, b, bin, sub, borrow);
input
a, b, bin;
output
sub, borrow;
①
②
③
④
⑤
소스코드
Ex_15_2_1
게이트 프리미티브를 사용하여 코드를 완성(fs_primitive)
assign 구문을 사용하여 코드를 완성(fs_assign)
if 조건문을 사용하여 코드를 완성(fs_if)
case 문을 사용하여 코드를 완성(fs_case)
반감산기 모듈(hs)을 설계하고, 인스턴스 하여 코드를 완성
(fs_hs_instance)
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
Parameter를 이용한 multi-bit 가산기
9
 전가산기의 입력 a와 b, 출력 sum의 비트 수를 parameter N으로 선
언하여 N-비트 ripple-carry adder(RCA)를 설계
b[N-1] a[N-1]
b[1] a[1]
b[0] a[0]
full adder
full adder
full adder
sum[N-1]
sum[1]
sum[0]
Add_Nb
cout
cin
N-비트 ripple-carry adder(RCA)
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
Parameter를 이용한 multi-bit 가산기
10
a b
0
cin
1
sum = a  b  cin = p  cin
cout = a · b + a · cin + b · cin
= !p · a + p · cin
p
1비트 전가산기의 부울 식
cout
sum
1비트 전가산기
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
Parameter를 이용한 multi-bit 가산기
module add_Nb (a,
parameter
input [N-1:0]
input
output [N-1:0]
output
reg
[N-1:0]
reg
[N-1:0]
reg
[N:0]
integer
b, cin, sum, cout);
N=1;
a, b;
cin;
sum;
cout;
sum;
p;
carry;
i;
11
소스코드
Ex_15_3_1
always @ (a or b or cin) begin
carry[0] = cin
for (i=0; i<N; i=i+1) begin
그림 15.11(b)의 회로를 참고하여 다음과 같이 코딩.
∙ 연산자 ^를 이용하여 p[i], sum[i]를 구현
∙ case 문을 이용한 MUX로 carry[i+1]을 구현
end // END of for
end
// END of always
assign cout = carry[N];
endmodule
집적 회로 설계
코드 15.17
Hanbat National University Prof. Lee Jaeheung
Parameter를 이용한 multi-bit 가산기
12
동작 확인
LED Array
cout
sum
a
b
cin
add_Nb
c
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
모듈 파라미터 변경을 이용한 8비트 가산기 설계
13
 코드 15.17에서 설계된 add_Nb 모듈의 parameter N을 8로 변경하
여 8-비트 RCA를 설계
b[7] a[7]
cout
full adder
sum[7]
b[1] a[1]
b[0] a[0]
full adder
full adder
sum[1]
sum[0]
0
8-비트 ripple-carry adder(RCA)
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
모듈 파라미터 변경을 이용한 8비트 가산기 설계
14
module add_8b (a, b, sum, cout);
parameter
N=8;
input [7:0] a, b;
output [7:0] sum;
output
cout;
소스코드
Ex_15_3_1
설계된 add_Nb 모듈(코드 15.17)을
인스턴스하고, parameter overriding을 통해
8비트 가산기를 구현한다.
*가산기의 캐리입력(cin)은 0으로 한다.
LED Array
endmodule
sum[7:0]
cout
add_8b
cin
12345678
BUS SW 1
a[7:0]
BUS SW 2
b[7:0]
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
0
모듈 파라미터 변경을 이용한 8비트 가/감산기
15
 코드 15.17에서 설계된 add_Nb 모듈의 parameter N을 8로 변경하
여 8-비트 가산/감산기를 설계
◆ mode
신호에 따라 가산(mode=0)과 감산(mode=1)을 선택적으로 연산
a  b  a  (b)  a  (b  1)
a[7]
b[7]
for 2' s complement number a, b
a[1]
b[1]
a[0]
b[0]
8-b RCA
cout
full adder
full adder
full adder
sum[7]
sum[1]
sum[0]
mode
8-비트 가산/감산기
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
모듈 파라미터 변경을 이용한 8비트 가/감산기
16
module add_sub_8b (a, b, mode, sum, cout);
parameter
N=8;
input [7:0] a, b;
input
mode;
output [7:0] sum;
output
cout;
소스코드
Ex_15_3_2
15.3.1에서 설계된 add_Nb 모듈(코드 15.17)을 인스턴스하고,
parameter overriding을 통해 8비트 RCA를 설계한다.
* mode 신호에 따라 8비트 가산과 감산을 선택적으로 연산하도록 설계
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
모듈 파라미터 변경을 이용한 8비트 가/감산기
17
LED Array
sum[7:0]
cout
add_sub_8b
mode
12345678
BUS SW 1
BUS SW 2
집적 회로 설계
a[7:0]
b[7:0]
Hanbat National University Prof. Lee Jaeheung
8:3 이진 인코더
18
 8:3 이진 인코더를 다음의 3가지 방법으로 설계
①
case 문을 사용하는 방법
②
if 조건문을 사용하는 방법
③
for 반복문을 사용하는 방법
8:3 이진 인코더 진리표
인코더 입력
(enc_in)
인코더 출력
(enc_out)
0000 0001
000
0000 0010
001
0000 0100
010
0000 1000
011
enc_out[2:0]
0001 0000
100
8:3 이진 인코더
0010 0000
101
0100 0000
110
1000 0000
111
enc_in[7:0]
Binary Encoder
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
8:3 이진 인코더
19
module enc_8to3_case (enc_in, enc_out);
input [7:0] enc_in;
output [2:0] enc_out;
reg
[2:0] enc_out;
always @(enc_in) begin
case (enc_in)
8'h01 : enc_out
8'h02 : enc_out
8'h04 : enc_out
8'h08 : enc_out
8'h10 : enc_out
8'h20 : enc_out
8'h40 : enc_out
8'h80 : enc_out
default : enc_out
endcase
end
endmodule
집적 회로 설계
=
=
=
=
=
=
=
=
=
소스코드 15_5
0;
1;
2;
3;
4;
5;
6;
7;
3'b000;
Hanbat National University Prof. Lee Jaeheung
8:3 이진 인코더
module enc_8to3_if (enc_in, enc_out);
input [7:0] enc_in;
output [2:0] enc_out;
소스코드 15_5
▪ if 조건문을 사용하여 코드를 완성한다.
∙ 표 15.20에 나열된 입력조건 이외에는 000이 출력되도록 한다.
endmodule
module enc_8to3_for (enc_in, enc_out);
input [7:0] enc_in;
output [2:0] enc_out;
▪ for 반복문을 사용하여 코드를 완성한다.
∙ 반복문 시작 전에 temp=8'b0000_0001의 초기값을 설정
∙ enc_in의 비트 수 만큼 반복하는 for 루프
∙ 반복루프 내부에서
* if(enc_in == temp)를 판단하여 enc_out=i
* temp를 왼쪽으로 1비트씩 시프트
▪ 표 15.20에 나열된 입력조건 이외에는 000이 출력되도록 한다.
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
8:3 이진 인코더
기능 검증
21
테스트벤치 작성
시뮬레이션
시뮬레이션 결과
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
8:3 이진 인코더
22
LED Array
enc_out[2:0]
enc_8to3
12345678
BUS SW 1
집적 회로 설계
enc_in[7:0]
Hanbat National University Prof. Lee Jaeheung
3:8 이진 디코더
23
 3:8 이진 디코더를 다음의 3가지 방법으로 설계
①
if 조건문을 사용하는 방법
②
case 조건문을 사용하는 방법
③
for 반복문을 사용하는 방법
3:8 이진 디코더 진리표
dec_in[2:0]
Binary Decoder
dec_out[7:0]
3:8 이진 디코더
집적 회로 설계
디코더 입력
(dec_in)
디코더 출력
(dec_out)
000
0000 0001
001
0000 0010
010
0000 0100
011
0000 1000
100
0001 0000
101
0010 0000
110
0100 0000
111
1000 0000
Hanbat National University Prof. Lee Jaeheung
3:8 이진 디코더
24
module dec_3to8_if (dec_in, dec_out);
input [2:0] dec_in;
output [7:0] dec_out;
reg
[7:0] dec_out;
always @(dec_in)
if
(dec_in
else if(dec_in
else if(dec_in
else if(dec_in
else if(dec_in
else if(dec_in
else if(dec_in
else
end
begin
== 0)
== 1)
== 2)
== 3)
== 4)
== 5)
== 6)
dec_out
dec_out
dec_out
dec_out
dec_out
dec_out
dec_out
dec_out
=
=
=
=
=
=
=
=
소스코드 15_6
8'h01;
8'h02;
8'h04;
8'h08;
8'h10;
8'h20;
8'h40;
8'h80;
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
3:8 이진 디코더
25
module dec_3to8_case (dec_in, dec_out);
input [2:0] dec_in;
output [7:0] dec_out;
reg
[7:0] dec_out;
소스코드 15_6
▪ case 문을 사용하여 코드를 완성한다.
endmodule
module dec_3to8_for (dec_in, dec_out);
input [2:0] dec_in;
output [7:0] dec_out;
reg
[7:0] dec_out;
▪ for 반복문을 사용하여 코드를 완성한다.
∙ dec_out의 비트 수 만큼 반복하는 for 루프
∙ 반복루프 내부에서 if(dec_in == i)를 판단하여
dec_out[i]에
1 또는 0을 할당
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
3:8 이진 디코더
기능 검증
26
테스트벤치 작성
시뮬레이션
시뮬레이션 결과
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
3:8 이진 디코더
27
동작 확인
LED Array
dec_out[7:0]
dec_3to8
12345678
BUS SW 1
dec_in[2:0]
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
BCD to 7-Segment 디코더
28
bcd_in[3:0]
BCD-to-7-seg 디코더 진리표
BCD-to-7-Segment
Decoder
seg_data[7:0]
a
b
f
g
c
e
d
h
집적 회로 설계
seg_com[7:0]
a=seg_data[0]
b=seg_data[1]
c=seg_data[2]
d=seg_data[3]
e=seg_data[4]
f =seg_data[5]
g=seg_data[6]
h=seg_data[7]
bcd_in
seg_data(hgfe_dcba)
디스플레이 값
0000
0011 1111
0
0001
0000 0110
1
0010
0101 1011
2
0011
0100 1111
3
0100
0110 0110
4
0101
0110 1101
5
0110
0111 1101
6
0111
0000 0111
7
1000
0111 1111
8
1001
0110 0111
9
Hanbat National University Prof. Lee Jaeheung
BCD to 7-Segment 디코더
29
소스코드
Ex_15_6_2
module bcd_seg_dec (bcd_in, seg_data, seg_com);
input [3:0] bcd_in;
output [7:0] seg_com;
output [7:0] seg_data;
▪ 앞 진리표를 구현하는 함수 bcd_to_seg를 정의한다.
∙ 함수 내부에 if 조건문 또는 case 문을 사용하여 코딩한다.
▪ 함수 bcd_to_seg를 호출하여 seg_data에 할당하는 구문
assign seg_com=8'b0111_1111;
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
BCD to 7-Segment 디코더
기능 검증
테스트벤치 작성
시뮬레이션
30
e
f
g
.
a
b
c
d
동작 확인
7-segment
Array
com5
com6
com7
com8
com1
com2
com3
com4
seg_com[7:0]
seg_data[7:0]
bcd_seg_dec
12345678
BUS SW 1
집적 회로 설계
bcd_in[3:0]
Hanbat National University Prof. Lee Jaeheung
4비트 ALU
31
 4비트 ALU (Arithmetic & Logic Unit)
◆ inst[3]=0이면
논리연산을 수행
◆ inst=[3]=1이면
◆ inst[2:1]에
◆ inst[0]에
산술연산을 수행
따라 4가지 논리연산 수행
논리연산
op_b[3:0]
4비트 ALU
alu_out[3:0]
집적 회로 설계
명령어(inst)
따라 논리연산 결과를 반전
op_a[3:0]
4비트 ALU의 명령어
inst[3:0]
산술연산
ALU 동작
0000
4'b0000
0001
4'b1111 (saturation)
0010
a AND b
0011
a NAND b
0100
a OR b
0101
a NOR b
0110
a XOR b
0111
a XNOR b
1000
a
1001
NOT a
1010
a+1
1011
a-1
1100
a+b
1101
a-b
Hanbat National University Prof. Lee Jaeheung
4비트 ALU
32
module alu_4b (op_a, op_b, inst, alu_out);
소스코드 15_7
input [3:0] op_a, op_b;
input [3:0] inst;
output [3:0] alu_out;
reg
[3:0] logic_out, arith_out, alu_out;
always @(op_a or op_b or inst) begin
▪ 다음과 같이 코딩한다.
∙ case(inst[2:1])로 4가지 논리연산(zero, AND, OR, XOR)을 구현하여
logic_out 생성
∙ case(inst[2:0])로 6가지 산술연산을 구현하여 arith_out 생성
∙ case(inst[3])으로 logic_out 또는 arith_out을 선택하여 alu_out
생성
단, 논리연산의 경우에는 if(inst[0]) 조건문으로 반전 관계를 구현
* 정의되지 않은 명령어 값의 경우에는 alu_out=0000을 출력
* 산술연산에서 발생되는 캐리출력은 무시한다.
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
4비트 ALU
33
기능 검증
테스트벤치 작성
시뮬레이션
시뮬레이션 결과
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
4비트 ALU
34
동작 확인
LED Array
alu_out[3:0]
alu_4b
12345678
op_a[3:0]
op_b[3:0]
inst[3:0]
BUS SW 1
BUS SW 2
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
좌/우 시프트 기능이 추가된 4비트 ALU35
명령어
4비트 ALU 명령어
논리연산
op_a[3:0]
op_b[3:0]
4비트 ALU
alu_out[4:0]
inst[5:0]
산술연산
시프트
연산
집적 회로 설계
ALU 동작
xx0000
5'b00000
xx0001
5'b11111 (saturation)
xx0010
a AND b
xx0011
a NAND b
xx0100
a OR b
xx0101
a NOR b
xx0110
a XOR b
xx0111
a XNOR b
xx1000
a
xx1001
NOT a
xx1010
a+1
xx1011
a-1
xx1100
a+b
xx1101
a-b
00xxxx
논리ㆍ산술연산 결과를 좌로 1비트 시프트
01xxxx
논리ㆍ산술연산 결과를 우로 1비트 시프트
10xxxx
No Shift
11xxxx
5'b00000
Hanbat National University Prof. Lee Jaeheung
좌/우 시프트 기능이 추가된 4비트 ALU36
module alu_4b_sh
input [3:0]
input [5:0]
output [4:0]
reg
[4:0]
reg
[4:0]
(op_a, op_b, inst, alu_out);
op_a, op_b;
inst;
alu_out;
alu_out;
logic_out, arith_out, mux_out;
소스코드
Ex_15_7_1
always @(op_a or op_b or inst) begin
// Logic & Arithmetic operations
▪ 다음과 같이 코딩한다.
∙ case (inst[2:1])로 4가지 논리연산(zero, AND, OR, XOR)을 구현하여
logic_out을 생성
∙ case (inst[2:0])으로 6가지 산술연산을 구현하여 arith_out을 생성
∙ case (inst[3])으로 logic_out과 arith_out을 선택하여 mux_out을 생성
단, 논리연산의 경우에는 if (inst[0]) 조건문으로 반전 관계를 구현
* 정의되지 않은 명령어 값의 경우에는 alu_out=00000을 출력
//Shift operations
▪ case (inst[5:4])를 사용하여 mux_out이 시프트된 alu_out을 만든다.
end // END of always
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
좌/우 시프트 기능이 추가된 4비트 ALU37
동작 확인
LED Array
alu_out[4:0]
alu_4b_sh
12345678
op_a[3:0]
op_b[3:0]
inst[5:0]
BUS SW 1
BUS SW 2
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
cnt_one_segdis 회로
38
 cnt_one_segdis 회로
◆ 8비트
입력 data_word에 포함된 1의 개수를 계수하여 7-segment에 10
진수로 표시하는 회로
data_word[7:0]
count_ones
(task)
cnt_one[3:0]
bcd_to_seg
(function)
seg_data[7:0]
seg_com[7:0]
cnt_one_segdis 회로
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
cnt_one_segdis 회로
39
8비트 입력 data_word에 포함된 1의 개수를 찾는 task conut_ones를 정의
task count_ones;
input [7:0] data_word;
output [3:0] count;
begin
소스코드 15_8
▪ 입력 data_word를 temp_reg로 치환하고, count=0으로 초기화.
▪ while(count < 9 && temp_reg) 반복문 내부에서
∙ temp_reg[7]=1이면 count를 1씩 증가시킨다.
∙ temp_reg를 왼쪽으로 1비트씩 시프트시킨다.
end
endtask
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
cnt_one_segdis 회로
40
소스코드 15_8
BCD to 7-Segment 디코더를 function bcd_to_seg로 정의
function [7:0] bcd_to_seg;
input [3:0] bcd_in;
begin
▪ BCD to 7-Segment 디코더를 함수 bcd_to_seg로 정의
end
endfunction
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
cnt_one_segdis 회로
41
소스코드 15_8
module cnt_one_segdis (data_word, seg_com, seg_data);
input [7:0] data_word;
output [7:0] seg_com
output [7:0] seg_data;
▪ 컴파일러 지시어를 이용하여 task count_ones.v를 include시킨다.
▪ 컴파일러 지시어를 이용하여 함수 bcd_to_seg.v를 include시킨다.
▪ always 문에서
∙ task count_ones를 호출하여 결과값을 cnt_one으로 받는다.
∙ 함수 bcd_to_seg를 호출하여 cnt_one을 seg_data로 변환한다.
assign seg_com=8'b0111_1111;
endmodule
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
cnt_one_segdis 회로
기능 검증
42
테스트벤치 작성
시뮬레이션
시뮬레이션 결과
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung
cnt_one_segdis 회로
43
동작 확인
e
f
g
.
a
b
c
d
7-segment
Array
com5
com6
com7
com8
com1
com2
com3
com4
seg_com[7:0]
seg_data[7:0]
cnt_one_segdis
12345678
data_word[7:0]
BUS SW 1
집적 회로 설계
Hanbat National University Prof. Lee Jaeheung