1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Verilogのgenerate文でのマルチプレクサの記述

Last updated at Posted at 2013-01-12

generate文を使ったcase文の代替です。入力bit幅が多い場合には使えるかもしれませんが、遅延は大きくなります。レジスタファイル記述などに使えそうです。

Modelsim altera 10.1bでのSimulationとQuartus12.1での合成、動作(7segに表示)を確認しました。

gentest.v
`timescale 1 ns / 10 ps 

module gentest(/*AUTOARG*/
   // Outputs
   value,
   // Inputs
   idx
   );
   input [3:0] idx;
   output [7:0] value;   
   
   wire [7:0]	tmp[15:0];
   wire [7:0]	tmpx[15:0];
   
   genvar 	i,j;

   generate
      for(i=0;i<16;i=i+1)begin :rep_tmpx
	 assign tmpx[i]=(idx==i)?(i<<1):0;
      end
      for(j=0;j<16;j=j+1)begin :rep_tmp
      	 if(j==0)assign tmp[j]=tmpx[j];
      	 else assign tmp[j]=tmp[j-1]|tmpx[j];
      end
   endgenerate
   
   assign value=tmp[15];
  
endmodule // gentest

module test();
   reg   clock ;
   reg [3:0] idx;

   wire [7:0] value;
   
   initial forever begin
      clock   <= 1;   
      #2 
      clock   <= 0;
      #2      ;
   end
   
   gentest g1(/*AUTOINST*/
	      // Outputs
	      .value			(value[7:0]),
	      // Inputs
	      .idx			(idx[3:0]));
   
   integer i;
   initial begin
      $display("start.");
      for(i=0;i<16;i=i+1)begin
        idx=i;        
        $display("%d",value);
        @(posedge clock);
      end 
      $display("end.");
      $finish();
   end
   
endmodule

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?