FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-17-2008, 01:00 AM
Bill Burris
Guest
 
Posts: n/a
Default Multiple Instances

Is there a compact way of creating multiple instances of a circuit?

Instead of repeating something like the following 32 times, can I do
this in some kind of a loop with indexing.

Channel U_Channel0 ( .clk(clk),
.reset(reset),
.delay_time(delay_time),
.gate_width(gate_width),
.threshold(threshold),
.ch(5'd0),
.din(db[0]),
.dout(dout[0]),
.empty(empty),
.half_full(half_full),
.full(full) );

Channel U_Channel1 ( .clk(clk),
.reset(reset),
.delay_time(delay_time),
.gate_width(gate_width),
.threshold(threshold),
.ch(5'd1),
.din(db[1]),
.dout(dout[1]),
.empty(empty),
.half_full(half_full),
.full(full) );

thanks

Bill
Reply With Quote
  #2 (permalink)  
Old 01-17-2008, 02:23 AM
Dwayne Dilbeck
Guest
 
Posts: n/a
Default Re: Multiple Instances

You want to use generate. See below. (NOTE: I did not do a syntax check)


generate
genvar i;
for (i=0; i<=32; i = i +1)
begin : u
Channel U_Channel0 ( .clk(clk),
.reset(reset),
.delay_time(delay_time),
.gate_width(gate_width),
.threshold(threshold),
.ch(i),
.din(db[i]),
.dout(dout[i]),
.empty(empty),
.half_full(half_full),
.full(full) );
end
endgenerate


"Bill Burris" <[email protected]> wrote in message
news:fmm5n1$dra$[email protected]..
> Is there a compact way of creating multiple instances of a circuit?
>
> Instead of repeating something like the following 32 times, can I do this
> in some kind of a loop with indexing.
>
> Channel U_Channel0 ( .clk(clk),
> .reset(reset),
> .delay_time(delay_time),
> .gate_width(gate_width),
> .threshold(threshold),
> .ch(5'd0),
> .din(db[0]),
> .dout(dout[0]),
> .empty(empty),
> .half_full(half_full),
> .full(full) );
>
> Channel U_Channel1 ( .clk(clk),
> .reset(reset),
> .delay_time(delay_time),
> .gate_width(gate_width),
> .threshold(threshold),
> .ch(5'd1),
> .din(db[1]),
> .dout(dout[1]),
> .empty(empty),
> .half_full(half_full),
> .full(full) );
>
> thanks
>
> Bill



Reply With Quote
  #3 (permalink)  
Old 01-17-2008, 05:05 AM
[email protected]
Guest
 
Posts: n/a
Default Re: Multiple Instances

On Jan 16, 7:00*pm, Bill Burris <wbur...@ualberta.ca> wrote:
> Is there a compact way of creating multiple instances of a circuit?
>
> Instead of repeating something like the following 32 times, can I do
> this in some kind of a loop with indexing.


In addition to the generate loop suggested by Dwayne, you can also
declare instance arrays if your connection scheme is simple and
regular enough. The only problem for your case would be the
incrementing channel number, which pretty much requires a generate
loop if you want to make the number of instances parameterizable.


Reply With Quote
  #4 (permalink)  
Old 01-17-2008, 06:55 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Multiple Instances

On Jan 16, 8:05 pm, sh...@cadence.com wrote:
> On Jan 16, 7:00 pm, Bill Burris <wbur...@ualberta.ca> wrote:
>
> > Is there a compact way of creating multiple instances of a circuit?

>
> > Instead of repeating something like the following 32 times, can I do
> > this in some kind of a loop with indexing.

>
> In addition to the generate loop suggested by Dwayne, you can also
> declare instance arrays if your connection scheme is simple and
> regular enough. The only problem for your case would be the
> incrementing channel number, which pretty much requires a generate
> loop if you want to make the number of instances parameterizable.


I like the array of instances for things like this - even when dealing
with
parameterized numbers. It CAN be more concise than a generate,
depending on
how your data is organized.

Bill, the trick is handling the signals that are unique for
each instance. For each of these you need to create a single "wide"
version
of the net, with all the signals concatenated. I'll assume your din,
dout
signals are 8 bits:

// Inputs
wire [ 2 * 5 - 1 : 0 ] ch_wide = { 5'd1, 5'd0 };
wire [ 2 * 8 - 1 : 0 ] din_wide = { db[1], db[0] };

// Outputs
wire [ 2 * 8 - 1 : 0 ] dout_wide;
assign { dout[ 1 ], dout[ 0 ] } = dout_wide;

The above becomes cleaner and easier in SystemVerilog with packed
arrays:

// Inputs
wire [ 1 : 0 ] [ 4 : 0 ] ch_wide = { 5'd1, 5'd0 };
wire [ 1 : 0 ] [ 7 : 0 ] din_wide = { db[1], db[0] };

// Outputs
wire [ 1 : 0 ] [ 7 : 0 ] dout_wide;
assign { dout[ 1 ], dout[ 0 ] } = dout_wide;

If the instance number ( i.e 2 above) is another parameter, it get's
trickier -
you'd probably need to do the assignments procedurally, but it still
works.
Again you'll find SystemVerilog packed arrays a big help here.

Then, the instanciation looks like:

Channel U_Channel[ 1 : 0 ]
(
.clk(clk),
.reset(reset),
.delay_time(delay_time),
.gate_width(gate_width),
.threshold(threshold),
.ch( ch_wide ),
.din( din_wide ),
.dout( dout_wide ),
.empty(empty),
.half_full(half_full),
.full(full)
);

It all depends on where the data is coming from / used. I tend to
use the array of instances more, so the data passing back and forth
is already in a "wide" form (or packed array in SystemVerilog) and the
extra assignments are not needed.

Generates are good to, but sometimes indexing into a wide bus within
the
loop can get ugly.

--Mark

Reply With Quote
  #5 (permalink)  
Old 01-17-2008, 07:08 PM
Bill Burris
Guest
 
Posts: n/a
Default Re: Multiple Instances

Thanks for the help everyone. The books I have don't cover generate and
instance arrays.

Bill
Reply With Quote
  #6 (permalink)  
Old 01-17-2008, 07:11 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Multiple Instances

On Jan 17, 10:55 pm, "gtw...@pacbell.net" <gtw...@pacbell.net> wrote:
> On Jan 16, 8:05 pm, sh...@cadence.com wrote:
>
> > On Jan 16, 7:00 pm, Bill Burris <wbur...@ualberta.ca> wrote:

>
> > > Is there a compact way of creating multiple instances of a circuit?

>
> > > Instead of repeating something like the following 32 times, can I do
> > > this in some kind of a loop with indexing.

>
> > In addition to the generate loop suggested by Dwayne, you can also
> > declare instance arrays if your connection scheme is simple and
> > regular enough. The only problem for your case would be the
> > incrementing channel number, which pretty much requires a generate
> > loop if you want to make the number of instances parameterizable.

>
> I like the array of instances for things like this - even when dealing
> with
> parameterized numbers. It CAN be more concise than a generate,
> depending on
> how your data is organized.
>
> Bill, the trick is handling the signals that are unique for
> each instance. For each of these you need to create a single "wide"
> version
> of the net, with all the signals concatenated. I'll assume your din,
> dout
> signals are 8 bits:
>
> // Inputs
> wire [ 2 * 5 - 1 : 0 ] ch_wide = { 5'd1, 5'd0 };
> wire [ 2 * 8 - 1 : 0 ] din_wide = { db[1], db[0] };
>
> // Outputs
> wire [ 2 * 8 - 1 : 0 ] dout_wide;
> assign { dout[ 1 ], dout[ 0 ] } = dout_wide;
>
> The above becomes cleaner and easier in SystemVerilog with packed
> arrays:
>
> // Inputs
> wire [ 1 : 0 ] [ 4 : 0 ] ch_wide = { 5'd1, 5'd0 };
> wire [ 1 : 0 ] [ 7 : 0 ] din_wide = { db[1], db[0] };
>
> // Outputs
> wire [ 1 : 0 ] [ 7 : 0 ] dout_wide;
> assign { dout[ 1 ], dout[ 0 ] } = dout_wide;
>
> If the instance number ( i.e 2 above) is another parameter, it get's
> trickier -
> you'd probably need to do the assignments procedurally, but it still
> works.
> Again you'll find SystemVerilog packed arrays a big help here.
>
> Then, the instanciation looks like:
>
> Channel U_Channel[ 1 : 0 ]
> (
> .clk(clk),
> .reset(reset),
> .delay_time(delay_time),
> .gate_width(gate_width),
> .threshold(threshold),
> .ch( ch_wide ),
> .din( din_wide ),
> .dout( dout_wide ),
> .empty(empty),
> .half_full(half_full),
> .full(full)
> );
>
> It all depends on where the data is coming from / used. I tend to
> use the array of instances more, so the data passing back and forth
> is already in a "wide" form (or packed array in SystemVerilog) and the
> extra assignments are not needed.
>
> Generates are good to, but sometimes indexing into a wide bus within
> the
> loop can get ugly.
>
> --Mark


HI Mike,

what this statement will do in the code above u have mentioned.
Channel U_Channel[ 1 : 0 ]

Reply With Quote
  #7 (permalink)  
Old 01-17-2008, 08:43 PM
Dwayne Dilbeck
Guest
 
Posts: n/a
Default Re: Multiple Instances

You probably have books written bassed on the verilog 93.

The generate and instance arrays were added later.

"Bill Burris" <[email protected]> wrote in message
news:fmo5j1$d5j$[email protected]..
> Thanks for the help everyone. The books I have don't cover generate and
> instance arrays.
>
> Bill



Reply With Quote
  #8 (permalink)  
Old 01-17-2008, 08:51 PM
Dwayne Dilbeck
Guest
 
Posts: n/a
Default Re: Multiple Instances

The code mike created will do exactly what the orignal poster code will do.
It creates two instances of "Channel". The major difference are the names
before the names were U_Channel0, no the name would be U_Channel[0]. Also
previously the use had to code the correct bits to the instatiated module.
Now the connects are grabbed automatically from an array. The developer
would have to code the arrays manually still.

I like the generate method, but that is personal. I started with VHDL and
for...generate statements, therfore the generate in verilog feels more
comfortable to me.

<[email protected]> wrote in message
news:[email protected]..
> On Jan 17, 10:55 pm, "gtw...@pacbell.net" <gtw...@pacbell.net> wrote:
>> On Jan 16, 8:05 pm, sh...@cadence.com wrote:
>>
>> > On Jan 16, 7:00 pm, Bill Burris <wbur...@ualberta.ca> wrote:

>>
>> > > Is there a compact way of creating multiple instances of a circuit?

>>
>> > > Instead of repeating something like the following 32 times, can I do
>> > > this in some kind of a loop with indexing.

>>
>> > In addition to the generate loop suggested by Dwayne, you can also
>> > declare instance arrays if your connection scheme is simple and
>> > regular enough. The only problem for your case would be the
>> > incrementing channel number, which pretty much requires a generate
>> > loop if you want to make the number of instances parameterizable.

>>
>> I like the array of instances for things like this - even when dealing
>> with
>> parameterized numbers. It CAN be more concise than a generate,
>> depending on
>> how your data is organized.
>>
>> Bill, the trick is handling the signals that are unique for
>> each instance. For each of these you need to create a single "wide"
>> version
>> of the net, with all the signals concatenated. I'll assume your din,
>> dout
>> signals are 8 bits:
>>
>> // Inputs
>> wire [ 2 * 5 - 1 : 0 ] ch_wide = { 5'd1, 5'd0 };
>> wire [ 2 * 8 - 1 : 0 ] din_wide = { db[1], db[0] };
>>
>> // Outputs
>> wire [ 2 * 8 - 1 : 0 ] dout_wide;
>> assign { dout[ 1 ], dout[ 0 ] } = dout_wide;
>>
>> The above becomes cleaner and easier in SystemVerilog with packed
>> arrays:
>>
>> // Inputs
>> wire [ 1 : 0 ] [ 4 : 0 ] ch_wide = { 5'd1, 5'd0 };
>> wire [ 1 : 0 ] [ 7 : 0 ] din_wide = { db[1], db[0] };
>>
>> // Outputs
>> wire [ 1 : 0 ] [ 7 : 0 ] dout_wide;
>> assign { dout[ 1 ], dout[ 0 ] } = dout_wide;
>>
>> If the instance number ( i.e 2 above) is another parameter, it get's
>> trickier -
>> you'd probably need to do the assignments procedurally, but it still
>> works.
>> Again you'll find SystemVerilog packed arrays a big help here.
>>
>> Then, the instanciation looks like:
>>
>> Channel U_Channel[ 1 : 0 ]
>> (
>> .clk(clk),
>> .reset(reset),
>> .delay_time(delay_time),
>> .gate_width(gate_width),
>> .threshold(threshold),
>> .ch( ch_wide ),
>> .din( din_wide ),
>> .dout( dout_wide ),
>> .empty(empty),
>> .half_full(half_full),
>> .full(full)
>> );
>>
>> It all depends on where the data is coming from / used. I tend to
>> use the array of instances more, so the data passing back and forth
>> is already in a "wide" form (or packed array in SystemVerilog) and the
>> extra assignments are not needed.
>>
>> Generates are good to, but sometimes indexing into a wide bus within
>> the
>> loop can get ugly.
>>
>> --Mark

>
> HI Mike,
>
> what this statement will do in the code above u have mentioned.
> Channel U_Channel[ 1 : 0 ]
>



Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
64-bit wide multiple port instances Jake Verilog 3 09-12-2007 12:06 AM
Reading files in multiple instances of a ROM model [email protected] Verilog 5 06-13-2005 09:04 AM
Multiple Mux instances by parameter. Roy Verilog 2 10-21-2003 07:30 PM
multiple task 'instances' Steven Sharp Verilog 2 07-24-2003 02:12 AM
multiple task 'instances' Eric Peterson Verilog 0 07-21-2003 06:48 PM


All times are GMT +1. The time now is 03:16 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved