Da - Afds338164 - TK Fpga - Asic

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

TRƯỜNG ĐH SƯ PHẠM KỸ THUẬT TPHCM

KHOA ĐÀO TẠO CHẤT LƯỢNG CAO ĐÁP ÁN CUỐI KỲ HK 1 NĂM HỌC 2019-2020
NGÀNH KỸ THUẬT MÁY TÍNH Môn: Thiết kế FPGA/ASIC
Mã môn học: AFDS338164
Đề số/Mã đề: AFDS338164.

Câu 1: (2.0 điểm) Thiết kế mạch giải mã led 7 đoạn anode/cathode chung, có tín hiệu lựa
chọn E.
Nếu E = 0: Giải mã led 7 đoạn anode chung, E = 1: Giải mã led 7 đoạn cathode chung

module HEX27SEG(
input wire [3:0] i,
input wire e,
output wire [7:0] leds
);
reg [7:0] q;
always @(i,e)
case (i)
0: q = 8'b0100_0000 ;
1: q = 8'b1111_1001;
2: q = 8'b1010_0100;
3: q = 8'b1011_0000;
4: q = 8'b1001_1001;
5: q = 8'b1001_0010;
6: q = 8'b1000_0010;
7: q = 8'b1111_1000;
8: q = 8'b1000_0000;
9: q = 8'b1001_0000;
default: q = 8'b1111_1111;
endcase
assign leds = (e)?~q:(q) ;
endmodule

Câu 2: (3.0 điểm) Sử dụng phương pháp thiết kế mạch tuần tự đồng bộ, thiết kế mạch đếm
từ 0 đến 9 và tự động lặp lại, ngõ ra hiển thị trên 1 LED 7 đoạn. Tín hiệu sw 0 cho phép lựa
chọn led hiển thị, sw0 = 0: hiển thị trên LED0, sw=1: hiển thị trên LED1. Cho tần số xung
clock ngõ vào là 1Hz, sử dụng mạch giải mã đã thiết kế ở câu 1 (Sinh viên không trình bày lại
chương trình cho mạch giãi mã).

module SynCounter(
input wire clk, reset, sw0,
output wire [7:0] a,b );
wire [3:0]q1;
wire [7:0]leds;
Counter counter1 (clk,reset,q1) ;
HEX27SEG h27seg1(q1,1'b0,leds);
demux dm1 (leds,sw0,a,b);
endmodule
module Counter
( input wire clk, reset,
output wire [3:0] q );
reg [7:0] r_reg;
Số hiệu: BM1/QT-PĐBCL-RĐTV Trang: 1/1
wire [7:0] r_next;
always @(posedge clk, posedge reset)
if (reset)
r_reg <= 0;
else
if (r_reg==9)
r_reg = 0 ;
else r_reg<=r_next;
assign r_next =r_reg + 1;
assign q=r_reg;
endmodule

module HEX27SEG(
input wire [3:0] i,
input wire e,
output wire [7:0] leds
);
reg [7:0] q;
always @(i,e)
case (i)
0: q = 8'b1100_0000 ;
1: q = 8'b1111_1001;
2: q = 8'b1010_0100;
3: q = 8'b1011_0000;
4: q = 8'b1001_1001;
5: q = 8'b1001_0010;
6: q = 8'b1000_0010;
7: q = 8'b1111_1000;
8: q = 8'b1000_0000;
9: q = 8'b1001_0000;
default: q = 8'b1111_1111;
endcase
assign leds = (e)?~q:(q) ;
endmodule

module demux(
input wire [7:0] in,
input wire sw,
output wire [7:0] a,b
);

assign a=(sw)?in:8'hff ;
assign b=(sw==0)?in:8'hff ;

endmodule

Câu 3: (3.0 điểm) Thiết kế mạch thực hiện mô hình máy trạng thái như sau.
- Thiết kế bảng trạng thái cho mô hình
- Viết chương trình mô tả mạch

Present state Next state Output

Số hiệu: BM1/QT-PĐBCL-RĐTV Trang: 1/1


a=0 a=1

A B C 00
B E C 01
C E D 01
D E C 10
E C F 10
F A B 11

module FSM(
input wire clock, reset, a,
output wire z1,z0);

reg [2:0] y, Y;
parameter [2:0] A = 3'b000, B = 3'b001, C = 3'b010, D = 3'b011,E = 3'b100 ,F = 3'b101 ;
// define the next state of combination circuits

always @(a,y)
case (y)
A: if (a) Y = C ;
else Y = B ;
B: if (a) Y = C;
else Y = E ;
C:if (a) Y = D;
else Y =E ;
D: if(a) Y= C ;
else Y = E ;
E: if(a) Y= F ;
else Y = C ;
F: if(a) Y= B ;
else Y = A ;
default: Y = 2'bxxx ;
endcase

// define the sequential block


always @(negedge reset, posedge clock)
if (reset==0) y=A ;
else y= Y;
// Define output
assign z0 = (y == B)||(y == C)||(y == F);
assign z1 = (y == D)||(y == E)||(y == F);
endmodule

Câu 4. (2.0 điểm) Thiết kế thanh ghi dịch đồng bộ 32 bit, vào nối tiếp, ra song song.

module Shift32(
input wire clk,data, reset,
output [31:0] q
);
reg [31:0] r_reg;
Số hiệu: BM1/QT-PĐBCL-RĐTV Trang: 1/1
wire [31:0] r_next;
always @(posedge clk, posedge reset)
if (reset)
r_reg <= 0;
else r_reg<=r_next;

assign r_next = {r_reg[30:0],data};


assign q=r_reg;
endmodule

Số hiệu: BM1/QT-PĐBCL-RĐTV Trang: 1/1

You might also like