range attribute on integer failure

O

Olaf

Guest
Hi,

the following snippet won't pass the modelsim compiler, what's wrong
with it?

---8<---
entity counter is
generic(
BITWIDTH : integer
);
port(
...
rld_value : in natural range 2**BITWIDTH-1 downto 0
);
end counter ;


architecture rtl of counter is
...
begin

process (clk)
variable count : natural range rld_value'range; -- XXX
...

--->8---

Error: Attribute "range" requires an array prefix.

is this a syntactically problem?

Thanks,
Olaf
 
On Jul 7, 5:37 am, Olaf <is...@inter.net> wrote:
Hi,

the following snippet won't pass the modelsim compiler, what's wrong
with it?
It's nice when a posted question has the answer already included (see
error message below).

Error: Attribute "range" requires an array prefix.
Since 'rld_value' is not an array, you can't take the 'range of it.

is this a syntactically problem?
Modelsim wouldn't have complained if it wasn't.

In this particular situation, there really isn't a good way to get
'count' and 'rld_value' to have the same range without copy/pasting
the equation for the range.

KJ
 
On Mon, 7 Jul 2008 05:19:56 -0700 (PDT), KJ <kkjennings@sbcglobal.net>
wrote:

On Jul 7, 5:37 am, Olaf <is...@inter.net> wrote:
Hi,

the following snippet won't pass the modelsim compiler, what's wrong
with it?
is this a syntactically problem?


Modelsim wouldn't have complained if it wasn't.

In this particular situation, there really isn't a good way to get
'count' and 'rld_value' to have the same range without copy/pasting
the equation for the range.
Possibly create a subtype declaration. I think you will have to put it
in a package so that it can be made visible to both places.
Untested here...

package mytypes is
constant MY_WIDTH : natural := 8;
subtype my_natural is natural range 2**MY_WIDTH-1 downto 0;
....
end package mytypes;

--------------------------

library mylib; -- compile the package into mylib
use mylib.mytypes.all;

-- or compile the package into work, if you don't want to create mylib
-- use work.mytypes.all;
-- but IMO work tends to get pretty untidy in a large project

entity counter is
generic(
BITWIDTH : MY_WIDTH
);
port(
...
rld_value : in my_natural
);
end counter ;

architecture rtl of counter is
...
begin

process (clk)
variable count : my_natural;
....


- Brian
 
On Tue, 8 Jul 2008 17:12:24 -0400, "KJ" <kkjennings@sbcglobal.net>
wrote:

"Brian Drummond" <brian_drummond@btconnect.com> wrote in message
news:mid5741lq2qovj6ehttuqljm9r2l4u61f6@4ax.com...
On Mon, 7 Jul 2008 05:19:56 -0700 (PDT), KJ <kkjennings@sbcglobal.net
wrote:

In this particular situation, there really isn't a good way to get
'count' and 'rld_value' to have the same range without copy/pasting
the equation for the range.

Possibly create a subtype declaration. I think you will have to put it
in a package so that it can be made visible to both places.
Untested here...

package mytypes is
constant MY_WIDTH : natural := 8;
subtype my_natural is natural range 2**MY_WIDTH-1 downto 0;
...
end package mytypes;


Then you lose the ability to instantiate different instances with different
values for the generic...until packages accept generics...which I suppose if
VHDL-200X gets the final approval will happen.
True; in solving the immediate problem it causes another one.

I suspect the OP's problem may be better solved with type
numeric_std.unsigned instead of natural for the port and "count"; since
this type is an array of std_logic, it will accept a range attribute
(with a simpler expression!)

- Brian
 
Perhaps a hybrid approach would work, especially if the OP has more
that one variable to declare of that range.

Define a subtype in the architecture using the same expression of
BITWIDTH for the range of the subtype. Then you can easily declare
variables or signals of that subtype. Since the subtype is defined
within the architecture, and dependent upon the generic, different
instantiations of the entity can have different generic values.

I would also limit the generic's range to "natural range 1 to 31", so
that it cannot be set to a value that results in an integer overflow
or otherwise useless range on the subtype.

Andy
 

Welcome to EDABoard.com

Sponsor

Back
Top