将VHDL代码转换为Verilog

时间:2012-10-11 09:55:11

标签: vhdl verilog

我必须将以下vhdl程序翻译成verilog:

ENTITY ascounter IS
  PORT (CLK :IN STD_LOGIC;
      QoutA, QoutB, QoutC, QoutD :OUT STD_LOGIC);
END ascounter;
ARCHITECTURE circuit OF ascounter IS
   SIGNAL CLKnot, QBnot, QCnot, QDnot, QA, QB, QC, QD, HIGH :STD_LOGIC;
   BEGIN
      HIGH<='1';
      CLKnot<=NOT CLK;
      QDnot<=NOT QD; 
      QCnot<=NOT QC;
      QBnot<=NOT QB;
      FFD: JKFF PORT MAP (J=>HIGH, K=>HIGH, CLK=>CLKnot, CLRN=>HIGH, PRN=>HIGH, Q=>QD);
      FFC: JKFF PORT MAP (J=>HIGH, K=>HIGH, CLK=>QDnot, CLRN=>HIGH, PRN=>HIGH, Q=>QC);
      FFB: JKFF PORT MAP (J=>HIGH, K=>HIGH, CLK=>QCnot, CLRN=>HIGH, PRN=>HIGH, Q=>QB);
      FFA: JKFF PORT MAP (J=>HIGH, K=>HIGH, CLK=>QBnot, CLRN=>HIGH, PRN=>HIGH, Q=>QA);
      QoutA<=QA;
      QoutB<=QB;
      QoutC<=QC;
      QoutD<=QD;
END circuit;

我已经做到了:

  ...
  assign HIGH = 1'b1;
  assign CLKnot = (~CLK);
  assign QDnot = (~QD);
  assign QCnot = (~QC);
  assign QBnot = (~QB);

 flipflop_jk FFD(.J(HIGH), .K(HIGH), .CK(CLKnot), .CLN(HIGH), .PRN(HIGH), .Q(QD));

 flipflop_jk FFC(.J(HIGH), .K(HIGH), .CK(QDnot), .CLN(HIGH), .PRN(HIGH), .Q(QC));

 flipflop_jk FFB(.J(HIGH), .K(HIGH), .CK(QCnot), .CLN(HIGH), .PRN(HIGH), .Q(QB));

 flipflop_jk FFA(.J(HIGH), .K(HIGH), .CK(QBnot), .CLN(HIGH), .PRN(HIGH), .Q(QA));

 assign QoutA = QA;
 assign QoutB = QB;
 assign QoutC = QC;
 assign QoutD = QD;

我使用了jk flipflop:

always @(CK or PRN or CLN)
 begin
  if (PRN == 1'b0)
  begin
     Q <= 1'b1 ; 
  end
  else if (CLN == 1'b0)
  begin
     Q <= 1'b0 ; 
  end
  else if (CK == 1'b0)  
  begin
     if (J == 1'b1 & K == 1'b1)
     begin
        Q <= ~Q ; 
     end
     else if (J == 1'b1 & K == 1'b0)
     begin
        Q <= 1'b1 ; 
     end
     else if (J == 1'b0 & K == 1'b1)
     begin
        Q <= 1'b0 ; 
     end 
  end 
 end 

当我尝试运行模拟时,我得到类似这样的错误,但我无法理解错误在哪里。

enter image description here

有没有人有任何想法?
非常感谢你!

2 个答案:

答案 0 :(得分:1)

在flipflop_jk定义中使用边缘灵敏度更合适。此外,您还包含一个异步清除信号,其复位信号的值不同。我的例子显示了同步清除。

您的信号捕获不会显示您的重置信号。我假设这是最初的低,然后你在时间0之后把它拿高。把Q设置为已知值。

module flipflop_jk(
  input      CK,
  input      PRN,
  input      CLN,
  input      J,
  input      K,
  output reg Q
);

always @(posedge CK or negedge PRN) begin
  if (PRN == 1'b0) begin
     Q <= 1'b1 ; 
  end
  else begin
    if (CLN == 1'b0) begin
      Q <= 1'b0 ; 
    end
    else if (J == 1'b1 & K == 1'b1) begin
      Q <= ~Q ; 
    end
    else if (J == 1'b1 & K == 1'b0) begin
      Q <= 1'b1 ; 
    end
    else if (J == 1'b0 & K == 1'b1) begin
      Q <= 1'b0 ; 
    end 
  end
end
endmodule

答案 1 :(得分:0)

我假设您已在jk flipflop模块中将Q声明为reg。默认情况下,在Verilog中,reg初始化为x。由于jk触发器的JKCLNPRN输入高(1'b1),因此执行的唯一语句是{{ 1}}(当Q <= ~Q ;变低时)。由于CK的反转仍为Qx仍然未知。您从未将x设置为已知值。