Nhóm 14 
1 
z 
z 
  
 
 
  
 
-  
 
 
 
 
 
 
 
 
 
 
 
 Sequential Logic Using 
UDP dùng Verilog 
 
 
  :  
  : 
: 
1. 
 
 
  
 : DT17AHN 
2008-2011  
 HÀ I ,ngày 25/ 04/ 2011  
 
 
Nhóm 14 
2      
 
: 6 
 6 
1.1.  6 
1.2. Khá 6 
  
.7 
1.4 8.9 
 
.10,11 
 12 
 12 
 12 
II.  G 12 
 13 
 13 
 13 
 13 
5. Cú pháp: 13 
 13 
 13 
 14 
 14 
1.1. Cú pháp: 14 
 14 
 14 
2.1. Cú pháp: 14 
 14 
 
Nhóm 14 
3 
IV.  15 
 15 
II. Wire: 16 
III. Reg: 16 
IV. Input, Output, Inout: 16 
 17 
II. Supply 0, Supply1: 17 
III. Time: 18 
 18 
V 19 
 19 
 19 
 19 
 20 
 20 
 20 
 20 
 20 
IX.  20 
 21 
 21 
 21 
III. G 22 
 22 
VII. MODULES 23 
I. Khai báo modules: 23 
 23 
III. Module instantiations: 24 
 25 
 25 
II. Delay trong  26 
 
Nhóm 14 
4 
 26 
 26 
 27 
 27 
 27 
VIII. Case: 27 
 28 
 28 
II 29 
X. HÀM 30 
I. Khai báo hàm: 30 
 30 
m: 31 
 32 
 32 
 32 
 32 
 
 33 
 33 
 33 
 33 
 33 
 34 
 34 
 34 
 35 
 35 
  36 
.37 
 a. 37 
 .38 
 
Nhóm 14 
5 
  
 39.40 
 41 
 42 
 42,43 
 44 
 44 
 44,45 
 46 
47 
: 47 
VERILOG.47,48,49 
 50 
 51                  
        
Nhóm 14 
6             
 
 
1.1.  
HDL-
high s
  
  
- Là ngôn ng thuc lp ngôn ng máy tính(computer language 
- Dùng miêu t cu trúc và hot ng mt vi mch 
- Dùng mô phng, kim tra hot ng vi mch 
- Biu din hành vi theo thi gian va cu trúc khônggian ca mch 
 
Nhóm 14 
7 
- Bao gm nhng ký hiu biu din thi gian và s1ng thi (time and 
concurrence)  
1.3 
 
Boolean h
 
 
 
Nhóm 14 
8 
thái( finite-state-
 
 
 
 
FPGA. 
1.4 
 
8-
-1076-1987). 
 
Nhóm 14 
9 
 
 
 
- 
 
- 
 
- 
 
- 
 
- 
 
 
Nhóm 14 
10 
- 
 
     
1.5.  
/** 
 * A behavioural model of a pipelined MAC unit. The two 4-bit 
inputs are 
 * multiplied in an 8-bit multiplier, with the result added to a 10-bit 
 * accumulator. The number of pipe stages is set by the 'stages' 
parameter, 
 * which defaults to 1. 
 * 
 * RST Synchronous reset 
 * C Clock 
 * A[3:0] Data Input 
 * B[3:0] Data Input 
 * Q[9:0] Accumulator output 
 */  
module MAC1 
 (input RST, CLK, 
 input [3:0] A, B, 
 output [9:0] Q);  
 parameter stages = 1;  
 reg [7:0] mul; 
 
Nhóm 14 
11 
 reg [9:0] sum[stages-1:0]; 
 integer i;  
 always @(posedge CLK) begin 
 for(i=stages-1; i>0; i = i-1) 
 sum[i] = sum[i-1];  
 if(RST) 
 sum[0] = 0; 
 else begin 
 mul = A * B; 
 sum[0] = sum[0] + mul; 
 end 
 end  
 assign Q = sum[stages-1]; 
endmodule             
 
Nhóm 14 
12 
 
 
I.  
VHDL. 
HDL 
n. 
 
 
 
 
 
 
// Khai báo module 
Module 
tên file.v. 
Input  
Output [msb:lsb] b 
Reg  
Wire  
 
 
Endmodule 
 
Nhóm 14 
13 
II.   
 
1. Khoảng trắng 
 
2. Chú giải 
C/C++) 
 
3. Chữ số: 
 
 
 
4. Từ định danh: 
 
5. Cú pháp: 
 
 
Không cho phé-, &, #, @ 
6. Toán tử: 
 
 
Nhóm 14 
14 
7. Từ khóaVerilog: 
assign, case, while, wire, reg, and, or, nand, và module. Chúng 
  
 
 
Drive_strenght 
strong1 và strong0 . 
Delay
 
 
1. Các cổng cơ bản: 
 
1.1. Cú pháp: 
GATE (drive_strength)#(delays) 
 
Delay 
 
Nhóm 14 
15 
1.2. Ví dụ: 
And  
 c2 
Or 
time = 3 
Xor  
2. Cổng buf, not: 
 
2.1. Cú pháp: 
 
2.2. Ví dụ: 
Not  
Buf  
c2 (p, f, g);  
IV.  
I. Đặt giá trị: 
 
 
 
 
 
 
 
II. Wire: 
 
Nhóm 14 
16 
 
 
 
 
1. Cú pháp: 
Wire [msb:lsb] tên  
Wand  
Wor  
Tri  
 
Wire c; 
Wand d; 
Assign d= a; 
Assign  
Wire  
III. Reg: 
Reg (register) 
 
1. Cú pháp: 
Reg  
 
Reg  
Reg  
Reg [5:0 
 
Nhóm 14 
17 
IV. Input, Output, Inout: 
 
1. Cú pháp: 
Input [msb:lsb] port ngõ vào. 
Output [msb:lsb] port ngõ ra. 
Inout  
 
Module sample (b, e, c, a); 
Input  
Output  
Output [1:0] 
riêng*/ 
Reg  
I. Integer (Số nguyên): 
là reg. 
 
 
1. Cú pháp: 
Integer  
 
 
Integer  
Assign  
II. Supply 0, Supply1: 
 
 
Nhóm 14 
18 
III. Time: 
 
1. Cú pháp: 
Time  
 
Time c; 
c = $time 
IV. Parameter (Tham số): 
 
1. Cú pháp: 
Parameter  
Parameter  
 
Parameter  
Parameter n = 4; 
Parameter ; 
 
reg [n-
th 
trên. 
always @(x) 
y = {{(add - sub) {x}}} 
if (x) begin 
state = par_2[1]; 
else 
state =par_2[2]; 
end. 
 
Nhóm 14 
19 
 
I. Toán tử số học: 
-
-z) - 
y). 
 
+, -, *, /, %. 
II. Toán tử quan hệ: 
-3b001) = (3b111) và (-
3b0-1< 6. 
  
<, <=, >, >=, = =, !=. 
III. Toán tử bit_wire: 
 
 
~ (bitwire NOT), & (bitwire AND), | (bitwire OR), ^ (bitwire 
OR). 
IV. Toán tử logic: 
 
 
  
!(NOT), && (AND), || (OR) 
Wire [7:0] x, y, z; 
Reg a; 
 
if ((x= = y)&&(z)) a=1; 
else a=! x; 
 
Nhóm 14 
20 
V. Toán tử biến đổi: 
 
 
 
 
VI. Toán tử ghép: 
 
  
 
VII. Toán tử dịch: 
Ghép  
  
{} (concatenation) 
Wire [2:0] x; 
Wire [3:0] y, Z; 
 
: 
. 
VIII. Toán tử điều kiện: 
 
  
 
IX. Thứ tự toán tử: 
   
 
Nhóm 14 
21 
 
Tên 
[ ] 
 
( ) 
 
!,~ 
 
&, |, ~&, ~|, ^, ~^ 
XNOR. 
+, - 
 
{ } 
 
{{ } } 
 
*, /, % 
 
+, - 
 
<<, >> 
 
<, <=, >, >= 
 
 
= =, != 
 
& 
 
^, ~^ 
Bit_wire XOR, Bit_wire XNOR. 
| 
Bit_wire OR. 
&&, || 
 
?: 
    
 
I. Literals (dạng kí tự): 
Verilog. Có  
 
 
 
 
 
 
 
Nhóm 14 
22 
 
 
 
 
 
 
 
 
II. Chọn 1 phần tử bit và chọn 1 phần các bit. 
  
1. Cú pháp: 
 
 
 
Reg [7:0] a, b; 
Reg [3:0] ls; 
c = a[7] & b[7]; 
ls = a[7:4] + b[3:0]; 
III. Gọi hàm chức năng: 
 
1. Cú pháp: 
 
 
Assign a = b & c & chk_bc(b, c); 
Function chk_bc; 
 
Nhóm 14 
23 
Input c, b; 
Chk_bc = b^ c; 
Endfunction 
IV. Wire, reg, và tham số: 
 
Verilog. 
VII. MODULES 
I. Khai báo modules: 
  
 
1. Cú pháp: 
Module tên module (danh sách port); 
Input [msb:lsb] danh sách port ngõ vào; 
Output [msb:lsb] danh sách port ngõ ra; 
Inout [ msb:lsb ] danh sách port vào_ ra; 
 
endmodule 
 
Module add_sub(add, in1, in2, out); 
 
Input[7:0 ] in1, in2; 
Wire in1, in2; 
Output [7:0] out; 
Reg out; 
 
Endmodule 
 
Nhóm 14 
24 
II. Chỉ định liên tiếp: 
 
1. Cú pháp: 
Wire  
Assign  
 
Wire  
Assign b = c &d; 
Assign d = x | y; 
III. Module instantiations: 
 
  
1. Cú pháp: 
 
 
 
 
 
module and4(a,b,c); 
input [3:0]a,b; 
 
Nhóm 14 
25 
output [3:0]c; 
assign c = a&b; 
endmodule 
// module instantiations 
wire [3:0] in1, in2; 
wire [3:0] o1, o2; 
 
and4 C1(in1, in2,o1); 
// tên 
and4 C2(.c(o2), .a(in1), .b(in2));  
 
 
 
 
 
  
 
I. Những chỉ định theo thủ tục: 
 
II. Delay trong chỉ định: 
-