verilog编写的基本电路逻辑及仿真.docx

上传人:b****7 文档编号:16706324 上传时间:2023-07-16 格式:DOCX 页数:24 大小:133.08KB
下载 相关 举报
verilog编写的基本电路逻辑及仿真.docx_第1页
第1页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第2页
第2页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第3页
第3页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第4页
第4页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第5页
第5页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第6页
第6页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第7页
第7页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第8页
第8页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第9页
第9页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第10页
第10页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第11页
第11页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第12页
第12页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第13页
第13页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第14页
第14页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第15页
第15页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第16页
第16页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第17页
第17页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第18页
第18页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第19页
第19页 / 共24页
verilog编写的基本电路逻辑及仿真.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

verilog编写的基本电路逻辑及仿真.docx

《verilog编写的基本电路逻辑及仿真.docx》由会员分享,可在线阅读,更多相关《verilog编写的基本电路逻辑及仿真.docx(24页珍藏版)》请在冰点文库上搜索。

verilog编写的基本电路逻辑及仿真.docx

verilog编写的基本电路逻辑及仿真

 

集成电路与Verilog语言

 

 

实验1:

分别用门级建模、数据流级建模、和行为级建模实现一个2选1的MUX,两个输入端分别为A和B,当选择端SEL=0时,输出F选择A;当选择端SEL=1时,输出F选择B。

门级建模:

源代码:

//MUX2to1gatelevel

moduleMUX_gate(a,b,sel,f);

inputa;

inputb;

inputsel;

outputf;

regf;

wirensel,y1,y2;

notunot(nsel,sel);

andu1and(y1,a,nsel);

andu2and(y2,b,sel);

oruor(f,y1,y2);

endmodule

综合结果:

TB代码:

moduletb_MUX_gate;

//Inputs

rega;

regb;

regsel;

//Outputs

wiref;

//InstantiatetheUnitUnderTest(UUT)

MUX_gateuut(

.a(a),

.b(b),

.sel(sel),

.f(f)

);

initialbegin

//InitializeInputs

a=0;

b=0;

sel=0;

//Wait100nsforglobalresettofinish

#10

//Addstimulushere

a=1;

b=0;

sel=0;

#10;

a=1;

b=0;

sel=1;

#10;

#10$finish;

end

endmodule

仿真结果:

数据流级建模:

源代码:

//MUX2to1datapro

moduleMUX_datapro(a,b,sel,f);

inputa;

inputb;

inputsel;

outputf;

regf;

wirensel,y1,y2;

assignnsel=~sel;

assigny1=a&nsel;

assigny2=b&sel;

assignf=y1|y2;

endmodule

综合结果:

TB代码:

moduletb_MUX_datarpro;

//Inputs

rega;

regb;

regsel;

//Outputs

wiref;

//InstantiatetheUnitUnderTest(UUT)

MUX_dataprouut(

.a(a),

.b(b),

.sel(sel),

.f(f)

);

initialbegin

//InitializeInputs

a=0;

b=0;

sel=0;

//Wait100nsforglobalresettofinish

#10;

//Addstimulushere

a=1;

b=0;

sel=0;

#10;

a=1;

b=0;

sel=1;

#10;

#10$finish;

en

endmodule

 

仿真结果:

行为级建模:

源代码:

//MUX2to1behav

moduleMUX_behav(f,a,b,sel);

inputa,b,sel;

outputf;

regf;

regy1,y2,nsel;

always@(aorborsel)

begin

nsel<=~sel;

y1<=a&nsel;

y2<=b&sel;

f<=y1|y2;

end

endmodule

综合结果:

TB代码:

moduletb_MUX_behav;

//Inputs

rega;

regb;

regsel;

//Outputs

wiref;

//InstantiatetheUnitUnderTest(UUT)

MUX_behavuut(

.a(a),

.b(b),

.sel(sel),

.f(f)

);

initialbegin

//InitializeInputs

a=0;

b=0;

sel=0;

//Wait100nsforglobalresettofinish

#10;

//Addstimulushere

a=1;

b=0;

sel=0;

#10;

a=1;

b=0;

sel=1;

#10;

#10$finish;

end

endmodule

仿真结果:

 

实验2题目:

实现一个计数器,计数时计数器可从0计到10。

源代码:

modulecounter(din,up1_down0,clk,nrst,sta1_pau0,load,counter);

input[3:

0]din;

inputup1_down0;

inputclk;

inputnrst;

inputsta1_pau0;

inputload;

output[3:

0]counter;

reg[3:

0]counter;

always@(posedgeclkornegedgenrst)

begin

if(~nrst)

counter<=4'b0000;

elseif(load)

counter<=din;

else

begin

if(~sta1_pau0)

counter<=counter;

else

if(up1_down0)

if(counter==10)

counter<=4'b0000;

else

counter<=counter+1;

else

if(counter==0)

counter<=4'b1010;

else

counter<=counter-1;

end

end

endmodule

综合结果:

TB代码:

moduletb2;

//Inputs

reg[3:

0]din;

regup1_down0;

regclk;

regnrst;

regsta1_pau0;

regload;

//Outputs

wire[3:

0]counter;

//InstantiatetheUnitUnderTest(UUT)

counteruut(

.din(din),

.up1_down0(up1_down0),

.clk(clk),

.nrst(nrst),

.sta1_pau0(sta1_pau0),

.load(load),

.counter(counter)

);

initial

clk=1'b0;

always

#5clk=~clk;

initialbegin

//InitializeInputs

din=0;

up1_down0=0;

nrst=0;

sta1_pau0=0;

load=0;

//Wait100nsforglobalresettofinish

#50;

//Addstimulushere

//从0开始加计数

din=4'b0111;

nrst=1;

up1_down0=1;

sta1_pau0=1;

#210;

//暂停

sta1_pau0=0;

#20;

//从7开始减计数

load=1;

#10;

load=0;

sta1_pau0=1;

up1_down0=0;

#200;

#20$finish;

end

endmodule

仿真结果:

 

实验3题目:

由Morre状态机设计一个简单的交通灯,假定红灯时间为9个时间单位,绿灯时间为6个时间单位,黄灯时间为3个时间单位。

源代码:

modulelight_machine(clk,nrst,y,t);

inputclk;

inputnrst;

output[1:

0]y;

output[3:

0]t;

reg[3:

0]q;

reg[1:

0]y;

reg[1:

0]state;

reg[3:

0]t;

parametergreen=2'b00,yellow=2'b01,red=2'b11;

initial

begin

q<=4'b0;

t<=4'b0;

end

always@(posedgeclkornegedgenrst)

begin

if(!

nrst)

begin

state<=green;

y<=2'bz;

end

else

case(state)

green:

begin

q<=q+1;

t<=q;

if(q==5)

begin

q<=4'b0;

state<=yellow;

end

else

begin

y<=2'b00;

state<=green;

end

end

yellow:

begin

q<=q+1;

t<=q;

if(q==2)

begin

q<=4'b0;

state<=red;

end

else

begin

y<=2'b01;

state<=yellow;

end

end

red:

begin

q<=q+1;

t<=q;

if(q==8)

begin

q<=4'b0;

state<=green;

end

else

begin

y<=2'b11;

state<=red;

end

end

endcase

end

endmodule

综合结果:

TB代码:

moduletb_2;

//Inputs

regclk;

regnrst;

//Outputs

wire[1:

0]y;

wire[3:

0]t;

//InstantiatetheUnitUnderTest(UUT)

light_machineuut(

.clk(clk),

.nrst(nrst),

.y(y),

.t(t)

);

initial

clk=1'b0;

always

#5clk=~clk;

initialbegin

//InitializeInputs

nrst=0;

//Wait100nsforglobalresettofinish

#30;

//Addstimulushere

nrst=1;

#500;

#20$finish;

end

endmodule

仿真结果:

实验4题目:

对一个400MHz的时钟分别完成2、4、8分频。

源代码:

moduledivclk(clkin,nrst,din,clkout);

inputclkin;

inputnrst;

input[1:

0]din;

outputclkout;

reg[28:

0]q;

regclkout;

initial

begin

q<=29'b0;

end

always@(posedgeclkinornegedgenrst)

begin

if(~nrst)

q<=29'b0;

else

q<=q+29'b1;

end

always@(posedgeclkin)

begin

case(din)

2'b00:

clkout<=q[0];

2'b01:

clkout<=q[1];

2'b10:

clkout<=q[2];

default:

clkout<=1'bz;

endcase

end

endmodule

综合结果:

TB文件:

moduletb_div;

//Inputs

regclkin;

regnrst;

reg[1:

0]din;

//Outputs

wireclkout;

//InstantiatetheUnitUnderTest(UUT)

divclkuut(

.clkin(clkin),

.nrst(nrst),

.din(din),

.clkout(clkout)

);

initialclkin=1'b0;

always

#1.25clkin=~clkin;

initialbegin

//InitializeInputs

nrst=0;

din=2'b11;

//Wait100nsforglobalresettofinish

#50;

//Addstimulushere

nrst=1;

din=2'b00;

#50;

din=2'b01;

#50;

din=2'b10;

#50;

din=2'b11;

#50;

#20$finish;

end

endmodule

仿真结果:

实验5题目:

按照病情严重程度将8名病人分配到8个病房,1号病房病情最轻,8号病房病人病情最严重。

每个病房有一个按钮用于呼叫医生,在医生办公室有个显示屏,用于显示哪个病房按了按钮。

由于病情不同,要求当病情较严重的病房按了按钮后,医生办公室的显示屏要优先显示其病房号。

源代码:

modulepriority_encoder(clk,I0,I1,I2,I3,I4,I5,I6,I7,Y);

inputclk;

inputI0;

inputI1;

inputI2;

inputI3;

inputI4;

inputI5;

inputI6;

inputI7;

output[2:

0]Y;

reg[2:

0]Y;

always@(posedgeclk)

begin

if(I7)

Y<=3'b111;

elseif(I6)

Y<=3'b110;

elseif(I5)

Y<=3'b101;

elseif(I4)

Y<=3'b100;

elseif(I3)

Y<=3'b011;

elseif(I2)

Y<=3'b010;

elseif(I1)

Y<=3'b001;

elseif(I0)

Y<=3'b000;

else

Y<=3'bz;

end

endmodule

综合结果:

TB文件:

moduletb2;

//Inputs

regclk;

regI0;

regI1;

regI2;

regI3;

regI4;

regI5;

regI6;

regI7;

//Outputs

wire[2:

0]Y;

//InstantiatetheUnitUnderTest(UUT)

priority_encoderuut(

.clk(clk),

.I0(I0),

.I1(I1),

.I2(I2),

.I3(I3),

.I4(I4),

.I5(I5),

.I6(I6),

.I7(I7),

.Y(Y)

);

initial

clk=1'b0;

always

#2clk=~clk;

initialbegin

//InitializeInputs

I0=0;

I1=0;

I2=0;

I3=0;

I4=0;

I5=0;

I6=0;

I7=0;

//Wait100nsforglobalresettofinish

#10;

//Addstimulushere

{I7,I6,I5,I4,I3,I2,I1,I0}<=8'b1110_1101;

#10;

{I7,I6,I5,I4,I3,I2,I1,I0}<=8'b0110_1011;

#10;

{I7,I6,I5,I4,I3,I2,I1,I0}<=8'b0011_0110;

#10;

仿真结果:

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

当前位置:首页 > 考试认证 > 公务员考试

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2