newbie question about type declaration

M

Max

I have a problem with types:

-----8<-----------
entity driver is
Port ( data : inout integer range 0 to 255;
clk : in std_logic);
end driver;

architecture Behavioral of driver is

type data_type is range 0 to 255;
signal data_reg: data_type;

begin

process (clk)
begin
if rising_edge(clk) then
--- some code here
data <= data_reg;
end if;
end process;
--------8<------------

the error is:
ERROR:HDLParsers:800 - driver.vhd Line xx. Type of data_reg is
incompatible with type of data.

How can I solve this problem?

thanks
 
R

Renaud Pacalet

Max said:
I have a problem with types:

-----8<-----------
entity driver is
Port ( data : inout integer range 0 to 255;
clk : in std_logic);
end driver;

architecture Behavioral of driver is

type data_type is range 0 to 255;

This declares a new type that as nothing to do with Integers.

subtype data_type is Integer range 0 to 255;

declares a subtype of type Integer and solves your problem.

Regards,

PS: inout mode for an integer port???
 
C

Colin Marquardt

Renaud Pacalet said:
This declares a new type that as nothing to do with Integers.

subtype data_type is Integer range 0 to 255;

declares a subtype of type Integer and solves your problem.

And best make that subtype declaration in a package and also use it
for the data port in the entity. The magic number 255 should probably
also be derived from a constant like DATA_WIDTH. Next, consider using
natural or positive instead of integer. All this makes the code easier
to read and less error prone.

HTH,
Colin
 

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,405
Messages
2,571,535
Members
48,796
Latest member
shadowoftheunknown

Latest Threads

Top