Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #959

Verilog macro issue

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Sat, 02 Apr 2011 13:36:12 -0500
From Chris Hinsley <chris.hinsley@gmail.com>
Newsgroups comp.lang.forth
Date Sat, 2 Apr 2011 19:36:12 +0100
Message-ID <2011040219361212758-chrishinsley@gmailcom> (permalink)
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Subject Verilog macro issue
User-Agent Unison/2.1.4
Lines 64
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-D98AGzJo2VItc4QGgsVmAgkkSBVhzmG2RlMM9NNTY0dfjS4M+wGHpdDJG55yn+HTDcFbN7nppx8Lzep!sLSHQWQh+3hpRXtGatfSjcMpWsXo9APMWsPHHiZaHsaAct+3ZAGUcM9uIARWO8JFe8UOLw==
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2650
Xref x330-a1.tempe.blueboxinc.net comp.lang.forth:959

Show key headers only | View raw


Hi folks, I've been a bit quiet recontly, mostly because I've been 
heads down on learning Verilog and moving my CPU from Logisym over to 
it.

I have a question that you Forth Verilog guys might be able to help with.

I have some encoders done like the folowing:

module enc4(i, o);
	input [15:0] i;
	output [3:0] o;
	reg [3:0] o;
	always @(i)
	begin
		o = 4'h0;
		case(i)
		16'b0000000000000010: o = 4'h1;
		16'b0000000000000100: o = 4'h2;
		16'b0000000000001000: o = 4'h3;
		16'b0000000000010000: o = 4'h4;
		16'b0000000000100000: o = 4'h5;
		16'b0000000001000000: o = 4'h6;
		16'b0000000010000000: o = 4'h7;
		16'b0000000100000000: o = 4'h8;
		16'b0000001000000000: o = 4'h9;
		16'b0000010000000000: o = 4'hA;
		16'b0000100000000000: o = 4'hB;
		16'b0001000000000000: o = 4'hC;
		16'b0010000000000000: o = 4'hD;
		16'b0100000000000000: o = 4'hE;
		16'b1000000000000000: o = 4'hF;
		endcase
	end
endmodule

But that's all getting a bit long winded, so I thought I'd do a macro 
to generate any width encoder. But I've hit a problem with the generate 
variable comparison needing to be a constant (that's the FPGA compiler 
error). Here's the code I wanted to write. Any advice for how to 
achieve this macro ?

`define ENCODER(NAME, BITS)			\
module NAME(i, o);							\
	input [((2 ** BITS) - 1):0] i;				\
	output [(BITS - 1):0] o;					\
	genvar n;									\
	generate									\
		for (n = 0; n < (2 ** BITS); n = n + 1) \
		begin									\
			if (i == (2 ** n))					\
				assign o = n;					\
		end									\
	endgenerate								\
endmodule

`ENCODER(enc1, 1)
`ENCODER(enc2, 2)
`ENCODER(enc3, 3)

Chears.

Chris

Back to comp.lang.forth | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-02 19:36 +0100
  Re: Verilog macro issue Jan Coombs <jan_2011-02@murray-microft.co.uk> - 2011-04-02 20:26 +0100
    Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-02 20:31 +0100
      Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-02 20:43 +0100
        Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-02 21:36 +0100
          Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-02 22:12 +0100
    Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-02 23:01 +0100
      Re: Verilog macro issue Jan Coombs <jan_2011-02@murray-microft.co.uk> - 2011-04-02 23:33 +0100
        Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-03 03:58 +0100
          Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-03 12:27 +0100
            Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-03 13:20 +0100
              Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-07 23:26 +0100
                Re: Verilog macro issue Jan Coombs <jan_2011-02@murray-microft.co.uk> - 2011-04-10 23:20 +0100
              Re: Verilog macro issue rickman <gnuarm@gmail.com> - 2011-04-11 10:36 -0700
  Re: Verilog macro issue Chris Hinsley <chris.hinsley@gmail.com> - 2011-04-11 20:16 +0100

csiph-web