一、实验目的:根据书中所给图片编写相应的独热码代码,并验证。
二、实验内容:Verilog HDL数字系统设计及仿真199页实例8-1。
三、实验代码:
module ex8_1(clock,reset,x,y1,y2) ;
input clock,reset;
input x;
output y1,y2;
reg y1,y2;
reg [3:0] cstate,nstate;
parameter s0=4'b0001,s1=4'b0010,
s2=4'b0100,s3=4'b1000;
always @ (posedge clock or posedge reset)
begin
if (reset)
cstate<=s0;
else
cstate<=nstate;
end
always @ (cstate or x)
begin
case (cstate)
s0:begin
if (x==0)
nstate=s1;
else
nstate=s3;
end
s1:begin
if (x==0)
nstate=s2;
else
nstate=s0;
end
s2:begin
if (x==0)
nstate=s3;
else
nstate=s1;
end
s3:begin
if (x==0)
nstate=s0;
else
nstate=s2;
end
default : nstate=s0;
endcase
end
always @ (cstate or x)
begin
case (cstate)
s0 : begin
if (x==0)
y1=1;
else
y1=0;
end
s1 : begin
if (x==0)
y1=0;
else
y1=0;
end
s2 : begin
if (x==0)
y1=0;
else
y1=0;
end
s3 : begin
if (x==0)
y1=0;
else
y1=1;
end
default :y1=0;
endcase
end
always @ (cstate or x)
begin
if (cstate==s0 && x==0)
y2=1;
else if (cstate==s3 && x==1)
y2=1;
else
y2=0;
end
endmodule
四、实验步骤:
1、建立工程:打开Quartus软件,在菜单栏中点击【File】→【New Project Wizard】,会弹出工程设置对话框,工程名和新建顶层模块名正常应该是空白的,这里填ex8_1,此名称要与设计模块中的module名称一致。填写好名称后,依次点击【Next】 即可,选择【Empty project】。进入下一步,选择添加文件。在Simulation 一栏中选择ModelSim工具。最后会有一个简单的报告,结束后就可以完成新工程的建立。
2、设计编译:在【File】菜单中选择【New】,选择Verilog HDL文件,建立一个新的设计文件,设计文件复制到软件中。将该文件保存后,在快捷工具栏中找到快捷按钮【Start Compilation】,点击分析。
3、联合仿真:在菜单栏找到按钮【RTL Simulation】,单击,进入Modelsim,单击【Wave—Default】栏的每一栏,出现【Define Clock】菜单栏,将Period栏的数字改一下,全部栏改完后,改动菜单栏的【Run Length】中的数据,单击【Run Length】栏旁边的【Run】按钮。
五、实验部分截屏:
六、实验结果截屏: