Verilog HDL学习_1:分频器/PWM的实现
(一)参考学习资料

(二)实际操作
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的实现的更多相关文章
- Verilog HDL的程序结构及其描述
这篇博文是写给要入门Verilog HDL及其初学者的,也算是我对Verilog HDL学习的一个总结,主要是Verilog HDL的程序结构及其描述,如果有错,欢迎评论指出. 一.Verilog ...
- Verilog HDL基础语法讲解之模块代码基本结构
Verilog HDL基础语法讲解之模块代码基本结构 本章主要讲解Verilog基础语法的内容,文章以一个最简单的例子"二选一多路器"来引入一个最简单的Verilog设计文件的 ...
- 基于Verilog HDL整数乘法器设计与仿真验证
基于Verilog HDL整数乘法器设计与仿真验证 1.预备知识 整数分为短整数,中整数,长整数,本文只涉及到短整数.短整数:占用一个字节空间,8位,其中最高位为符号位(最高位为1表示为负数,最高位为 ...
- 浅谈Verilog HDL代码编写风格
消失了好久,没有写文章,也没有做笔记,因为最近再赶一个比赛,时间很紧,昨天周六终于结束了,所以趁着周末这会儿有时间,写点东西,记录下来.首先我学习FPGA才一年多,我知道自己没有资格谈论一些比较深层次 ...
- 如何高效的编写Verilog HDL——进阶版
博主之前写过一篇文章来谈论如何高效的编写Verlog HDL——菜鸟版,在其中主要强调了使用Notepad++来编写Verilog HDL语言的便捷性,为什么说是菜鸟版呢,因为对于新手来说,在还没有熟 ...
- verilog HDL -模块代码基本结构
1--verilog HDL 语言的预编译指令作用:指示在编译verliog HDL源代码前,需要执行哪些操作. 2--模块内容是嵌在module 和endmodule两个语句之间.每个模块实现特定的 ...
- Verilog HDL 使用规范(一)
本博文参考:<大规模逻辑设计指导书>,对于写出规范的代码,培养良好的代码风格颇有裨益. wire and register 一个reg变量只能在一个always语句中赋值: 这个说明至关重 ...
- 关于初次使用Verilog HDL语言需要懂的基本语法
关于初次使用Verilog HDL语言需要懂的基本语法 1.常量 数字表达式全面的描述方式为:<位宽><进制><数字> 8’b10101100,表示位宽为8的二进制 ...
- FPGA Verilog HDL 系列实例--------步进电机驱动控制
[连载] FPGA Verilog HDL 系列实例 Verilog HDL 之 步进电机驱动控制 步进电机的用途还是非常广泛的,目前打印机,绘图仪,机器人等等设备都以步进电机为动力核心.那么,下面我 ...
随机推荐
- [bzoj4825] [loj#2018] [Hnoi2017] 单旋
Description \(H\) 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(\(splay\))是一种数据 结构,因为代码好写,功能多,效率高,掌握这种数据结构 ...
- CSS基础应用总结
目录 CSS 样式笔记 文字水平居中和垂直居中 如何设置a标签不带下划线 控件右对齐 div上下居中 控件左右居中 控件展示在同一行 设置文字超出部分...显示 CSS 样式笔记 文字水平居中和垂直居 ...
- 玩转Django2.0---Django笔记建站基础十(二)(常用的Web应用程序)
10.3 CSRF防护 CSRF(跨站请求伪造)也成为One Click Attack或者Session Riding,通常缩写为CSRF或者XSRF,是一种对网站的恶意利用,窃取网站的用户信息来制作 ...
- 每天玩转3分钟 MyBatis-Plus - 4. 高级查询(二)(条件构造器)
每天玩转3分钟 MyBatis-Plus - 1. 配置环境 每天玩转3分钟 MyBatis-Plus - 2. 普通查询 每天玩转3分钟 MyBatis-Plus - 3. 高级查询(一) 每天玩转 ...
- 简单看看LockSupport和AQS
这次我们可以看看并发中锁的原理,大概会说到AQS,ReentrantLock,ReentrantReadWriteLock以及JDK8中新增的StampedLock,这些都是在java并发中很重要的东 ...
- openresty http
openresty http openresty默认没有提供http客户端,需要第三方提供插件. 下载方式: wget https://raw.githubusercontent.com/pintsi ...
- Informatica9.5.1创建资源库出错找不到libpmora8.so
错误信息: Database driver event...Error occurred loading library [libclntsh.so.10.1: cannot open shared ...
- 命令行下使用RAR和7-Zip压缩数据
3.6.1 RAR Winrar的命令行模式程序在安装目录下的 rar.exe (打包压缩程序),unrar.exe(解压缩程序) WinRAR的常用参数如下: -a 添加文件到压缩文件 -k 锁定压 ...
- SpringBoot学习遇到的问题(1) - 配置文件有日志的debug模式等配置项,为什么不起作用
这个问题困扰我近乎两天,通过查找N多资料后终于解决,写下来共享给大家. logging.level.root=DEBUG ... 一系列的日志配置项,都不起作用的原因是springboot启动加载不到 ...
- C语言寒假大作战03
这个作业属于哪个课程 软件4班 这个作业要求在哪里 C语言寒假大作战03 这个作业的目标 增加菜单程序各年级题目操作函数 参考文献 随机数rand 2.2.2 设计思路和遇到的问题 这次作业写好没多久 ...