我有一个带有fowling输入和输出的Verilog模块
module Foo
#(
parameter DATA_BITS = 32,
parameter ENUM_BITS = 8,
parameter LED_BITS = 8
)
(
//Module IO declarations
input logic Clk_i,
input logic Reset_i,
input logic NoGoodError_i,
input logic EncoderSignal_i,
input logic [DATA_BITS-1:0]DistanceCount_i,
//Enable the gate
output logic GateEnable_o
)
总体设计思想如下。当我接收到NoGoodError_i的正沿时,启动一个计数器,并通过EncoderSignal_i信号的正沿向上计数到DistanceCount_i计数。这看起来非常简单,然而我的设计挑战变成了我可以在完成前一次计数之前获得另一个NoGoodError_i。因此,我需要一种方法在行和开始计数器中获得高达10 NoGoodError_i的信号。然后,一旦计数器过期(滚动),就重新使用它们。请任何设计技巧将非常感谢。
发布于 2018-06-05 04:23:13
我会使用一个计数器数组,每个计数器都有一个“忙”位。如果设置了该位,则计数器正在运行。
接下来,您将使用模10索引,该索引用于设置繁忙位。
如果您要启动的计数器仍处于忙碌状态,我将发出一个标记。
我只是在运行中输入了以下内容:语法不解析,可能会出现打字错误(甚至有可能):
reg [DATA_BITS-1:0] counter [0:9];
reg [9:0] busy;
reg [3:0] cntr_to_start;
always @(posedge Clk_i or posedge Reset_i)
begin
if (Reset_i)
begin
busy <= 10'b0;
for (i=0; i=<10; i=i+1)
counter[i] <= 'b0;
cntr_to_start <= 'b0;
end
begin
// Run a counter if it's busy flag is set
// At max (rollover) stop and clear the busy flag
for (i=0; i<10; i=i+1)
begin
if (busy[i])
begin
if (counter[i]==(33'b1<<DATA_BITS)-1)
begin
counter[i] <= 1'b0;
busy[i] <= 1'b0;
end
else
counter[i] <= counter[i] + 1;
end
end
// If no good start the next counter
// If we have no next counter: ????
if (NoGoodError_i)
begin
if (busy[cntr_to_start])
// Houston: we have a problem!
// More errors then we have counters
else
begin
busy[cntr_to_start] <= 1'b1;
if (cntr_to_start==9)
cntr_to_start <= 'b0;
else
cntr_to_start <= cntr_to_start + 1;
end
end
end
https://stackoverflow.com/questions/50687209
复制相似问题