北航verilog上机实验报告(3)

2018-12-19 23:01

Verilog上机实验报告

ii.

initial begin

num=4; clk=0; rst=1; #10 rst=0; #110 rst=1;

#100000 $stop; end

div m(.rst(rst),.clk(clk),.out(out),.num(num)); endmodule

产生占空比不同的分频时钟

----------------------------主程序div_ex.v ----------------------------------------- module div_ex(rst,clk,out,top,down); input rst, clk;

input [3:0] top,down; //通过top,down调节占空比 output out; reg out; reg [3:0] i;

always @(posedge clk) begin if(!rst) begin i<=0; out<=0; end else begin

if (out==1) begin

if (i==(top-1)) begin i<=0;

out=~out; end else begin

i<=i+1; out=out; end end

11

Verilog上机实验报告

else begin

if (i==(down-1)) begin i<=0;

out=~out; end else begin

i<=i+1; out=out; end end end end

endmodule

----------------------------测试文件div_ex_tb.v -----------------------------------------

`timescale 1ns/100ps `define clk_cycle 50 module t; reg clk,rst; wire out;

reg [3:0] top,down;

always #`clk_cycle clk=~clk; initial begin

top=2; down=4; clk=0; rst=1; #10 rst=0; #110 rst=1;

#100000 $stop; end

div_ex m(.rst(rst),.clk(clk),.out(out),.top(top),.down(down)); endmodule

3. 实验总结

12

Verilog上机实验报告

本次实验是Verilog上机的第二个实验,练习了比较简单的时序逻辑电路的设计——分频器。

其中二分频的设计比较简单,课本上有几乎完全相同的代码,只需要稍加修改即可。而任意分频的设计比较困难,需要好好思考。我通过想学长请教,以及上网上查找资料,利用一个计数器完成了任意分频的设计,而产生不同占空比的设计,其原理相同。

13

Verilog上机实验报告

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

一、 实验目的

1. 掌握条件语句在简单时序模块设计中的使用;

2. 学习在Verilog模块中应用计数器;

3. 学习测试模块的编写、综合和不同层次的仿真。

二、 实验内容

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

三、 对任务的理解

题目要求产生特定形状的周期波形,从给出的波形来看,就是一个top=10us,down=40us,T=50us的周期方波。如果输入时钟为10MB,则top=100,down=400。可以利用实验2中占空比不同的分频电路的代码来完成任务。

四、 实现思路

1. 首先这个比较器应当有3个对外的端口,分别是:复位rst,输入时钟clk和输

出out。

2. 利用计数器产生特定的延时,来产生响应的波形。这个任务和实验二中的思考

题二第二个小任务完全相同。

五、 代码

1. 主程序

---------------------------------------文件名 div_ex.v--------------------------------------------

module div_ex(rst,clk,out); input rst, clk; reg [6:0] top; reg [8:0] down; output out; reg out;

14

Verilog上机实验报告

always @(posedge clk) begin if(!rst) begin top<=0; down<=0; out<=0; end else begin

if (out==1) begin

if (top==100) begin top<=0; out<=~out; end else begin

top<=top+1; out<=out; end end else begin

if (down==400) begin

down<=0; out<=~out; end else begin

down<=down+1; out<=out; end end end end

endmodule

2. 测试模块

----------------------------------------文件名 div_ex_tb.v-----------------------------------

15


北航verilog上机实验报告(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:法务会计视角下网络股票、期货诈骗证据研究

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: