Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help needed for type conversion in QUARTUS 2

Status
Not open for further replies.

childs

Member level 5
Joined
Apr 28, 2008
Messages
87
Helped
15
Reputation
30
Reaction score
12
Trophy points
1,288
Activity points
1,945
I am having some problems with quartus 2 that i can't solve.... ><

Referring to the short modified code as below, I would like to compare the data in B with A, however the compilation does not allow this comparison, even though both the array A & B are formed by type "BYTE". Any idea how to fix this problem??

......
TYPE BYTE6 IS ARRAY (0 to 5) OF std_logic_vector(7 downto 0);
TYPE BYTE3 IS ARRAY (0 to 2) OF std_logic_vector(7 downto 0);
......
SIGNAL A: BYTE6 := (OTHERS => x"00");
SIGNAL B: BYTE3 := (OTHERS => x"00");
SIGNAL C: std_logic := '0';
......

IF (A(0 to 2) = B) THEN
C <= '1';
ELSE
C <= '0';
END IF;

......
 

try this
Code:
IF ((A(0)=B(0)) AND (A(1)=B(1)) AND (A(2)=B(2))) then
     C <= '1';
ELSE
     C <= '0';
END IF;
 

Re: help needed for type conversion in qu(at)rtus 2

nand_gates said:
try this
Code:
IF ((A(0)=B(0)) AND (A(1)=B(1)) AND (A(2)=B(2))) then
     C <= '1';
ELSE
     C <= '0';
END IF;

Thanks. This work fine but somehow I will deal with larger size of such comparison so the code shall be quite long...

However currently I had fixed the problem by referring how the type "std_logic_vector" is being declared in "stad_logic_1164" package. So now i declared my code following the below style as:

........
TYPE BYTE_VECTOR IS ARRAY (NATURAL RANGE <>) OF std_logic_vector(7 downto 0);

SIGNAL A: BYTE_VECTOR(0 to 5) := (OTHERS => x"00");
SIGNAL B: BYTE_VECTOR(0 to 2) := (x"00",x"00",x"00");
........

IF (A(0 to 2) = B) THEN
C <= '1';
ELSE
C <= '0';
END IF;

........

And it is working fine for now :)
 

I was in doubt, if VHDL would allow comparison of arrays, but I found it supported explicitely in the IEEE specification. However
The operands of each relational operator must be of the same type.
This is the problem with your first approch, cause two separate type definition are not necessarily recognized as same type.

A more general solution would be by using an iteration like:
Code:
C<='1';
FOR I IN 0 TO 2 LOOP
  IF A(I) /= B(I) THEN
    C<= '0';
  END IF;
END LOOP;
The solution is somewhat long-winded but flexible.
 

    childs

    Points: 2
    Helpful Answer Positive Rating
Re: help needed for type conversion in qu(at)rtus 2

I like this solution as this is more general and flexible. Thx. :)

Somehow I only successfully compiled but not yet try to synthesis the 2nd method i used, I guess it shall be able to work :p


FvM said:
I was in doubt, if VHDL would allow comparison of arrays, but I found it supported explicitely in the IEEE specification. However
The operands of each relational operator must be of the same type.
This is the problem with your first approch, cause two separate type definition are not necessarily recognized as same type.

A more general solution would be by using an iteration like:
Code:
C<='1';
FOR I IN 0 TO 2 LOOP
  IF A(I) /= B(I) THEN
    C<= '0';
  END IF;
END LOOP;
The solution is somewhat long-winded but flexible.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top