HDLBits学习------Problem 173~177(完结)

Problem 173 Clock

        问题:编写testbench产生一个驱动时钟信号,来驱动模块dut,时钟周期为10ps

        解决:

`timescale 1ps/1ps //仿真单位为1ps,精度为1ps
module top_module ( );

	reg clk;
	
	dut dut_inst(clk);
	
	initial begin
		#0 clk = 0;//clk初始为0
	end
	
	always #5 clk = ~clk;//每5个时钟单位 clk取反一次
		
endmodule

Problem 174 Testbench1

        问题:编写testbench产生A、B两个输出信号,波形如下:

        解决:

`timescale 1ps/1ps

module top_module ( output reg A, output reg B );//

    // generate input patterns here
    initial begin
	
		#0 	A=0;
			B=0;
		#10	A=1;
		#5	B=1;
		#5 A=0;
		#20 B=0;
		
    end

endmodule

        注意理解#后面的延时 而不是在某一个时刻


Problem 175 AND gate

        问题:为你提供如下的与门

module andgate (
    input [1:0] in,
    output out
);

       编写testbench测试输入的四种组合,每5个时基改变一次

        解决:

`timescale 1ps/1ps

module top_module();

	reg[1:0] in;
	reg out;
	
	andgate andgate_inst(in,out);
	
	initial begin
		#0	in = 2'b00;
        #10	in = 2'b01;
        #10	in = 2'b10;
        #10	in = 2'b11;
	end
	
endmodule

        居然妄图写循环执行,发现并不需要


Problem 176 Testbench2

        问题:编写testbench例化下面的模块,然后产生下图的波形输出

module q7 (
    input clk,
    input in,
    input [2:0] s,
    output out
);

        解决:

`timescale 1ps/1ps

module top_module();

	reg clk;
	reg in;
	reg[2:0] s;
	reg out;
	
	q7 q7_inst(
		.clk(clk),
		.in(in),
		.s(s),
		.out(out)
	);
	
	initial begin
		#0	clk = 0;
			in = 1'b0;
			s = 3'd2;
		#10 s = 3'd6;
		#10	in = 1'b1;
			s = 3'd2;
		#10 in = 1'b0;
			s = 3'd7;
		#10 in = 1'b1;
			s = 3'd0;
		#30 in = 1'b0;
	end
	
	always #5 clk = ~clk;
	
endmodule

Problem 177 T flip-flop

        问题:提供一个T触发器的模块

module tff (
    input clk,
    input reset,   // active-high synchronous reset
    input t,       // toggle
    output q
);

        编写testbench例化该tff模块,复位它然后切换到状态‘1’

        解决:

`timescale 1ps/1ps

module top_module();

	reg clk;
	reg reset;
	reg t;
	reg q;
	
	tff tff_inst(
		.clk(clk),
		.reset(reset),
		.t(t),
		.q(q)
	);
	
	initial begin
		#0	clk = 0;
			t = 1'b0;
			reset = 1'b1;
		#10 reset = 1'b0;
			t = 1'b1;
	end
	
	always #5 clk = ~clk;
	
endmodule

        呜~~~~

        终于做完了,题目还是都比较基础的感觉,比较收获的就是状态机那部分了,三段式真的学到了很多,还有就是分模块设计电路那里,也体会到了分模块设计的好处。最后就是testbench的编写了,虽然感觉还算简单把,但是也是一直没有学习,现在也算了解了一点了

        后面就准备着手小项目,先点个oled玩玩~~~

        完结撒花~~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值