2

我正在合成一个数字块,我需要一个带有 2 个异步复位的 D 触发器。(原因是我将使用可用时钟驱动一个复位,我将使用第二个复位我的数字块的所有寄存器)我准备了以下代码:

module dff_2rst(q,qn,clk,d, rst,clear);
    input  clk,d, rst, clear ;
    output q,qn;
    reg q,qn;
    always @(posedge clk or posedge rst or posedge clear)    //asynchronous reset    
    begin 
    (* full_case, parallel_case *)  
    case({rst, clear})  
        2'b00: begin 
                q <= d; 
                qn<=~d;
               end
        default: begin     
                    q <= 1'b0;  
                    qn <=1'b1;
                end 
    endcase
    end



endmodule     

但我收到以下错误:

The statements in this 'always' block are outside the scope of the synthesis policy. Only an 'if' statement is allowed at the top level in this always block. (ELAB-302)
*** Presto compilation terminated with 1 errors. ***

我也试过

if(~rst & ~clear)

但我也有错误。

你有想法纠正我的代码吗?非常感谢!

4

2 回答 2

1

在 Verilog RTL 中编写异步复位、设置(清除)触发器的标准方法是:

always @(posedge clk or posedge rst or posedge clear) begin
  if (rst) begin
    // Aysnc Reset
    q <= 'b0 ;
  end
  else if (clear) begin
    // Async Clear 
    q <= 'b0 ;
  end
  else begin
    // Sync logic here
    q <= d;
  end
end

assign qn = ~n;

qn 的小技巧要求它 qn 是一条线,目前定义为一个 reg。reg q,qn;应该只是reg q;

同样对于更简洁的代码,新的标头类型更简洁并避免重复:

module dff_2rst(
    input      clk,
    input      d,
    input      rst,
    input      clear,
    output reg q,
    output     qn );
于 2016-03-11T14:48:59.647 回答
0

谢谢你摩根。你的代码对我很有启发。我无法使用

assign qn=~q; 

因为我得到了错误:

qn is not a valid left-hand side of a continuous assignment.

但是我以以下方式修改了您的代码并且它可以工作:

module dff_2rst(q,qn,clk,d, rst,clear);
    input  clk,d, rst, clear ;
    output q,qn;
    reg q,qn;
    always @(posedge clk or posedge rst or posedge clear)    //asynchronous reset    
//
    begin
        if (rst) begin
         // Aysnc Reset
            q <= 'b0 ; 
            qn<= 'b1 ;   
        end
        else if (clear) begin
        // Async Clear 
            q <= 'b0 ;
            qn<= 'b1 ;
        end
        else begin
        // Sync logic here
            q <= d;
            qn<= ~d;
        end
    end
endmodule
于 2016-03-11T15:46:04.430 回答