当前位置:网站首页>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边栏推荐
- Modeling Semantics with Gated Graph Neural Networks for KBQA
- Android Development - set cache
- Janus series article 3 API usage guide videoroom creating a new video room
- Visual Studio 2015 团队开发之Azure DevOps篇
- Ugui learning notes (V) togglegroup makes multiple choice radio boxes
- Unity shader cartoon style rendering
- 《Kubernetes》你需要掌握的 Service 和 Ingress
- Microservice Architecture - service registry and service gateway (6.8) (Reprint)
- Games101 section 13 ray tracing notes
- C # traversal set
猜你喜欢

Net framework

Classroom attendance system based on QT design (using RDS for MySQL cloud database)

Technology sharing | how to recover the erroneously deleted table and the data in the table?

Steps to configure V530 switch

The maximum recommended number of rows for MySQL is 2000W. Is it reliable?

Easypoi --- excel file export

HTAP comes at a price

Vscode界面介绍

The practice of the beego framework for goweb development: Section V project construction and user registration

Source code of voice live broadcast app
随机推荐
Goweb开发之Beego框架实战:第一节 Beego框架介绍
Deep understanding of deepsea and salt deployment tools – storage6
PostgreSQL weekly news - July 20, 2022
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Leetcode 2022.04.10 China Merchants Bank special competition D. store promotion (DP)
线性代数及矩阵论(九)
C#遍历集合
Code implementation additive attention
Kubernetes service and ingress you need to master
The actual combat of the beego framework of goweb development: Section III program execution process analysis
Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
火了 2 年的服务网格究竟给微服务带来了什么?(转载)
Janus series article 3 API usage guide videoroom creating a new video room
配置V530交换机步骤
部分情况下Error:(xx, xx) Failed to resolve: xxxxxx解决。
It is said that NVIDIA has held talks with Softbank and will offer more than US $32billion to acquire arm
侦察机与预警机的区别
Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
Application of Pegasus d200s UAV and airborne lidar in large-scale DEM construction
The maximum recommended number of rows for MySQL is 2000W. Is it reliable?