Verilog HDL
2007/06/18 22:22
http://blog.naver.com/PostPrint.nhn?blogId=babojay&logNo=40038879588#
Chapter 5.
Gete-Level Modeling
Áö±Ý±îÁö VerilogÀÇ ±âº»ÀûÀÎ °Íµé¿¡ ´ëÇØ ¾Ë¾Æº¸¾Ò´Ù. ÀÌÁ¦ ½ÇÁ¦ Çϵå¿þ¾îÀÇ ¸ðµ¨¸µÀ» »ìÆ캸ÀÚ. Çϵå¿þ¾î ±â¼ú(H/W description)¿¡ ³× °³ÀÇ Ãß»óÈ ´Ü°è Áß Gate level modeing¿¡ ´ëÇØ ¸ÕÀú »ìÆ캻´Ù. µðÁöÅÐȸ·Î¿¡ ´ëÇÑ ±âº»Áö½ÄÀÌ ÀÖ´Ù¸é gate levelÀÌ ÀÌÇØÇÏ°í ¼³°èÇϱ⿡ °¡Àå Á÷°üÀûÀ̶ó°í »ý°¢µÈ´Ù. À̺¸´Ù ´õ ³·°í ±âÃÊ°¡ µÇ´Â switch level modelingÀÌ ÀÖÁö¸¸, ±¸Á¶¿Í µ¿ÀÛÀÌ º¹ÀâÇÏ°í Á÷°üÀûÀÌÁö ¸øÇϱ⠶§¹®¿¡ ³ªÁß¿¡ ´Ù·ç±â·Î ÇÑ´Ù. ´õ±¸³ª ½ÇÁ¦ ¼³°èÇöÀå¿¡¼ switch level·Î ¸ðµ¨¸µ ÇÏ´Â ¿¹´Â ±×¸® ¸¹Áö ¾Ê±â ¶§¹®ÀÌ´Ù.
*Objectives
- Verilog¿¡¼ Áö¿øÇÏ´Â Logic Gate
Primitives.
- and/or , buf/not °ÔÀÌÆ®ÀÇ Áø¸®Ç¥¿Í ½Éº¼°ú instantiationÀÇ ÀÌÇØ
-
Logic diagramÀ¸·Î ºÎÅÍ Verilog ·Î ±â¼úÇÏ´Â ¹æ¹ýÀÇ ÀÌÇØ
- rise, fall, turn-off delayÀÇ
ÀÌÇØ
- min, max, typ delayÀÇ ÀÌÇØ
5.1 Gate Types
- Primitives : ±âº»ÀûÀ¸·Î Á¦°øµÇ´Â ¹Ì¸® Á¤ÀÇ µÇ¾î ÀÖ´Â logic gate modules
5.1.1 And/Or Gate
- ÇÑ°³ÀÇ output, ´Ù¼öÀÇ input.
- port listÀÇ ¸Ç óÀ½¿¡ ¿À´Â Å͹̳ÎÀº
outputÀÌ´Ù.
±×¸² 5.1 ±âº»ÀûÀÎ gate symbol°ú Áø¸®Ç¥
Ex)
wire OUT, IN1,
IN2, IN3;
// ±âº»ÀûÀÎ gate
instantiation
and a1(OUT, IN1, IN2);
nand na1(OUT, IN1, IN2);
or or1(OUT, IN1,
IN2);
nor nor1(OUT, IN1, IN2);
xor
x1(OUT, IN1, IN2);
xnor nx1(OUT, IN1, IN2);
// 2°³ ÀÌ»óÀÇ
ÀÔ·Â
nand na1_3inp(OUT, IN1, IN2, IN3);
// ÀνºÅϽº À̸§ÀÇ
»ý·«
and (OUT, IN1, IN2);
* º°µµÀÇ Á¤ÀÇ ¾øÀÌ »ç¿ë°¡´ÉÇϸç, ¸®½ºÆ®ÀÇ ¼ø¼¿¡ ÀÇÇØ ¿¬°áÀÌ ÀÌ·ç¾îÁø´Ù.
(out, i1, i2, i3,...)
** 2°³ ÀÌ»óÀÇ ÀÔ·ÂÀ» ¿øÇÒ °æ¿ì ¿øÇÏ´Â ÀÔ·ÂÀ»
±×³É Àû¾îÁØ´Ù.
*** ÀνºÅϽº À̸§ÀÌ ¾ø¾îµµ µÈ´Ù.
5.1.2 Buf/Not Gates
- ÇÑ°³ÀÇ input, ´Ù¼öÀÇ output.
- port listÀÇ ¸Ç ¸¶Áö¸·¿¡ ¿À´Â Å͹̳ÎÀÌ
inputÀÌ´Ù.
±×¸² 5.2 ±âº»ÀûÀÎ gate symbol°ú Áø¸®Ç¥
Ex)
// basic gate
instantiation
buf b1(OUT1, IN);
not
n1(OUT1, IN);
// 2°³ ÀÌ»óÀÇ
output
buf b1_2out(OUT1, OUT2, IN);
// ÀνºÅϽº À̸§ÀÇ
»ý·«
not (OUT1, IN);
¡á bufif/notif
- Á¦¾î½ÅÈ£(control signal)À» °®°í Ãâ·ÂÀ» Á¦¾îÇÏ´Â buf/not gateÀÌ´Ù.
- Á¦¾î½ÅÈ£´Â Á¤»óÃâ·ÂÀ» Ãâ·ÂÇϰųª
z(High impedance)¸¦ °®°Ô ÇÏ´Â ±â´ÉÀ»
ÇÑ´Ù.
±×¸² 5.3 bufif/notifÀÇ symbol°ú Áø¸®Ç¥
* bufif0/notif0´Â control ½ÅÈ£°¡ negative activeµ¿ÀÛÀ» ÇÏ°Ô µÈ´Ù.
Ex)
//
bufif
bufif1 b1(out, in, ctrl);
bufif0 b0(out, in, ctrl);
//
notif
notif1 n1(out, in, ctrl);
notif0 n0(out, in, ctrl);
5.1.3 Examples
¡á Gate-level multiplexer(4-to-1)
±×¸² 5.4 4-to-1 Multiplexer
À̸¦ Logic DiagramÀ¸·Î Ç¥ÇöÇÏ¸é ´ÙÀ½°ú °°´Ù.
±×¸² 5.5 Logic diagram for 4-to-1 MUX
Ex)
// Module
4-to-1 MUX
module mux4_to_1(out, i0, i1, i2, i3, s1,
s0);
output
out;
// Port declaration
input i0, i1, i2,
i3;
input s1, s0;
wire s1n,
s0n;
// Internal wire
wire y0, y1, y2, y3;
not (s1n,
s1);
// create s1n, s0n
not (s0n, s0);
and (y0, i0, s1n,
s0n); // 3-input and gate
and (y1,
i1, s1n, s0);
and (y2, i2, s1, s0n);
and (y3, i3, s1, s0);
or (out, y0, y1, y2, y3); // 4-input or gate
endmodule
* ±×¸² 5.5¿¡¼¿Í °°ÀÌ ³»ºÎÀûÀ¸·Î s1n, s0nÀÌ ÇÊ¿äÇÏ°í, y0, y1, y2, y3ÀÌ
ÇÊ¿äÇÏ´Ù.
** primitivesÀÇ ÀÌ¿ëÀ¸·Î ÀνºÅϽº À̸§ÀÌ ¸ðµÎ »ý·«µÇ¾ú´Ù. DescriptionÀÌ °£·«ÇØÁø´Ù.
¿©±â¿¡ stimulus¸¦ Ãß°¡ÇÏ¿© ½ÃÇèÇÏ´Â ¹æ¹ýÀº ´ÙÀ½°ú °°´Ù.
Ex)
// stimulus
moduleÀÇ Á¤ÀÇ
module stimulus;
reg IN0, IN1, IN2,
IN3;
reg S1, S0;
wire OUTPUT;
mux4_to_1 mymux(OUTPUT, IN0, IN1, IN2, IN3, S1, S0);
initial
begin
IN0 = 1; IN1 = 0; IN2
= 1; IN3 = 0;
#1 $display("IN0 =
%b, IN1 = %b, IN2 = %b, IN3 = %b\n", IN0, IN1, IN2, IN3);
S1 = 0; S0 =
0; // chose
IN0
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 0; S0 =
1; // chose
IN1
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 1; S0 =
0; // chose
IN2
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 1; S0 =
1; // chose
IN3
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
end
endmodule
½Ã¹Ä·¹ÀÌ¼Ç °á°ú
IN0 = 1, IN1 = 0, IN2 = 1, IN3 = 0
S1 = 0, S0 = 0, OUTPUT = 1
S1 = 0, S0 = 1, OUTPUT = 0
S1 = 1, S0 = 0, OUTPUT = 1
S1 = 1, S0 = 1, OUTPUT = 0
¡á 4-bit full adder
- 4-bit ripple carry adder¸¦ ±¸ÇöÇϱâ À§ÇØ 1-bit full adder¸¦ ¸ÕÀú
±¸ÇöÇÑ´Ù.
- 1-bit full adderÀÇ ¹æÁ¤½Ä°ú logic diagramÀº ´ÙÀ½°ú °°´Ù.
±×¸² 5.6. 1-bit full adder
Ex)
// 1-bit full
adder
module fulladd(sum, c_out, a, b, c_in);
output sum,
c_out; // I/O port declaration
input a, b, c_in;
wire s1, c1, c2;
xor (x1, a,
b);
and (c1, a, b);
xor (sum, s1,
c_in);
and (c2, s1, c_in);
or (c_out, c2, c1);
endmodule
- 4-bit ripple carry full adder ´Â 4 °³ÀÇ 1-bit full adder·Î ¸¸µé ¼ö ÀÖ´Ù.
±×¸² 5.7 4-bit full adder
Ex)
// 4-bit full
adder
module fulladd4(sum, c_out, a, b, c_in);
output [3:0]
sum;
output c_out;
input [3:0] a,
b;
input c_in;
wire c1, c2, c3;
fulladd fa0(sum[0],
c1, a[0], b[0], c_in);
fulladd fa1(sum[1], c2, a[1], b[1],
c_1);
fulladd fa2(sum[2], c3, a[2], b[2],
c_2);
fulladd fa3(sum[3], c_out, a[3], b[3],
c_3);
endmodule
Ex)
//
Stimulus for 4-bit full adder
module stimulus;
reg[3:0] A,
B;
reg C_IN;
wire [3:0]
SUM;
wire C_OUT;
fulladd4 FA1_4(SUM, C_OUT, A, B, C_IN);
initial
begin
$monitor($time, "A= %b, B=
%b, C_IN= %b, --- C_OUT= %b, SUM= %b\n", A, B, C_IN, C_out,
SUM);
end
initial
begin
A = 4'd0; B = 4'd0; C_IN =
1'b0;
#5 A = 4'd3; B = 4'd4;
#5 A = 4'd2; B = 4'd5;
#5 A = 4'd9; B = 4'd9;
#5 A = 4'd10; B = 4'd15;
#5 A = 4'd10; B =
4'd5; C_IN = 1'b1;
end
endmodule
- ½Ã¹Ä·¹ÀÌ¼Ç °á°ú
0 A= 0000, B= 0000, C_IN= 0, --- C_OUT= 0, SUM = 0000
5 A= 0011, B= 0100, C_IN= 0, --- C_OUT= 0, SUM = 0111
10 A= 0010, B= 0101, C_IN= 0, --- C_OUT= 0, SUM = 0111
15 A= 1001, B= 1001, C_IN= 0, --- C_OUT= 1, SUM = 0010
20 A= 1010, B= 1111, C_IN= 0, --- C_OUT= 1, SUM = 1001
25 A= 1010, B= 0101, C_IN= 1, --- C_OUT= 1, SUM = 0000
5.2 Gate Delays
- Áö±Ý±îÁö gateÀÇ delay¿¡ ´ëÇÑ °í·Á´Â ¾ø¾úÁö¸¸, ½ÇÁ¦ H/W¿¡¼´Â delay¸¦ °í·ÁÇÏ¿© ¼³°èÇØ¾ß ÇÑ´Ù.
- primitivesµéµµ delay¿¡ ´ëÇÑ Æ¯¼ºÀ» ÁöÁ¤ÇÏ¿© ÁÙ ¼ö ÀÖ´Ù.
5.2.1 Rise, Fall, Turn-off Delays
- Rise delay : 0, x, z¿¡¼ 1·Î transitionµÇ´Âµ¥ ±îÁö °É¸®´Â ½Ã°£.
- Fall delay
: 1, x, z¿¡¼ 0À¸·Î transitionµÇ´Âµ¥ ±îÁö °É¸®´Â ½Ã°£.
-
Turn-off delay : 0, 1¿¡¼
z·Î trnasitionµÇ´Âµ¥ ±îÁö °É¸®´Â ½Ã°£.
±×¸² 5.8 Delays
- delay¸¦ ÁöÁ¤ÇØ ÁÖ´Â ¹æ¹ýµµ ¼¼°¡Áö°¡ ÀÖ´Ù.
- 1°³ÀÇ delay : Rise, Fall,
Turn-off¸ðµÎ µ¿ÀÏÇÏ°Ô ÁöÁ¤
- 2°³ÀÇ delay : (rise, fall) °ú °°ÀÌ ¾Õ¿¡ ÀÖ´Â °ÍÀÌ rise, µÚÀÇ °ÍÀÌ
fallÀÌ´Ù. À̶§ turn-off delay´Â µÑ Áß ÀÛÀº°ÍÀÌ µÈ´Ù.
- 3°³ÀÇ delay : (rise, fall,
turn-off)·Î °¢°¢ ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
- delay¸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ¸¸é ¸ðµç delay´Â 0ÀÌ µÈ´Ù.
Ex)
//Delay ÁöÁ¤
¹æ¹ý
and #(delay_time) a1(out, i1, i2); //
rise, fall, turn-off = delay_time
and #(rise_val, fall_val) a2(out, i1, i2); // rise = rise_val, fall = fall_val,
// turn-off = min(rise_val, fall_val)
bufif0
#(r_time, f_time, to_time) b1(out, in, ctrl); // °¢°¢
ÁöÁ¤(¼ø¼À¯ÀÇ)
and #(5) a1(out, i1,
i2);
// ¸ðµç delay´Â 5
and #(4,6) a2(out, i1,
i2); // rise =
4, fall = 6, turn-off = 4
bufif0 #(3,4,5) b1(out, in,
ctrl); // rise=3, fall=4, turn-off=5
5.2.2 Min/Typ/Max Values
- À§¿¡¼ ¾ð±ÞÇÑ ¼¼°¡ÁöÀÇ delay¿¡ ´ëÇÏ¿© ÃÖ¼Ò°ª, ÃÖ´ë°ª, º¸Åë°ªÀ» ÁöÁ¤ÇØ ³õÀ» ¼ö ÀÖ´Ù.
- ½Ã¹Ä·¹À̼Ç
°úÁ¤¿¡¼ ¼¼°¡Áö delay categoryÁß Çϳª¸¦ ¼±ÅÃÇÏ¿© ½Ã¹Ä·¹ÀÌ¼Ç Çغ¼ ¼ö ÀÖ°Ô µÈ´Ù.
- Verilog-XL ½Ã¹Ä·¹ÀÌÅÍÀÇ
°æ¿ì +maxdelays, +typdelays, +mindelaysÀÇ ¿É¼ÇÀ¸·Î delay¿É¼ÇÀ» ¼±ÅÃÇÒ ¼ö ÀÖ´Ù.
Ex)
//delay
sets
// rise delay = 3(min) : 4(typ) :
5(max)
// fall delay =
2(min : 3(typ) : 4(max)
// turn-off delay = 4(min) :
5(typ): 6(max)
and #(3:4:5, 2:3:4:,
4:5:6) a1(out, i1, i2);
>verilog test.v +maxdelays -> test.v¸¦ maxdelay°ªÀ¸·Î ½Ã¹Ä·¹À̼ÇÇ϶ó.
(Verilog-XL ½Ã¹Ä·¹ÀÌÅÍ)
5.2.3 Daely Example
±×¸² 5.9 Module D
Ex)
// Module
D
modue D (out, a, b, c);
output out;
input a, b,
c;
wire e;
and #(5) a1(e, a,
b);
or #(4) o1(out, e, c);
endmodule
Ex)
// Stimulus
for module D
module stimulus;
reg A, B,
C;
wire OUT;
D d1(OUT, A, B, C);
initial
begin
A = 1'b0; B = 1'b0; C =
1'b0;
#10 A = 1'b1; B = 1'b1; C = 1'b1;
#10 A = 1'b1; B = 1'b0; C = 1'b0;
#20
$finish;
end
endmodule
- À§ÀÇ ½Ã¹Ä·¹À̼ÇÀ» ½ÇÇà½ÃÄÑ waveformÀ» ¾òÀ¸¸é ´ÙÀ½°ú °°´Ù
±×¸² 5.10 Waveform of delay simulation