北航电子电路设计数字部分实验报告.docx

上传人:b****6 文档编号:3640018 上传时间:2022-11-24 格式:DOCX 页数:35 大小:712.81KB
下载 相关 举报
北航电子电路设计数字部分实验报告.docx_第1页
第1页 / 共35页
北航电子电路设计数字部分实验报告.docx_第2页
第2页 / 共35页
北航电子电路设计数字部分实验报告.docx_第3页
第3页 / 共35页
北航电子电路设计数字部分实验报告.docx_第4页
第4页 / 共35页
北航电子电路设计数字部分实验报告.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

北航电子电路设计数字部分实验报告.docx

《北航电子电路设计数字部分实验报告.docx》由会员分享,可在线阅读,更多相关《北航电子电路设计数字部分实验报告.docx(35页珍藏版)》请在冰豆网上搜索。

北航电子电路设计数字部分实验报告.docx

北航电子电路设计数字部分实验报告

电子电路设计数字部分实验报告

 

学院:

姓  名:

实验一简单组合逻辑设计

实验内容

描述一个可综合的数据比较器,比较数据a、b的大小,若相同,则给出结果1,否则给出结果0。

实验仿真结果

实验代码

主程序

modulecompare(equal,a,b);

input[7:

0]a,b;

outputequal;

assignequal=(a>b)?

1:

0;

endmodule

测试程序

modulet;

reg[7:

0]a,b;

regclock,k;

wireequal;

initial

begin

a=0;

b=0;

clock=0;

k=0;

end

always#50clock=~clock;

always@(posedgeclock)

begin

a[0]={$random}%2;

a[1]={$random}%2;

a[2]={$random}%2;

a[3]={$random}%2;

a[4]={$random}%2;

a[5]={$random}%2;

a[6]={$random}%2;

a[7]={$random}%2;

b[0]={$random}%2;

b[1]={$random}%2;

b[2]={$random}%2;

b[3]={$random}%2;

b[4]={$random}%2;

b[5]={$random}%2;

b[6]={$random}%2;

b[7]={$random}%2;

end

initial

begin#100000$stop;end

comparem(.equal(equal),.a(a),.b(b));

endmodule

实验二简单分频时序逻辑电路的设计

实验内容

用always块和@(posedgeclk)或@(negedgeclk)的结构表述一个1/2分频器的可综合模型,观察时序仿真结果。

实验仿真结果

实验代码

主程序

modulehalf_clk(reset,clk_in,clk_out);

inputclk_in,reset;

outputclk_out;

regclk_out;

always@(negedgeclk_in)

begin

if(!

reset)

clk_out=0;

else

clk_out=~clk_out;

end

endmodule

测试程序

`timescale1ns/100ps

`defineclk_cycle50

moduletop;

regclk,reset;

wireclk_out;

always#`clk_cycleclk=~clk;

initial

begin

clk=0;

reset=1;

#10reset=0;

#110reset=1;

#100000$stop;

end

half_clkm0(.reset(reset),.clk_in(clk),.clk_out(clk_out));

endmodule

实验三利用条件语句实现计数分频时序电路

实验内容

利用10MHz的时钟,设计一个单周期形状的周期波形。

实验仿真结果

实验代码

主程序

modulefdivision(RESET,F10M,out);

inputF10M,RESET;

outputout;

regout;

reg[7:

0]i;

always@(posedgeF10M)

if(!

RESET)

begin

out<=0;

i<=0;

end

elseif(i==2||i==3)

begin

out=~out;

i<=i+1;

end

elseif(i==5)

i<=1;

else

i<=i+1;

endmodule

测试程序

`timescale1ns/100ps

moduledivision_top;

regF10M,RESET;

wireout;

always#50F10M=~F10M;

initial

begin

RESET=1;

F10M=0;

#90RESET=0;

#100RESET=1;

#10000$stop;

end

fdivisionfdivision(.RESET(RESET),.F10M(F10M),.out(out));

endmodule

实验四阻塞赋值与非阻塞赋值的区别

实验内容

比较四种不同的写法,观察阻塞与非阻塞赋值的区别。

Blocking:

always@(posedgeclk)

begin

b=a;

c=b;

end

Blocking1:

always@(posedgeclk)

begin

c=b;

b=a;

end

Blocking2:

always@(posedgeclk)b=a;

always@(posedgeclk)c=b;

non_Blocking:

always@(posedgeclk)

begin

b<=a;

c<=b;

End

实验仿真结果

实验代码

主程序

moduleblocking(clk,a,b,c);

output[3:

0]b,c;

input[3:

0]a;

inputclk;

reg[3:

0]b,c;

always@(posedgeclk)

begin

b=a;

c=b;

end

endmodule

测试部分

`timescale1ns/100ps

`include"./blocking.v"

`include"./blocking1.v"

`include"./blocking2.v"

`include"./non_blocking.v"

modulecompareTop;

wire[3:

0]b11,c11,b12,c12,b13,c13,b2,c2;

reg[3:

0]a;

regclk;

initial

begin

clk=0;

forever#50clk=~clk;

end

initial

begin

a=4'h3;

$display("%d",a);

#100a=4'h7;

$display("%d",a);

#100a=4'hf;

$display("%d",a);

#100a=4'ha;

$display("%d",a);

#100a=4'h2;

$display("%d",a);

#100$stop;

end

blockingblocking(clk,a,b11,c11);

blocking1blocking1(clk,a,b12,c12);

blocking2blocking2(clk,a,b13,c13);

non_blockingnon_blocking(clk,a,b2,c2);

endmodule

实验五用always块实现较复杂的组合逻辑

实验目的

运用always块设计一个8路数据选择器。

要求:

每路输入数据与输出数据均为4位2进制数,当选择开关(至少3位)或输入数据发生变化时,输出数据也相应地变化。

实验仿真结果

实验代码

主程序

modulealu(out,opcode,a1,a2,a3,a4,a5,a6,a7,a8);

output[3:

0]out;

reg[3:

0]out;

input[3:

0]a0,a1,a2,a3,a4,a5,a6,a7;

input[2:

0]opcode;

always@(opcodeora1ora2ora3ora4ora5ora6ora7ora0)

begin

case(opcode)

3'd0:

out=a0;

3'd1:

out=a1;

3'd2:

out=a2;

3'd3:

out=a3;

3'd4:

out=a4;

3'd5:

out=a5;

3'd6:

out=a6;

3'd7:

out=a7;

default:

out=4'b0000;

endcase

end

endmodule

测试程序

`timescale1ns/1ns

`include"./main5.v"

modulealutext;

wire[3:

0]out;

reg[3:

0]a1,a2,a3,a4,a5,a6,a7,a8;

reg[2:

0]opcode;

initial

begin

a1={$random}%16;

a2={$random}%16;

a3={$random}%16;

a4={$random}%16;

a5={$random}%16;

a6={$random}%16;

a7={$random}%16;

a8={$random}%16;

repeat(100)

begin

#100opcode={$random}%8;

a1={$random}%16;

a2={$random}%16;

a3={$random}%16;

a4={$random}%16;

a5={$random}%16;

a6={$random}%16;

a7={$random}%16;

a8={$random}%16;

end

#100$stop;

end

alualu(out,opcode,a1,a2,a3,a4,a5,a6,a7,a8);

endmodule

实验六在VerilogHDL中使用函数

实验目的

设计一个带控制端的逻辑运算电路,分别完成正整数的平方、立方和最大数为5的阶乘运算。

实验仿真结果

实验代码

主程序

moduletryfunct(clk,n,result1,result2,result3,reset);

output[31:

0]result1,result2,result3;

input[3:

0]n;

inputreset,clk;

reg[31:

0]result1,result2,result3;

always@(posedgeclk)

begin

if(!

reset)

begin

result1<=0;

result2<=0;

result3<=0;

end

else

begin

result1<=fun1(n);

result2<=fun2(n);

result3<=fun3(n);

end

end

function[31:

0]fun1;

input[3:

0]operand;

fun1=operand*operand;

endfunction

function[31:

0]fun2;

input[3:

0]operand;

begin

fun2=operand*operand;

fun2=operand*fun2;

end

endfunction

function[31:

0]fun3;

input[3:

0]operand;

reg[3:

0]index;

begin

fun3=1;

if(operand<11)

for(index=2;index<=operand;index=index+1)

fun3=index*fun3;

else

for(index=2;index<=10;index=index+1)

fun3=index*fun3;

end

endfunction

endmodule

测试程序

`include"./main6.v"

`timescale1ns/100ps

moduletryfunctTop;

reg[3:

0]n,i;

regreset,clk;

wire[31:

0]result1,result2,result3;

initial

begin

clk=0;

n=0;

reset=1;

#100reset=0;

#100reset=1;

for(i=0;i<=15;i=i+1)

begin

#200n=i;

end

#100$stop;

end

always#50clk=~clk;

tryfunctm(.clk(clk),.n(n),.result1(result1),.result2(result2),.result3(result3),.reset(reset));

endmodule

实验七在VerilogHDL中使用任务(task)

实验目的

用两种不同方法设计一个功能相同的模块,该模块能完成四个8位2进制输入数据的冒泡排序。

第一种,模仿原题例子中用纯组合逻辑实现;第二种,假设8位数据是按照时钟节拍串行输入的,要求用时钟触发任务的执行法,每个时钟周期完成一次数据交换操作。

实验仿真结果

实验代码

主程序1

modulerank(ra,rb,rc,rd,a,b,c,d);

output[7:

0]ra,rb,rc,rd;

input[7:

0]a,b,c,d;

reg[7:

0]ra,rb,rc,rd,va,vb,vc,vd,tmp;

regi;

always@(aorborcord)

begin

{va,vb,vc,vd}={a,b,c,d};

repeat(7)

begin

exchange(va,vb);

exchange(vb,vc);

exchange(vc,vd);

end

{ra,rb,rc,rd}={va,vb,vc,vd};

end

taskexchange;

inout[7:

0]x,y;

reg[7:

0]tmp;

if(x>y)

begin

tmp=x;

x=y;

y=tmp;

end

endtask

endmodule

测试部分1

`timescale1ns/100ps

`include"main7.v"

moduletask_Top;

reg[7:

0]a,b,c,d;

wire[7:

0]ra,rb,rc,rd;

initial

begin

a=0;b=0;c=0;d=0;

repeat(50)

begin

#100a={$random}%255;

b={$random}%255;

c={$random}%255;

d={$random}%255;

end

#100$stop;

end

rankrank(.ra(ra),.rb(rb),.rc(rc),.rd(rd),.a(a),.b(b),.c(c),.d(d));

endmodule

主程序2

modulerank(a,rst,clk,ra,rb,rc,rd);

output[7:

0]ra,rb,rc,rd;

input[7:

0]a;

inputclk,rst;

reg[7:

0]ra,rb,rc,rd;

reg[7:

0]va,vb,vc,vd;

reg[3:

0]i;

always@(posedgeclkornegedgeclk)

begin

if(!

rst)

begin

va=0;

vb=0;

vc=0;

vd=0;

i=0;

end

else

begin

if(i<8)

begin

i=i+1;

va=a;

exchange(va,vb);

exchange(vb,vc);

exchange(vc,vd);

exchange(va,vb);

exchange(vb,vc);

exchange(va,vb);

{ra,rb,rc,rd}={va,vb,vc,vd};

end

end

end

taskexchange;

inout[7:

0]x,y;

reg[7:

0]tmp;

if(x>y)

begin

tmp=x;

x=y;

y=tmp;

end

endtask

endmodule

测试部分2

`timescale1ns/100ps

`include"main7_other.v"

moduletask_Top;

reg[7:

0]a;

wire[7:

0]ra,rb,rc,rd;

regclk,rst;

initial

begin

a=0;

rst=0;

clk=0;

#50rst=1;

#100a={8{$random}};

#100a={8{$random}};

#100a={8{$random}};

#100a={8{$random}};

#100a={8{$random}};

#100a={8{$random}};

#100a={8{$random}};

#100a={8{$random}};

#100$stop;

end

always#100clk=~clk;

rankrank(.a(a),.rst(rst),.clk(clk),.ra(ra),.rb(rb),.rc(rc),.rd(rd));

endmodule

实验八利用有限状态机进行时序逻辑的设计

实验目的

设计一个串行数据检测器。

要求连续四个或四个以上为1时输出1,其他输入情况下为0.

实验仿真结果

实验代码

主程序

moduleseqdet(x,z,clk,rst,state);

inputx,clk,rst;

outputz;

output[2:

0]state;

reg[2:

0]state;

wirez;

parameterIDLE='d0,A='d1,B='d2,C='d3,D='d4;

assignz=(state==D&&x==1)?

1:

0;

always@(posedgeclk)

if(!

rst)

begin

state<=IDLE;

end

else

casex(state)

IDLE:

if(x==1)

begin

state<=A;

end

A:

if(x==1)

begin

state<=B;

end

else

begin

state<=IDLE;

end

B:

if(x==1)

begin

state<=C;

end

else

begin

state<=IDLE;

end

C:

if(x==1)

begin

state<=D;

end

else

begin

state<=IDLE;

end

D:

if(x==1)

begin

state<=D;

end

else

begin

state<=IDLE;

end

default:

state=IDLE;

endcase

endmodule

测试代码

`include"main8.v"

moduleseqdet_Top;

regclk,rst;

reg[23:

0]data;

wire[2:

0]state;

wirez,x;

assignx=data[23];

always#10clk=~clk;

always@(posedgeclk)

data={data[22:

0],data[23]};

initial

begin

clk=0;

rst=1;

#2rst=0;

#30rst=1;

data='b1001_1111_0111_1110;

#500$stop;

end

seqdetm(x,z,clk,rst,state);

endmodule

实验九楼梯灯

实验目的

Ø楼下到楼上依次有3个感应灯:

灯1、灯2、灯3。

当行人上下楼梯时,各个灯感应到后自动点亮,若在8s内感应信号消失,则点亮8s,若感应信号存在时间超过8s,则感应信号消失4s后灯自动关闭。

Ø任务1:

做出如上逻辑电路设计并仿真;

Ø任务2:

考虑去抖情况,对于感应信号到达存在毛刺(小于0.5s),设计合适逻辑并剔出。

任务3:

若为节约能源,下一个灯点亮的同时将自动关闭上一个灯,做出如上逻辑设计并仿真(仅考虑一个人的情况)

实验仿真结果

实验代码

主程序

modulelight_All(clk10,rst,switch,light);

inputclk10,rst;

input[2:

0]switch;

output[2:

0]light;

reg[2:

0]state1,state2,state3;

reg[7:

0]count1,count2,count3;

reg[2:

0]count_1,count_2,count_3;

reg[2:

0]light;

parameter

state1_start=3'b000,state2_start=3'b000,state3_start=3'b000,

state1_work=3'b001,state2_work=3'b001,state3_work=3'b001,

state1_up=3'b010,state2_up=3'b010,state3_up=3'b010,

state1_down=3'b011,state2_down=3'b011,state3_down=3'b011,

state1_other=3'b100,state2_other=3'b100,state3_other=3'b100;

always@(posedgeclk10)

if(!

rst)

begin

state1<=state1_start;

count1<=8'b0;

count_1<=3'b0;

end

else

if(switch[0]=='b1&&count_1<4)

count_1<=count_1+1;

else

case(state1)

state1_start:

if(switch[0]=='b1)

begin

state1<=state1_up;

count1<=78;

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

当前位置:首页 > 高中教育 > 语文

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

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