- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此代码是一个按钮防抖器。但我不明白为什么有两个人字拖:
reg PB_sync_0; always @(posedge clk) PB_sync_0 <= ~PB; // invert PB to make PB_sync_0 active high
reg PB_sync_1; always @(posedge clk) PB_sync_1 <= PB_sync_0;
为什么这段代码的作者没有写这个?
reg PB_sync_1; always @(posedge clk) PB_sync_1 <= ~PB;
完整代码如下:
module PushButton_Debouncer(
input clk,
input PB, // "PB" is the glitchy, asynchronous to clk, active low push-button signal
// from which we make three outputs, all synchronous to the clock
output reg PB_state, // 1 as long as the push-button is active (down)
output PB_down, // 1 for one clock cycle when the push-button goes down (i.e. just pushed)
output PB_up // 1 for one clock cycle when the push-button goes up (i.e. just released)
);
// First use two flip-flops to synchronize the PB signal the "clk" clock domain
reg PB_sync_0; always @(posedge clk) PB_sync_0 <= ~PB; // invert PB to make PB_sync_0 active high
reg PB_sync_1; always @(posedge clk) PB_sync_1 <= PB_sync_0;
// Next declare a 16-bits counter
reg [15:0] PB_cnt;
// When the push-button is pushed or released, we increment the counter
// The counter has to be maxed out before we decide that the push-button state has changed
wire PB_idle = (PB_state==PB_sync_1);
wire PB_cnt_max = &PB_cnt; // true when all bits of PB_cnt are 1's
always @(posedge clk)
if(PB_idle)
PB_cnt <= 0; // nothing's going on
else
begin
PB_cnt <= PB_cnt + 16'd1; // something's going on, increment the counter
if(PB_cnt_max) PB_state <= ~PB_state; // if the counter is maxed out, PB changed!
end
assign PB_down = ~PB_idle & PB_cnt_max & ~PB_state;
assign PB_up = ~PB_idle & PB_cnt_max & PB_state;
endmodule
谢谢!
最佳答案
该代码的作者使用 2 个触发器来将 PB 信号同步到 clk 域。正如他在评论中提到的"PB" is the glitchy, asynchronous to clk
。不同步时钟域转换上的信号可能会导致系统出现亚稳态,如工具引用 en.wikipedia.org/wiki/Metastability_in_electronics
关于verilog - 为什么在此 Verilog HDL 代码中使用两个触发器而不是一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24660371/
如标题所示,结构 Verilog 和行为 Verilog 之间的主要区别是什么? 最佳答案 根据 IEEE 标准,这些术语没有严格的定义。然而,习惯上,结构 是指使用模块实例来描述设计(尤其是对于较低
我正在尝试简单地转换流程图 state machine进入 Verilog代码。 但是我不知何故被以下内容困住了,因为我对 Verilog 几乎没有任何了解,所以我可能会遗漏一些东西。 状态机检测到
是否可以在 verilog 中参数化位域?本质上,我想使用参数或替代方法来定义位范围。我能想到的唯一方法是使用如下所示的`define,但似乎应该有更好的方法。 `define BITFIELD_SE
初学者在这里。我正在尝试在 Verilog 中编写一个简单的 16 位微处理器并在 Spartan 6 上实现它。 ALU 实现所有有符号操作(根本没有无符号操作)。所有输入都是连线并带有符号。结果存
我写了一些 Verilog 代码,其中部分代码如下: int i; add_bit = 1'b0; for (i = 0; i < add_len; i++)
我需要在我的 Verilog 代码中使用有理数。我寻找了任何资源,但找不到有关此问题的任何信息。如何在 Verilog 中定义有理数。 最佳答案 Verilog 有一个 real用于实数(浮点)数的数
我正在自学verilog。我正在阅读的这本书在介绍章节中指出,要执行除法,我们使用“/”运算符或“%”运算符。后面几章都说除法对于verilog来说太复杂了,不能综合,所以要进行除法就引入了很长的算法
是否可以在 Verilog 中创建 parameter 数组?例如,类似于以下内容: parameter[TOTAL-1 : 0] PARAM_ARRAY = {1, 0, 0, 2} 如果不可能,那
例如,假设我有一个 reg [7:0] myReg我给它赋值 -8'D69 我知道 Verilog 将它存储为 2 的补码,所以它应该存储为 10111011 我现在的问题是是否要对其执行操作,例如
我正在尝试编写一个用于遗传算法的适应度函数,该函数包含指数部分。那么我该如何实现这个函数( e^x ),其中 e :the base=2.7 ,x:exponent 在 verilog HDL 语言中
我在verilog中有一个语句,看起来像integer level = log(N)(其中N是一个参数,级别待确定)但我知道我无法在verilog中执行复杂的数学语句,所以我想知道是否有替代解决方案来
在 Verilog 中,您可以简单地使用模块语法创建模块。如何创建多个模块并调用另一个模块? 我的主模块有以下模块: module Lab7Part1(SW, HEX0, HEX1, HEX2, HE
在使用自上而下的方法在 verilog 中设计电路时,我可以从电路的行为开始,然后定义每个模块中的细节,以构建可综合的结构电路。但我怎么知道我的代码是否可综合呢?是否有任何指南可以遵循来支持 veri
如果我有一个 if 语句,例如: if(risingEdge && cnt == 3'b111) begin ... end 如果risingEdge不为真,它会检查cnt吗? 这在 HDL 内部
我一直在尝试构建一个模块,该模块返回(3 位)输入的二进制补码表示(第一位是符号)。我认为以下代码在概念上是正确的,但我可能遗漏了它的结构:当我尝试编译时,出现以下错误: (vlog-2110) Il
我对 HDL 语言非常陌生。我有一个关于如何对移位寄存器进行编程的问题。 (我知道我转向另一个方向)。为什么本书使用 wire[N-1:0] r_next?我的实现有什么缺点?谢谢 我的第一次尝试如下
郑重声明,我是一个十足的 Verilog 新手。我正在编写一个使用一些双向总线的模块。 inout wire [KEY_SIZE-1:0] prevKey; inout wire [TAG_SIZE-
我进行了搜索以了解 verilog 中的行为代码和数据流代码之间的区别。最后我找不到很好的例子,到处都在讲述他们所做的事情。例如: “它非常简单。名称本身就解释了它们是什么。数据流是描述程序的一种方式
在 Verilog 中,您可以简单地使用模块语法创建模块。您如何创建多个模块并从另一个模块调用一个? 我有以下模块是我的主要模块: module Lab7Part1(SW, HEX0, HEX1, H
我正在学习 verilog 分层事件队列。我对非事件事件有一点疑问。我知道它们是在当前模拟时间完成所有事件事件后执行的。但是我写了一个简单的代码来更好地理解这个概念,但我得到的结果让我感到困惑。这是我
我是一名优秀的程序员,十分优秀!