编写RTL逻辑问题

问题描述 投票:-1回答:1

假设我有一条总线B。如果B的对应索引为1,我想创建一个新的总线C,其信号将延迟一个与其索引成比例的幅度。总线B(宽度5)的值为10111,并且B永远保持在该值。现在我希望C像这样:

clk 0: 00001
clk 1: 00011
clk 2: 00111
clk 3: 10111

((请注意,总线B中的第3位为0,因此,在位置2之后,其C的MSB(位置4)在下一个时钟应为高)。

下面显示的是相应的波形。


B[0] ,,,|'''''''''''''''''''''''''''''''''
B[1] ,,,|'''''''''''''''''''''''''''''''''
B[2] ,,,|'''''''''''''''''''''''''''''''''
B[3] ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
B[4] ,,,|'''''''''''''''''''''''''''''''''

clk   ,,|''|,,|''|,,|''|,,|''|,,|''|,,|''|

C[0] ,,,|'''''''''''''''''''''''''''''''''
C[1] ,,,,,,,,,|'''''''''''''''''''''''''''
C[2] ,,,,,,,,,,,,,,,|'''''''''''''''''''''
C[3] ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
C[4] ,,,,,,,,,,,,,,,,,,,,,,|''''''''''''''

如何使用systemverilog在synthesizable RTL逻辑中对此建模并总是阻塞。我正在寻找与此类似的东西(这只是一个伪代码:]]

Logic[width-1:0][width-1:0] temp;
logic hit_zero; //This is a variable seen and modified by all the generated always blocks(I am not sure if that's allowed)
generate
   for (genvar i = 0; i < width; i++) begin
        always @(posedge clk) begin
              if (B[i] == 1) begin
                 temp[i] <= temp[i] << i;
                 if (hit_zero) begin
                   temp[i] <= temp[i] << (pos+1);
                   hit_zero <= 0;
                 end
                 pos <= i;
              end else begin
                 temp[i] <= temp[i] << i;
                 hit_zero <= 1;  
              end
              temp[i][0] <= B[i];
        end
   end
  endgenerate
  generate 
   for (genvar i = 0; i < width; i++) begin 
    assign C[i] = temp[i][i];
   end
  endgenerate

假设我有一条总线B。如果B的对应索引为1,我想创建一个新的总线C,其信号将延迟一个与其索引成比例的幅度。让我用一个...解释一下]

verilog system-verilog register-transfer-level
1个回答
0
投票

我提出了一个Always块的示例,该块似乎至少在仿真中起到了您想要的作用。它应该是可合成的,尽管我没有尝试过。它期望一个复位信号来设置初始值。因此,您可以尝试将其用作探索的基础。

[需要pos指向当前位位置,该位置根据Bincr)的位状态递增。

© www.soinside.com 2019 - 2024. All rights reserved.