range attribute on integer failure

O

Olaf

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
 
K

KJ

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
 
K

KJ

Brian Drummond said:
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.

KJ
 
A

Andy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top