Académique Documents
Professionnel Documents
Culture Documents
Types
Access Composite
Array Record
Scalar
Integer Physical
Real Enumerated
Predefined (STANDARD) Data types
• Integer
– Minimum range for any implementation as defined by standard:
- 2,147,483,647 to 2,147,483,647
– Integer assignment example
• Real
– Minimum range for any implementation as defined by standard:
- 1.0E38 to 1.0E38
– Real assignment example
• Physical
– Can be user defined range
– Physical type example
• Array
– Used to collect one or more elements of a similar type in a single
construct
– Elements can be any VHDL data type
– Sample one-dimensional array (vector)
0...element numbers... 31
0 ...array values... 1
VARIABLE X: data_bus;
VARIABLE Y: BIT;
15...element numbers... 0
0 ...array values... 1
VARIABLE X: register;
VARIABLE Y: BIT;
• Access
– Similar to pointers in other languages
– Allows for dynamic allocation of storage (=c.f. malloc in C)
– Useful for simulating queues, fifos, etc. Used for accessing the
file system (see the LINE type, which is an access string type).
count:=new natural;
count.ALL=10;
deallocate(count);
Example: Dynamic Pointers
• Subtype
– Allows for user defined constraints on a data type
– May include entire range of base type
– Assignments that are out of the subtype range result in error
– Subtype example
Type Std_ulogic is ('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-');
'U' -- Uninitialized
'X' -- Forcing unknown
'0' -- Forcing zero
'1' -- Forcing one
'Z' -- High Impedance
'W' -- Weak Unknown
'L' -- Weak Low
'H' -- Weak High
'-' -- Don’t Care
VOH VH
VDD R
VL
VOH V=VOH
V
R=ROH
VL
VSS
Representation of 1’s and 0’s
Ri
~10 Mohms => 'Z'
Vres
<0.8V >0.8V,<2.4V >2.4V - TTL
Rres <10% >10%, <90% >90% - CMOS (% of VDD-VSS)
b<="000000010010";
b<=B"000000010010";
b<=B"0000_0001_0010";
b<=X"012"; -- Hexadecimal assignment
b<=O"0022"; -- Octal Assignment
Multi-dimensional Vector & Array
assignments
subtype instruction:bit_vector(31 downto 0);
signal regs:array(0 to 15) of instruction;
regs(2)<=regs(0)+regs(1);
op1<="0000";
instruction 31..24 23..20 19..16 15..12 11..0
op2<="0001"; op1 op2 op3
op3<="0010";
ADD: -- reg(op1)<=reg(op2)+reg(op3)
reg(bit2int(op1))<=reg(bit2int(op2))+reg(bit2int(op3));
-- reg(0)<=reg(1)+reg(2)
Aggregates
signal rec:rec_type:=(1,1.0,"1111");
Signal a,b,cin,cout,sum:std_logic;
Process(a,b,cin)
variable carry:std_logic;
begin
carry:=(a AND b) OR (a AND cin) OR (b AND cin);
(cout,sum)<=carry & (a XOR b XOR cin);
End process;
Left bit Right bit
Type Attributes
Integer’high = 2,147,483,647
Integer’low = -2,147,483,647
Bit’left = '0'
Bit’right = '1'
Array Type attributes
a_type’range = 7 downto 0
a_type’reversed_range = 0 to 7
a_type’length = 8
Type conversion (Similar Base)
signal i:integer;
signal r:real;
i<=integer(r);
r<=real(i);
Type conversion (Same Base)
signal i:integer;
signal b:bit_vector(3 downto 0)
i<=bits2int(b);
b<=int2bits(i,4);
Example: Integer to Bits and vice
versa
package my_package is
Function int2bits(value:integer;ret_size:integer) return bit_vector;
Function bits2int(value:bit_vector) return integer;
end my_package;
Packages
VHDL Hierarchy
Package
Concurrent Process
Concurrent
Statements
Statements
Sequential Statements
VHDL Packages
• Packages encapsulate elements that can be globally shared among
two or more design units
• A package consists of two parts
Definition of all
elements contained
in the package
Packages
• What can you put in a package?
– Subprograms (i.e., functions and procedures)
– Data and type declarations such as
• User record definitions
• User types and enumerated types
• Constants
• Files
• Aliases
• Attributes
– Component declarations
• Entities and Architectures cannot be declared or defined in a
package
• To use a package, make it visible via the “use” language construct
Subprograms
END add_bits3;
Name of procedure
Procedure calling parameters
• Logical operators
– AND, OR, NAND, NOR, XOR, XNOR (XNOR in VHDL’93 only !!!)
• Relational operators
– =, /=, <, <=, >, >=
• Addition operators
– +, -, &
• Multiplication operators
– *, /, mod, rem
• Miscellaneous operators
– **, abs, not
Synthesis of Logical Operators
...
signal A, B, C: BIT_VECTOR(3 downto 0);
signal D, E, F, G: BIT_VECTOR(1 downto 0);
signal H, I, J, K: BIT;
signal L, M, N, O, P: BOOLEAN;
...
A <= B and C;
D <= E or F or G;
H <= (I nand J) nand K;
L <= (M xor N) and (O xor P);
Synthesis of relational operators
signal A, B: BIT_VECTOR(3 downto 0);
signal C, D: BIT_VECTOR(1 downto 0);
signal E, F, G, H, I, J: BOOLEAN;
G <= (A = B);
H <= (C < D);
I <= (C >= D);
J <= (E > F);
Miscellaneous Operators
• The concatenation operator &
VARIABLE shifted, shiftin : BIT_VECTOR (0 TO 3);
...
shifted := shiftin(1 TO 3) & '0';
0 1 2 3
SHIFTIN 1 0 0 1
SHIFTED 0 0 1 0
PROCESS
SUBTYPE smallintA IS integer (RANGE 0 TO 10);
SUBTYPE smallintB IS integer (RANGE 0 TO 15);
VARIABLE A: smallintA := 5;
VARIABLE B: smallintB :=8;
VARIABLE C: integer;
BEGIN
C := B * A; -- OK
B := B+1; -- OK
END;
Potential problems (ctd.)