【问题标题】:Counting of different channels diverge and jumps不同通道的计数发散和跳跃
【发布时间】:2017-10-18 13:23:29
【问题描述】:

我正在尝试实现一个计数模块。我的基本设置: FPGA(带有 Xilinx Artix-35T 的 Digilent 的 Arty),带有两条 BNC 电缆,连接到连接到信号发生器的 IO 端口,并通过 USB/UART 连接到 PC 以进行读取。我的信号发生器产生 1 Hz 的 TTL 信号。

我现在想计算通道 1、通道 2 中的事件数量以及通道 1 和 2 的重合度。虽然基本原理有效,但我看到通道 1 和 2 是分开的,即使它们具有相同的输入 (通过 BNC-T 连接器)。此外,有时其中一个输出通道会跳动 - 朝任一方向,见图。 紫色通道(“通道 1”)与绿色(“通道 2”)具有不同的斜率。巧合也使这里发生了两次小的有损跳跃。

我的顺序计数代码看起来像

reg [15:0] coinciInt [(numCoincidences -1):0]; // internally store events
always @(posedge clk or posedge reset)    // every time the clock rises...
begin
    signalDelay <= signal;                // delayed signal for not counting the same event twice

    if(reset)                             // reset
    begin
        for(i=0;i<numCoincidences;i=i+1) 
            coinciInt[i] <= 16'b0;
    end
    else                                  // No reset
    begin
        for(i=1;i<numCoincidences;i=i+1)   // loop through all coincidence possibilities:
        begin 
            if( ((signal & i) == i) && ((signalDelay & i) != i) )   // only if signal give coincidence, but did not give before, it's a coincidence
            begin                         // "(signal & i) == i" means that "signal" is checked if bitmask of "i" is contained: 
                                          // ((0011 & 0010) == 0010) is true, since 0011 & 0010 = 0010 == 0010  
                coinciInt[i] <= coinciInt[i] + 1'b1;    // the i-th coincidence triggered, store it
            end
        end
    end
end // end of always

assign coinci = coinciInt;  // the output variable is called coinci, so assign to this one

请注意,所有事件都在注册表中 - 巧合以及“单一事件”。理想情况下,coinci[1] 应该存储通道 1 的事件,coinci[2] 这些通道 2 和 coinci[3] 1 和 2 之间的巧合,因为通道被标记为 1,2,4,8,...,2 ^n 和各自总和的巧合。 coinci[0] 用于某种校验和,但现在已经离题了。

对于缺失的计数有什么想法吗?对于不同的斜坡?

非常感谢

编辑 1

@Brian Magnuson 指出了元稳定性问题。使用多缓冲输入解决了发散通道的问题。这很好用。虽然我不完全明白其中的原因,但到目前为止,我也没有看到巧合频道有任何跳跃。您可能会为我节省很多时间,谢谢!

【问题讨论】:

  • 很高兴它为您解决了问题。对不起,简短的回答。 en.wikipedia.org/wiki/… 有更多信息。基本上没有同步器,您可以保证偶尔违反输入扇出到的第一个 FF 的设置/保持要求。当这种情况发生时,翻牌进入的状态(0/1)是不确定的。同步器“包含”该行为并且不会让它污染您的计数器逻辑。另一个 google'able 短语将是“时钟域交叉”。祝你好运!

标签: verilog fpga system-verilog counting


【解决方案1】:

我怀疑存在亚稳定性问题。您在 ch1/ch2 上的输入脉冲可能与您使用的系统时钟不同步。 See here.

因此,您可能有时会在“中步”捕获计数器更新,可以说这会导致意外行为。

要解决此问题,您可以将输入翻转两次(称为双列同步器),然后再将它们输入到您的逻辑的其余部分。通常多位同步需要更仔细的处理,但在您的情况下,每个位都可以独立处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多