(一)参考学习资料

(二)实际操作

1. 相关变量计算:

 

First Initial

Second Initial

Upper case

H

X

ASCII (Dec)

72

88

Lengths of the pulse

   

Mu

Mu_1

2.5*105

Mu_2

2.5*105

k : mu

ku_1 : mu_1

1.2812:3.7188

ku_2 : mu_2

1.3438:3.6562

nu

nu_1

18

nu_2

18

Ku

Ku_1

64060

Ku_2

67190

Lower case

h

x

ASCII (Dec)

104

120

Lengths of the pulse

   

Ml

Ml_1

2.5*105

Ml_2

2.5*105

k : ml

kl_1 : ml_1

1.4063:3.5937

k : ml_2

1.4688:3.5312

nl

nl_1

18

nl_2

18

Kl

Kl_1

70315

Kl_2

73440

2. 第一版:

 module Assignment2(rst, CP, Z);
input CP;
input rst; //1 for upper & 0 for lower reg turn = ;
reg [:] cyc = ; //use for the number of cycles //constant parameters
parameter k = , n = , K = ;
parameter KK = K-; //take parameters according to rst input
reg [:] M;
reg [:] MM;
reg [:] m;
//output of the lautch
output Z;
reg Z; //parameters of upper case
parameter [:] Mu [:] = {, };
parameter [:] mu [:] = {, };
//parameter Ku_1 = k*Mu_1/(k+mu_1);
parameter [:] MMu [:] = {, };
//Parameter []KKu_1 = Ku_1-1; //parameters of lower case
parameter [:] Ml [:] = {, };
parameter [:] ml [:] = {, };
parameter [:] MMl [:] = {, }; //Check rst to determine upper or lower.
//check the number of turn to determine the first two or the second.
always@(posedge CP)
begin
if(rst)
begin
M <= turn ? Mu[]:Mu[];
m <= turn ? mu[]:mu[];
MM <= turn ? MMu[]:MMu[];
end
else if(!rst)
begin
M <= turn ? Ml[]:Ml[];
m <= turn ? ml[]:ml[];
MM <= turn ? MMl[]:MMl[];
end
end //Latch
reg [n-:] Q = ;
wire ld, cz;
assign ld = Q>=MM;
assign cz = (Q<KK)|ld; always@(posedge CP)
begin
{Q,Z} <= {ld?:Q+, cz};
cyc = ld ? cyc+ : cyc; if(cyc == )
begin
turn <= ;
cyc <= ;
end
else begin
turn <= ;
end
end endmodule
  • 出现问题1:

解决方案:将如下部分的变量类型由reg改为了input,系统没有再次崩溃。

     //take parameters according to rst input
reg [:] M;
reg [:] MM;
reg [:] m;
//output of the lautch
output Z;
reg Z;

原因:不明

补充:reg变量不可按位赋值,在二维数组中的赋值应为下图第一种方法。

// Correct
M <=Mu[]; // Wrong
M <=Mu[][:];
  • 出现问题2:vwf文件仿真时,M没有成功赋值

解决方案:修正了对reg宽度的定义。

补充:

1. Verilog中reg类型的宽度是自定义的,若无定义则默认为1bit。reg的宽度影响变量的取值,若赋值超出reg的范围,不会产生Error,reg变量的最大值将被默认为reg宽度。修改变量时应注意该变量的取值范围。

2. reg变量只能存储整数,允许的运算为加减乘除,若要实现浮点数需要以此为基础构建相关专门的模块。

3. 第二版:

 module Assignment2(rst, CP, Z, K);
input CP;
input rst; //1 for upper & 0 for lower reg turn = ;
//use to determine whether the first group of pulses or the second one
reg [:] cyc = ;
//use for the number of pulses in one 'turn' ////constant parameters
parameter n = , M = ;
parameter MM = M-; ////take parameters according to rst input
output [n-:] K;
reg [n-:] K = ; ////output of the lautch
output Z;
reg Z; ////parameters of upper case
parameter Ku_1 = ;
parameter Ku_2 = ; ////parameters of lower case
parameter Kl_1 = ;
parameter Kl_2 = ; ////Latch
reg [n-:] Q;
wire ld, cz;
assign ld = Q>=MM;
assign cz = (Q<K-)|ld; always@(posedge CP)
begin
////Check rst to determine upper or lower.
////check the number of turn to determine the first two or the second.
case(rst)
: begin
if(turn)K <= Kl_2;
else if(!turn)K <= Kl_1;
else K <= ;
end
: begin
if(turn)K <= Ku_2;
else if(!turn)K <= Ku_1;
else K <= ;
end
default: K <= ;
endcase ////renew the state and output clock.
{Q,Z} <= {ld?:Q+, cz};
cyc = ld ? cyc+ : cyc; ////1 cyc represent a pulse
////2 cycles cause an increment in turn
////4 cycles for an entire loop
if(cyc == )
begin
turn <= ;
end
else if(cyc== && turn==)
begin
turn <= ;
cyc <= ;
end end endmodule
  • 仿真结果://K的取值有修改。
  • 补充:在Z的第一个输出前有一小段空白期,测量为微秒级,第一个输出仍为5ms。感觉应该不影响时钟的使用,但没有经过硬件检测。

Verilog HDL学习_1:分频器/PWM的实现的更多相关文章

  1. Verilog HDL的程序结构及其描述

    这篇博文是写给要入门Verilog HDL及其初学者的,也算是我对Verilog  HDL学习的一个总结,主要是Verilog HDL的程序结构及其描述,如果有错,欢迎评论指出. 一.Verilog ...

  2. Verilog HDL基础语法讲解之模块代码基本结构

    Verilog HDL基础语法讲解之模块代码基本结构   本章主要讲解Verilog基础语法的内容,文章以一个最简单的例子"二选一多路器"来引入一个最简单的Verilog设计文件的 ...

  3. 基于Verilog HDL整数乘法器设计与仿真验证

    基于Verilog HDL整数乘法器设计与仿真验证 1.预备知识 整数分为短整数,中整数,长整数,本文只涉及到短整数.短整数:占用一个字节空间,8位,其中最高位为符号位(最高位为1表示为负数,最高位为 ...

  4. 浅谈Verilog HDL代码编写风格

    消失了好久,没有写文章,也没有做笔记,因为最近再赶一个比赛,时间很紧,昨天周六终于结束了,所以趁着周末这会儿有时间,写点东西,记录下来.首先我学习FPGA才一年多,我知道自己没有资格谈论一些比较深层次 ...

  5. 如何高效的编写Verilog HDL——进阶版

    博主之前写过一篇文章来谈论如何高效的编写Verlog HDL——菜鸟版,在其中主要强调了使用Notepad++来编写Verilog HDL语言的便捷性,为什么说是菜鸟版呢,因为对于新手来说,在还没有熟 ...

  6. verilog HDL -模块代码基本结构

    1--verilog HDL 语言的预编译指令作用:指示在编译verliog HDL源代码前,需要执行哪些操作. 2--模块内容是嵌在module 和endmodule两个语句之间.每个模块实现特定的 ...

  7. Verilog HDL 使用规范(一)

    本博文参考:<大规模逻辑设计指导书>,对于写出规范的代码,培养良好的代码风格颇有裨益. wire and register 一个reg变量只能在一个always语句中赋值: 这个说明至关重 ...

  8. 关于初次使用Verilog HDL语言需要懂的基本语法

    关于初次使用Verilog HDL语言需要懂的基本语法 1.常量 数字表达式全面的描述方式为:<位宽><进制><数字> 8’b10101100,表示位宽为8的二进制 ...

  9. FPGA Verilog HDL 系列实例--------步进电机驱动控制

    [连载] FPGA Verilog HDL 系列实例 Verilog HDL 之 步进电机驱动控制 步进电机的用途还是非常广泛的,目前打印机,绘图仪,机器人等等设备都以步进电机为动力核心.那么,下面我 ...

随机推荐

  1. MySQL多表联查以及以及架构

    多表之间关联查询:      据库操作中,多表联合查询是后台开发者常用到的查询语句. JOIN SQL JOIN 子句用于把来自两个或多个表的行结合起来,最常见的 JOIN 类型:SQL INNER ...

  2. 百度搜索关键词联想API JSONP使用实例

    许多搜索引擎都提供了关键词联想api,且大多数都是jsonp. Jsonp(JSON with Padding) 是 json 的一种"使用模式",可以让网页从别的域名(网站)那获 ...

  3. 如何从Serilog请求日志记录中排除健康检查终结点

    这是在ASP.NET Core 3.X中使用Serilog.AspNetCore系列文章的第四篇文章:. 第1部分-使用Serilog RequestLogging减少日志详细程度 第2部分-使用Se ...

  4. 关于MySQL5.6配置文件my-default.ini不生效问题

    一.问题描述 首先,由于工作要求,需使用MySQL5.6版本(绿色版),从解压到修改root密码,一切都很顺利,但是在我要修改mysql的最大连接数的时候,出现问题了,配置不生效.完蛋.还好有万能的百 ...

  5. Linux 常用工具openssh之ssh-add

    前言 ssh-add命令是把专用密钥添加到ssh-agent的高速缓存中,从而提高ssh的认证速度 语法 ssh-add [-cDdLlXx] [-t life] [file ...] 选项 -D:删 ...

  6. 外网通过frp进行windows远程文件共享

    需求 远程访问位于内网中的文件.例如,家里,公司内. 所需技术 frp windows文件共享 具有公网地址的服务器一台 实现过程 windows文件共享,首先自己在局域网内实现.这不是本文重点. 公 ...

  7. mvc jQuery 点击按钮实现导出Excel功能 参数长短不限

    var exportSubmit=function(url, obj){ var form = $("<form>"); //定义一个form表单 form.attr( ...

  8. sharding-JDBC学习笔记

    sharding-JDBC学习笔记 ShardingSphere ShardingSphere是一套开源的分布式数据库中间件解决方案组成的生态圈,它由Sharding-JDBC.Sharding-Pr ...

  9. Docker快速上手之搭建SpringBoot项目

    Docker是基于Go语言实现的云开源项目. Docker的主要目标是“Build,Ship and Run Any App,Anywhere”,也就是通过对应用组件的封装.分发.部署.运行等生命周期 ...

  10. ATL的GUI程序设计(1)

    from:http://blog.titilima.com/atlgui-1.html 第一章 不能免俗的"Hello, World!" 在这一章里,就像所有的入门级教程一样,我也 ...