西安交通大学数字电子技术实验.docx

上传人:b****5 文档编号:28123176 上传时间:2023-07-08 格式:DOCX 页数:25 大小:176.02KB
下载 相关 举报
西安交通大学数字电子技术实验.docx_第1页
第1页 / 共25页
西安交通大学数字电子技术实验.docx_第2页
第2页 / 共25页
西安交通大学数字电子技术实验.docx_第3页
第3页 / 共25页
西安交通大学数字电子技术实验.docx_第4页
第4页 / 共25页
西安交通大学数字电子技术实验.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

西安交通大学数字电子技术实验.docx

《西安交通大学数字电子技术实验.docx》由会员分享,可在线阅读,更多相关《西安交通大学数字电子技术实验.docx(25页珍藏版)》请在冰豆网上搜索。

西安交通大学数字电子技术实验.docx

西安交通大学数字电子技术实验

数字电子技术

基于FPGA的EDA基础试验

 

姓名:

王子丰

班级:

电气42班

学号:

2140401052

一、实验目的

1.学习使用ISE13.4软件生成一个新工程文件;

2.学习使用HDL进行电路设计;

3.学会编辑顶层文件和用户约束文件;

4.熟悉仿真、综合、实现及FPGA配置等;

5.熟悉在Basys2开发板上的简单外围设备的控制。

二、实验内容

1.组合逻辑电路实验

1)第一题

源文件:

moduleexp1-1(

inputa,

inputb,

inputc,

inputd,

outputy

);

assigny=~(a&b|c&d);

endmodule

约束文件:

NET"a"LOC="P11";//SW0

NET"b"LOC="L3";//SW1

NET"c"LOC="K3";//SW2

NET"d"LOC="B4";//SW3

NET"y"LOC="M5";//LD0

 

仿真文件:

moduleexp1-1test;

//Inputs

rega;

regb;

regc;

regd;

//Outputs

wirey;

//InstantiatetheUnitUnderTest(UUT)

exp1-1uut(

.a(a),

.b(b),

.c(c),

.d(d),

.y(y)

);

initialbegin

//InitializeInputs

a=0;

b=0;

c=0;

d=0;

//Wait100nsforglobalresettofinish

#100;

//Addstimulushere

a=0;

b=0;

c=0;

d=1;

#100;

a=0;

b=0;

c=1;

d=0;

#100;

a=0;

b=0;

c=1;

d=1;

#100;

a=0;

b=1;

c=0;

d=0;

#100;

a=0;

b=1;

c=0;

d=1;

#100;

a=0;

b=1;

c=1;

d=0;

#100;

a=0;

b=1;

c=1;

d=1;

#100;

a=1;

b=0;

c=0;

d=0;

#100;

end

endmodule

仿真波形:

2)第二题

源文件:

modulemux41a(

inputwirea,

inputwireb,

inputwirec,

inputwired,

inputwire[1:

0]s,

outputwirey

);

assigny=~s[1]&~s[0]&a

|~s[1]&s[0]&b

|s[1]&~s[0]&c

|s[1]&s[0]&d;

 

Endmodule

约束文件:

NET"a"LOC="P11";

NET"b"LOC="L3";

NET"c"LOC="K3";

NET"d"LOC="B4";

NET"s[0]"LOC="G3";

NET"s[1]"LOC="F3";

NET"y"LOC="M5";

仿真文件:

modulemux41atest;

//Inputs

rega;

regb;

regc;

regd;

reg[1:

0]s;

//Outputs

wirey;

//InstantiatetheUnitUnderTest(UUT)

mux41auut(

.a(a),

.b(b),

.c(c),

.d(d),

.s(s),

.y(y)

);

initialbegin

//InitializeInputs

a=0;

b=0;

c=0;

d=0;

s=0;

//Wait100nsforglobalresettofinish

#100;

//Addstimulushere

a<=0;

b<=0;

c<=1;

d<=0;

s[0]<=0;

s[1]<=1;

#100;

end

endmodule

仿真波形:

3)第三题

源文件:

modulex7heg(

inputwire[7:

0]x,

inputwireclk,

inputwireclr,

outputreg[6:

0]a_to_g,

outputreg[3:

0]an

);

wire[1:

0]s;

reg[3:

0]digit;

reg[19:

0]clkdiv;

assigns=clkdiv[19:

18];

always@(*)

case(s)

0:

if(x[3:

0]>=4'b1010)

digit=x[3:

0]-4'b1010;

else

digit=x[3:

0];

1:

if(x[3:

0]>=4'b1010)

digit=4'b0001;

else

digit=4'b0000;

2:

if(x[7:

4]>=4'b1010)

digit=x[7:

4]-4'b1010;

else

digit=x[7:

4];

3:

if(x[7:

4]>=4'b1010)

digit=4'b0001;

else

digit=4'b0000;

default:

digit=4'b0000;

endcase

always@(*)

case(digit)

0:

a_to_g=7'b0000001;

1:

a_to_g=7'b1001111;

2:

a_to_g=7'b0010010;

3:

a_to_g=7'b0000110;

4:

a_to_g=7'b1001100;

5:

a_to_g=7'b0100100;

6:

a_to_g=7'b0100000;

7:

a_to_g=7'b0001111;

8:

a_to_g=7'b0000000;

9:

a_to_g=7'b0000100;

'hA:

a_to_g=7'b0001000;

'hB:

a_to_g=7'b1100000;

'hC:

a_to_g=7'b0110001;

'hD:

a_to_g=7'b1000010;

'hE:

a_to_g=7'b0110000;

'hF:

a_to_g=7'b0111000;

default:

a_to_g=7'b0000001;

endcase

always@(*)

begin

an=4'b1111;

an[s]=0;

end

always@(posedgeclkorposedgeclr)

begin

if(clr==1)

clkdiv<=0;

else

clkdiv<=clkdiv+1;

end

endmodule

约束文件:

NET"a_to_g[0]"LOC=M12;

NET"a_to_g[1]"LOC=L13;

NET"a_to_g[2]"LOC=P12;

NET"a_to_g[3]"LOC=N11;

NET"a_to_g[4]"LOC=N14;

NET"a_to_g[5]"LOC=H12;

NET"a_to_g[6]"LOC=L14;

NET"an[3]"LOC=K14;

NET"an[2]"LOC=M13;

NET"an[1]"LOC=J12;

NET"an[0]"LOC=F12;

NET"clk"LOC=B8;

NET"clr"LOC=G12;

NET"x[7]"LOC=N3;

NET"x[6]"LOC=E2;

NET"x[5]"LOC=F3;

NET"x[4]"LOC=G3;

NET"x[3]"LOC=B4;

NET"x[2]"LOC=K3;

NET"x[1]"LOC=L3;

NET"x[0]"LOC=P11;

4)第四题

源文件:

moduleadder4a(

inputwire[3:

0]a,

inputwire[3:

0]b,

outputwire[3:

0]s,

outputwirec4

);

wire[4:

0]c;

assignc[0]=0;

assigns=a^b^c[3:

0];

assignc[4:

1]=a&b|c[3:

0]&(a^b);

assignc4=c[4];

endmodule

约束文件:

NET"a[0]"LOC=P11;

NET"a[1]"LOC=L3;

NET"a[2]"LOC=K3;

NET"a[3]"LOC=B4;

NET"b[0]"LOC=G3;

NET"b[1]"LOC=F3;

NET"b[2]"LOC=E2;

NET"b[3]"LOC=N3;

NET"c4"LOC=G1;

NET"s[0]"LOC=P4;

NET"s[1]"LOC=N4;

NET"s[2]"LOC=N5;

NET"s[3]"LOC=P6;

2.时序逻辑电路实验

1)第一题

源文件:

modulemod10(

inputclk,clr,

outputreg[6:

0]a_to_g,

outputwire[3:

0]an,

outputreg[3:

0]q

);

assignan=4'b1110;//最右译码管使能

reg[26:

0]counter;//时钟分频,默认时钟为50MHZ,分频为1HZalways@(posedgeclk)

if(counter==25000000)

counter<=0;//达到一半时计数归零

else

counter<=counter+1;

regclk_div;//引入新的电平

always@(posedgeclk)

if(counter==25000000)clk_div<=~clk_div;

always@(posedgeclk_divorposedgeclr)

begin

if(clr==1)

q<=0;

elseif(q==9)

q<=0;

else

q<=q+1;

end

always@(*)

case(q)

0:

a_to_g=7'b0000001;

1:

a_to_g=7'b1001111;

2:

a_to_g=7'b0010010;

3:

a_to_g=7'b0000110;

4:

a_to_g=7'b1001100;

5:

a_to_g=7'b0100100;

6:

a_to_g=7'b0100000;

7:

a_to_g=7'b0001111;

8:

a_to_g=7'b0000000;

9:

a_to_g=7'b0001100;

default:

a_to_g=7'b0000001;

endcase

endmodule

约束文件:

NET"q[0]"LOC="G1";

NET"a_to_g[0]"LOC="M12";

NET"a_to_g[1]"LOC="L13";

NET"a_to_g[2]"LOC="P12";

NET"a_to_g[3]"LOC="N11";

NET"a_to_g[4]"LOC="N14";

NET"a_to_g[5]"LOC="H12";

NET"a_to_g[6]"LOC="L14";

NET"an[3]"LOC="K14";

NET"an[2]"LOC="M13";

NET"an[1]"LOC="J12";

NET"an[0]"LOC="F12";

NET"clk"LOC="B8";

NET"clr"LOC="G12";

 

2)第二题

源文件:

moduleregf(

clr,clk,d,load,q

);

inputwireclk;

inputwireclr;

inputwireload;

input[3:

0]d;

output[3:

0]q;

reg[3:

0]q;

always@(posedgeclkorposedgeclr)

begin

if(clr==1)

q<=0;//异步清零

elseif(!

clr&&load)

begin

q[0]<=1;

q[1]<=1;

q[2]<=1;

q[3]<=1;

end//同步置数

else

q<=d;

end

endmodule

约束文件:

NET"clk"LOC="B8";

NET"clr"LOC="P11";

NET"load"LOC="L3";

NET"q[3]"LOC="G1";

NET"q[2]"LOC="P4";

NET"q[1]"LOC="N4";

NET"q[0]"LOC="N5";

NET"d[3]"LOC="G3";

NET"d[2]"LOC="F3";

NET"d[1]"LOC="E2";

NET"d[0]"LOC="N3";

仿真文件:

moduleregftest;

//Inputs

regclr;

regclk;

reg[3:

0]d;

regload;

//Outputs

wire[3:

0]q;

//InstantiatetheUnitUnderTest(UUT)

regfuut(

.clr(clr),

.clk(clk),

.d(d),

.load(load),

.q(q)

);

initialbegin

//InitializeInputs

clr=0;

clk=0;

d=0;

load=0;

//Wait100nsforglobalresettofinish

#100;

//Addstimulushere

clr=1;#200;

clr=0;clk=1;d=0100;#200;

clr=0;clk=0;d=1100;#200;

clr=0;clk=1;d=1001;#200;

clr=0;clk=0;d=0011;#200;

clr=0;clk=1;d=0000;#200;

clr=0;clk=0;d=0010;#200;

clk=1;

load=1;

end

endmodule

仿真结果:

3.HDL综合实验(数字钟)

源文件:

moduleclock(

inputclk,

inputclr,

inputhourup,

inputminuteup,

outputreg[6:

0]a,

outputregled,

outputreg[3:

0]enable

);

reg[3:

0]digit;

reg[19:

0]clkdiv;

reg[27:

0]divide;

regq1;

reg[5:

0]second;

regq2;

reg[5:

0]minute;

regq3;

reg[4:

0]hour;

regh;

regm;

always@(posedgeclkorposedgehourup)

begin

h<=0;

if(hourup)

begin

if

(1)

h<=1;

else

h<=0;

end

end

always@(posedgeclkorposedgeminuteup)

begin

m<=0;

if(minuteup)

begin

if

(1)

m<=1;

else

m<=0;

end

end

always@(posedgeclk)

begin

clkdiv<=clkdiv+1;

end

always@(*)

begin

enable=4'b1111;

enable[clkdiv[19:

18]]=0;

if(clr)

enable=4'b1111;

end

always@(*)

case(clkdiv[19:

18])

0:

begin

if(minute>=0&&minute<10)

digit=minute;

elseif(minute>=10&&minute<20)

digit=minute-10;

elseif(minute>=20&&minute<30)

digit=minute-20;

elseif(minute>=30&&minute<40)

digit=minute-30;

elseif(minute>=40&&minute<50)

digit=minute-40;

else

digit=minute-50;

end

1:

begin

if(minute>=0&&minute<10)

digit=0;

elseif(minute>=10&&minute<20)

digit=1;

elseif(minute>=20&&minute<30)

digit=2;

elseif(minute>=30&&minute<40)

digit=3;

elseif(minute>=40&&minute<50)

digit=4;

else

digit=5;

end

2:

begin

if(hour>=0&&hour<10)

digit=hour;

elseif(hour>=10&&hour<20)

digit=hour-10;

elseif(hour>=20&&hour<30)

digit=hour-20;

elseif(hour>=30&&hour<40)

digit=hour-30;

elseif(hour>=40&&hour<50)

digit=hour-40;

else

digit=hour-50;

end

3:

begin

if(hour>=0&&hour<10)

digit=0;

elseif(hour>=10&&hour<20)

digit=1;

else

digit=2;

end

default:

digit=0;

endcase

always@(*)

case(digit)

0:

a=7'b0000001;

1:

a=7'b1001111;

2:

a=7'b0010010;

3:

a=7'b0000110;

4:

a=7'b1001100;

5:

a=7'b0100100;

6:

a=7'b0100000;

7:

a=7'b0001111;

8:

a=7'b0000000;

9:

a=7'b0000100;

default:

a=7'b0000001;

endcase

always@(posedgeclk)

begin

if(divide<25000000)

begin

divide<=divide+1;

q1<=0;

end

else

begin

divide<=0;

q1<=1;

end

end

always@(posedgeq1)

begin

if(led)

led<=0;

else

led<=1;

end

always@(posedgeled)

begin

if(second<59)

begin

second<=second+1;

q2<=0;

end

else

begin

second<=0;

q2<=1;

end

end

assignq4=q2+m;

always@(posedgeq4)

begin

if(minute<59)

begin

minute<=minute+1;

q3<=0;

end

else

begin

minute<=0;

q3<=1;

end

end

assignq5=q3+h;

always@(posedgeq5)

begin

if(hour<23)

hour<=hour+1;

else

hour<=0;

end

endmodule

约束文件

NET"a[0]"LOC="M12";

NET"a[1]"LOC="L13";

NET"a[2]"LOC="P12";

NET"a[3]"LOC="N11";

NET"a[4]"LOC="N14";

NET"a[5]"LOC="H12";

NET"a[6]"LOC="L14";

NET"enable[3]"LOC="K14";

NET"enable[2]"LOC="M13";

NET"enable[1]"LOC="J12";

NET"enable[0]"LOC="F12";

NET"clk"LOC="B8";

NET"hourup"LOC="M4";

NET"minuteup"LOC="G12";

NET"led"LOC="M5";

NET"clr"LOC="L3";

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 职业规划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1