期末数电作业

一、实验目的

运用Quartus软件与Modelism联合仿真

二、实验内容运用Quartus软件与Modelsim软件尝试建立一个门级模型
三、实验原理按照视频上的内容,书写和运行代码,完成实验和仿真
四、实验工具电脑、Quartus软件与Modelsim软件
五、实验过程截屏及代码
实验一:
实验一截屏

实验代码:

module dec4to16 (W,En,Y);
  input [3:0] W;
  input En;
  output [0:15]Y;
  wire [0:3]M;
  
  dec2to4 Dec1 (W[3:2],En,M[0:3]);
  dec2to4 Dec2 (W[1:0],M[0],Y[0:3]);
  dec2to4 Dec3 (W[1:0],M[1],Y[4:7]);
  dec2to4 Dec4 (W[1:0],M[2],Y[8:11]);
  dec2to4 Dec5 (W[1:0],M[3],Y[12:15]);
 
endmodule

module dec2to4(W, En, Y);
    input [1:0]W;
    input En;
    output reg [0:3]Y;
    
    always @(W, En)
    begin
        if(En==0)
            Y=4'b0000;
        else
            case(W)
                0:Y=4'b1000;
                1:Y=4'b0100;
                2:Y=4'b0010;
                3:Y=4'b0001;
            endcase
    end
    
endmodule

测试代码:

`timescale 1 ps/ 1 ps
module tb_dec();
    reg [3:0]W;
    reg En;
    wire [0:15]Y;

    dec4to16 li(.W(W),.En(En),.Y(Y));
    
    initial
    begin
    W=4'b0000;
    #10 W=4'b0001;
    #10 W=4'b0010;
    #10 W=4'b0011;
    #10 W=4'b0100;
    #10 W=4'b0101;
    #10 W=4'b0110;
    #10 W=4'b0111;
    #10 W=4'b1000;
    #10 W=4'b1001;
    #20 $stop;
    end
    initial
    En=1'b0;
    always #10 En=~En;
    
endmodule

b站视频链接:

【Quarturs-哔哩哔哩】https://b23.tv/MA087n

实验二实验截图:

实验二第一部分代码:

module add_pp(a,b,cin,sum,cout,clock);
input [7:0]a,b;
input cin,clock;
output [7:0]sum;
output cout;
reg c1o;
wire c1;

always @(posedge clock)
c1o<=c1;

assign {cout,sum[7:4]}=a[7:4]+b[7:4]+c1o;
assign {c1,sum[3:0]}=a[3:0]+b[3:0]+cin;

endmodule
测试代码:

module tbs51;
reg [7:0] add1,add2;
reg clock;
reg add_cin;
wire [7:0] add_sum;
wire add_cout;

integer seed1=9,seed2=12,seed3=15;

always
begin
add1={$random(seed1)}%128;
add2={$random(seed2)}%128;
add_cin={$random(seed3)}/2;
#60;
end
initial clock=0;
always #15 clock=~clock;
add_pp myadd (add1,add2,add_cin,add_sum,add_cout,clock);

endmodule

实验二的第二部分实验截图:

实验代码:

module mul_pp(mul_a, mul_b, clock, reset_n, mul_out); 
input [3:0] mul_a, mul_b;
input clock;
input reset_n;
output [7:0] mul_out;

reg[7:0] mul_out;
reg [7:0] temp_and0;
reg [7:0]temp_and1;
reg [7:0] temp_and2;
reg[7:0]temp_and3;
reg[7:0]temp_add1;
reg[7:0] temp_add2;
always @(posedge clock or negedge reset_n)
begin
if(!reset_n)
begin
mul_out <= 0;
temp_and0 <= 0;
temp_and1 <= 0;
temp_and2 <= 0;
temp_and3 <=0;
temp_add1 <= 0;
temp_add2 <=0;
end
else
begin
temp_and0 <= mul_b[0]? {4'b0, mul_a}:8'b0;
temp_and1 <= mul_b[1]? {3'b0, mul_a,1'b0}:8'b0;
temp_and2 <= mul_b[2]? {2'b0, mul_a,2'b0}:8'b0;
temp_and3 <= mul_b[3]? {1'b0, mul_a,3'b0}:8'b0;
temp_add1 <= temp_and0 +temp_and1;
temp_add2 <= temp_and2 +temp_and3;
mul_out <= temp_add1 +temp_add2;
end
end
endmodule

测试代码:module tbs52;
reg [3:0] mul_a,mul_b;
reg reset_n,clock;
wire [7:0] mul_out;
integer seed1=9,seed2=12;
always
begin
mul_a=$random(seed1);
mul_b=$random(seed2);
#30;
end
initial
begin
reset_n=1;clock=0;
#20reset_n=0;
#10reset_n=1;
end
always #15 clock=~clock;
mul_pp mymul(mul_a,mul_b, clock, reset_n, mul_out);
endmodule

b站视频链接:

【Qutartus-哔哩哔哩】https://b23.tv/y3uIE5

实验三实验截图

实验代码:module Majority #(parameter size=8,max=3,majority=5)(
input [size-1:0] Data,
output reg       Y
);
reg   [max-1:0]    count;
integer          k;
always@(Data)begin
count=0;
for(k=0;k<size;k=k+1)begin
if(Data[k]==1)count=count+1;
end
Y=(count>=majority);
end
endmodule

实验测试代码:`timescale 1 ps/ 1 ps
module tb_Majority();
reg [7:0] data;
wire Y;
Majority i1 (.Data(data),.Y(Y));
initial                                          
begin                                                  
        data[7:0]=8'b00000000;
    #5 data[7:0]=8'b11010011;
    #5 data[7:0]=8'b11010100;
    #5 data[7:0]=8'b11010101;
    #5 data[7:0]=8'b11010110;
    #5 data[7:0]=8'b11010111;
    #5 data[7:0]=8'b11011000;
    #5 data[7:0]=8'b11011001;
    #5 data[7:0]=8'b11011010;
    #5 data[7:0]=8'b11011011;
    #5 data[7:0]=8'b11011100;
    #5 data[7:0]=8'b11011101;
    #5 data[7:0]=8'b11011110;
    #5 data[7:0]=8'b11011111;
    #5 data[7:0]=8'b11100000;    
    #20 $stop;
end                                                                                                    
endmodule

b站视频链接:

【modelsim的实践运用-哔哩哔哩】https://b23.tv/DX6krG

注明:这里因为我是运用Modelsim来做的,所以每个实验都有两个代码(一个实验代码、一个测试代码,测试代码是用来测试实验代码的。)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值