当前位置:网站首页>Verilog 每日一题 (VL27 可置位计数器)
Verilog 每日一题 (VL27 可置位计数器)
2022-07-28 16:23:00 【别再出error了】
题目描述
请编写一个十六进制计数器模块,计数器输出信号递增每次到达0,给出指示信号zero,当置位信号set 有效时,将当前输出置为输入的数值set_num。
模块的接口信号图如下:


思路:在这个波形图看的不清楚,实际上rst_n置1后num先为0,再变1,一开始没注意这个一直不知道为啥错了。所以输出的number必须有一个周期的时延。
这里用添加一个中间计数器num来延后一个时钟,当num<=num+1时,number <=num,由于always块是并行的,所以此时number赋值时num,非阻塞赋值num<=num+1同步进行,而此时的num=0;
拓展的想,如果再加一个num2<=number,赋值又会延后一个周期。可以通多添加中间变量来增加时延。
(这个方法可以记一下)
剩余的思路就简单了,num=0时zero=1,num从0-15循环。
`timescale 1ns/1ns
module count_module(
input clk,
input rst_n,
input set,
input [3:0] set_num,
output reg [3:0]number,
output reg zero
);
reg [3:0]num;
always @(posedge clk or negedge rst_n)begin
if (!rst_n) zero <= 1'd0;
else if (num == 0) zero <= 1;
else zero <= 1'b0;
end
always @(posedge clk or negedge rst_n) begin
if (!rst_n) num <= 4'b0;
else if(set) num <= set_num;
else num <= num + 1'd1;
end
always @(posedge clk or negedge rst_n) beign
if (!rst_n) number <= 1'd0;
else number <= num;
end
endmodule边栏推荐
- 飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
- UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree
- What does the service grid that has been popular for two years bring to microservices? (Reprinted)
- Some notes on how unity objects move
- 2022牛客多校第二场CDE
- Verilog 每日一题 (VL5 信号发生器)
- Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
- Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
- The practice of beego framework in goweb development: Section I Introduction to beego framework
- Verilog 每日一题(VL6 数据串转并电路)
猜你喜欢

What does the service grid that has been popular for two years bring to microservices? (Reprinted)

The actual combat of the beego framework of goweb development: Section III program execution process analysis

Goweb开发之Beego框架实战:第二节 项目初始化配置

Verilog 每日一题(VL6 数据串转并电路)

Re11: read EPM legal judgment prediction via event extraction with constraints

Comprehensively design an oppe homepage -- page service part
Read excel xlsx format file in unity

带参数的微信小程序二维码生成

Realize the reset function of steering wheel UI with touch rotation and finger departure in unity

Unity shader cartoon style rendering
随机推荐
飞马D200S无人机与机载激光雷达在大比例尺DEM建设中的应用
The practice of the beego framework for goweb development: Section V project construction and user registration
Code implementation additive attention
Re11: read EPM legal judgment prediction via event extraction with constraints
Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
Make full use of English
The 16th program design competition of Dalian University of Technology (Problem Solver)
After paying $1.8 billion in royalties to Qualcomm, Huawei reportedly ordered 120million chips from MediaTek! Official response
Unity shader texture animation
Problem solution of code heartstrings Junior Group (official competition) of Dalian University of Technology (Development Zone campus) in 2021
Difference between reconnaissance aircraft and early warning aircraft
List of supplementary questions
How do we do full link grayscale on the database?
Rsync service deployment and parameter details
Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
Kubernetes service and ingress you need to master
Unity shader global fog effect
Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)