云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 北航verilog上机实验报告

北航verilog上机实验报告

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 11:07:04

Verilog上机实验报告

always @(posedge clk_in) begin

if (!reset)

clk_out=1; //原例题中此处为clk_out=0; else

clk_out=~clk_out; end endmodule

2. 测试模块

----------------------------------------文件名 half_clk_tb.v----------------------------------- `timescale 1ns/100ps `define clk_cycle 50 module top; reg clk,reset; wire clk_out;

always #`clk_cycle clk=~clk; initial begin

clk=0; reset=1; #10 reset=0; #110 reset=1; #100000 $stop; end

half_clk m0(.reset(reset),.clk_in(clk),.clk_out(clk_out)); endmodule

六、 仿真波形

七、 总结及对波形的说明

1. 实验结论

从波形中可以看出当clk_out的周期为clk_in的两倍,并且在t=300ns时,为clk_out的下降沿,恰好和例题中的输出信号波形反相,满足题目的要求。

9

Verilog上机实验报告

2. 实验思考(课本P318思考题二)

1) 如果没有reset信号,可以通过在测试文件中的initial块中设置clk_in的初值为

1来使输出反相。

2) 只用clk时钟沿的出发可以通过一个计数器来产生其他分频的时钟,并且通过调

节计数器的值来产生不同占空比的分频时钟,其代码如下: i. 产生任意分频的时钟

----------------------------主程序div.v ----------------------------------------- module div(rst,clk,out,num); input rst, clk;

input [3:0] num; //通过num调节分频数 output out; reg out; reg [3:0] i;

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

if (i==((num[3:1])-1)) //num[3:1]代替num/2 begin i<=0;

out=~out; end else begin i<=i+1; out=out; end end end

endmodule

----------------------------测试文件div_tb.v ----------------------------------------- `timescale 1ns/100ps `define clk_cycle 50 module t; reg clk,rst; wire out;

reg [3:0] num;

always #`clk_cycle clk=~clk;

10

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上机实验报告 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

Verilog上机实验报告 always @(posedge clk_in) begin if (!reset) clk_out=1; //原例题中此处为clk_out=0; else clk_out=~clk_out; end endmodule 2. 测试模块 ----------------------------------------文件名 half_clk_tb.v----------------------------------- `timescale 1ns/100ps `define clk_cycle 50 module top; reg clk,reset; wire c

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com