【问题标题】:Verilog Decoder with single inputs/outputs, not vector具有单个输入/输出的 Verilog 解码器,而不是矢量
【发布时间】:2016-06-27 13:22:21
【问题描述】:

我找到了这个用于温度计解码器的 verilog 代码(在代码编码器中,但这是错误的)。

我想根据节奏调整它,从中生成一个网表。 我的问题是,实际代码会生成 [7:0] + 1 输入和 [3:0] 输出。

我想要的是一个具有 8 + 1 个单输入和 4 个单输出的模块:

module thermometer_encoder_8bit(
 out0,out1,out2,out3, //  4-bit binary Output
 in0,in1,in2,in3,in4,in5,in6,in7, //  8-bit Input
 enable       //  Enable for the encoder
 );

 input  enable;
 input in0,in1,in2,in3,in4,in5,in6,in7;
 output out0,out1,out2,out3;

 reg out0,out1,out2,out3;
 ... 

这是实际的、未改编的代码:

module thermometer_encoder_8bit(
  binary_out , //  4 bit binary Output
  encoder_in , //  8-bit Input
  enable       //  Enable for the encoder
  );
  output [3:0] binary_out  ;
  input  enable ; 
  input [7:0] encoder_in ; 

  reg [3:0] binary_out ;

  always @ (enable or encoder_in)
  begin
  binary_out = 0;                 // 0000 0000
  if (enable) begin
     case (encoder_in) 

       8'b00000001 : binary_out = 1;  // 0000 0001
       8'b00000011 : binary_out = 2;  // 0000 0011
       8'b00000111 : binary_out = 3;  // 0000 0111
       8'b00001111 : binary_out = 4;  // 0000 1111
       8'b00011111 : binary_out = 5;  // 0001 1111
       8'b00111111 : binary_out = 6;  // 0011 1111
       8'b01111111 : binary_out = 7;  // 0111 1111
       8'b11111111 : binary_out = 8;  // 0000 1111

     endcase
   end
  end

endmodule

有没有可能,以一种简单的方式做到这一点?

您好, 达荷马

【问题讨论】:

    标签: verilog digital hardware-programming


    【解决方案1】:

    首先,我没有看到default 声明。

    如果您确定 encoder_in 仅包含案例语句中提到的那些数字,您可以使用类似这样的东西。 binary_out = $clog2(encoder_in + 1)

    【讨论】:

      【解决方案2】:

      我会使用您所需的输入和输出修改现有代码,然后进行分配以将现有逻辑连接到新的输入和输出。我还没有编译这个,所以请谨慎对待。

      module thermometer_encoder_8to4(
        out0 , //  4 bit binary Output
        out1 ,
        out2 ,
        out3 ,
        in0 , //  8-bit Input
        in1,
        in2,
        in3
        in4,
        in5,
        in6,
        in7
        enable       //  Enable for the encoder
        );
        output out0  ;
        output out1;
        output out2;
        output out3;
        input  enable ; 
        input in0;
        input in1;
        input in2;
        input in3;
        input in4;
        input in5;
        input in6;
        input in7;
      
        // Keep the binary_out and use this to drive the new non-vector outs... 
        reg [3:0] binary_out ;
      
        // Here is where we assign the non-vector outs and non-vector ins.
        wire [7:0] encoder_in = {in7,in6,in5,in4,in3,in2,in1,in0};
        assign {out3,out2,out1,out0} = binary_out;
      
        always @ (enable or encoder_in)
        begin
        binary_out = 0;                 // 0000 0000
        if (enable) begin
           case (encoder_in) 
      
             8'b00000001 : binary_out = 1;  // 0000 0001
             8'b00000011 : binary_out = 2;  // 0000 0011
             8'b00000111 : binary_out = 3;  // 0000 0111
             8'b00001111 : binary_out = 4;  // 0000 1111
             8'b00011111 : binary_out = 5;  // 0001 1111
             8'b00111111 : binary_out = 6;  // 0011 1111
             8'b01111111 : binary_out = 7;  // 0111 1111
             8'b11111111 : binary_out = 8;  // 0000 1111
      
           endcase
         end
        end
      
      endmodule
      

      我将添加以下内容,注意这不是您的具体问题,但想知道这是否对您有用。

      在原始模块的实例化时,您可以将各个输入和输出分配为串联向量。

      thermometer_encoder_8bit u0_ thermometer_encoder_8bit 
      (
         binary_out ({out0,out1,out2,out3}), //  4-bit binary Output
         encoder_in ({in0,in1,in2,in3,in4,in5,in6,in7}), //  8-bit Input
         enable     (enable)  //  Enable for the encoder
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-05
        • 1970-01-01
        • 1970-01-01
        • 2020-02-22
        • 1970-01-01
        • 2016-07-19
        相关资源
        最近更新 更多