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


这里的波形图有问题,明明第一个上升沿来时,已经开始加一了,这里的num是中间计数器,number被赋值会慢一拍,但这也看不出来啊。。。牛客网的题真是,还是HDLbits的做的开心。
考虑了这个之后,就很简单了。具体解题过程如下:
`timescale 1ns/1ns
module count_module(
input clk,
input rst_n,
input mode,
output reg [3:0]number,
output reg zero
);
reg [3:0] num; //声明一个reg变量作为中间计数
always @(posedge clk or negedge rst_n) begin
if(!rst_n) num <= 0 ;
else if(num==9&&mode==1) num<=0; //要考虑num=9继续增加时变0的情况
else if(num==0&&mode==0) num<=9; //要考虑num=0继续减少时变9的情况
else if(mode==1) num<=num+1; //mode控制加减
else if(mode==0) num<=num-1;
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n) number <= 0; //将num赋值给number
else number <= num;
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n) zero = 0;
else if(num==0) zero <= 1;
else zero <= 0;
end
endmodule
边栏推荐
- After paying $1.8 billion in royalties to Qualcomm, Huawei reportedly ordered 120million chips from MediaTek! Official response
- Make full use of English
- Some attention code explanations
- 微服务架构-服务注册中心和服务网关(6.8) (转载)
- Ugui learning notes (III) summary of the use of each control
- Unity editor learning (I) using features to change the display of fields in components
- 一文了解 Kubernetes 中的服务发现
- Goweb开发之Beego框架实战:第四节 数据库配置及连接
- Ugui learning notes (V) togglegroup makes multiple choice radio boxes
- Unity shader realizes mirror effect with rendered texture
猜你喜欢

Unity shader transparent effect
![[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)

使用阿里云免费的SSL证书

Comprehensively design an oppe homepage -- page service part

浏览器解码过程分析

Reasoning Over Semantic-Level Graph for Fact Checking

: No such file or directory

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

Fine-grained Fact Verification with Kernel GA Network

How to protect image security during construction
随机推荐
Visual Studio 2015 团队开发之Azure DevOps篇
Function接口之andThen
Codeforces round 770 (Div. 2) e. fair share
部分情况下Error:(xx, xx) Failed to resolve: xxxxxx解决。
高速电路中电容的选型和应用——详解
浏览器解码过程分析
Analysis of kubernetes service principle
Net framework
Comprehensively design an oppe homepage -- page service part
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
MySQL installation tutorial
The maximum recommended number of rows for MySQL is 2000W. Is it reliable?
Pytorch Foundation: similarities and differences between torch.mul, torch.mm and torch.matmul
Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
WPF command button transparent style
Games101-assignment05 ray tracing - rays intersect triangles
Shopee code League 2022 - qualification round p3.connecting the numbers (segment tree / bipartite graph determination, to be discussed)
Modeling Semantics with Gated Graph Neural Networks for KBQA
22年多校第三场(F的证明
C# 导入Excel文件数据的几种方法