Documente Academic
Documente Profesional
Documente Cultură
• Examples:
SIGNAL control: BIT := '0';
1. SIGNAL count: INTEGER RANGE 0 TO 100;
2. SIGNAL y: STD_LOGIC_VECTOR (7 DOWNTO 0);
---------------------------------------
1. LIBRARY ieee;
2. USE ieee.std_logic_1164.all;
3. ---------------------------------------
4. ENTITY count_ones IS
5. PORT ( din: IN STD_LOGIC_VECTOR (7 DOWNTO 0);
6. ones: OUT INTEGER RANGE 0 TO 8);
7. END count_ones;
8. ---------------------------------------
Count Ones #1 (not OK) Code2
• Examples:
VARIABLE control: BIT := '0';
VARIABLE count: INTEGER RANGE 0 TO 100;
VARIABLE y: STD_LOGIC_VECTOR (7 DOWNTO 0) :=
"10001000";
• VARIABLE can only be used in sequential code
• its declaration can only be done in the
declarative part of a PROCESS, FUNCTION, or
PROCEDURE.
• assignment operator for a VARIABLE is ‘‘:=’’
(Ex.: count:=35;).
Example : Count Ones #2 (OK) code1
1. ---------------------------------------
2. LIBRARY ieee;
3. USE ieee.std_logic_1164.all;
4. ---------------------------------------
5. ENTITY count_ones IS
6. PORT ( din: IN STD_LOGIC_VECTOR (7 DOWNTO 0);
7. ones: OUT INTEGER RANGE 0 TO 8);
8. END count_ones;
9. ---------------------------------------
Count Ones #2 (OK) code2
10.ARCHITECTURE ok OF count_ones IS
11.BEGIN
12. PROCESS (din)
13. VARIABLE temp: INTEGER RANGE 0 TO 8;
14. BEGIN
15. temp := 0; -- variable
16. FOR i IN 0 TO 7 LOOP
17. IF (din(i)='1') THEN
18. temp := temp + 1; -- variable
19. END IF;
20. END LOOP;
21. ones <= temp;
22. END PROCESS;
23.END ok;
24.---------------------------------------
SIGNAL x VARIABLE
SIGNAL VARIABLE
Assignment <= :=
Scope Can be global (seen by entire Local (visible only inside the
code) corresponding PROCESS,
FUNCTION, or PROCEDURE)
Behavior Update is not immediate in Updated immediately (new value
sequential code (new value can be used in the next line of
generally only available at the code)
conclusion of the PROCESS,
FUNCTION, or PROCEDURE)
Usage In a PACKAGE, ENTITY, or Only in sequential code, that is,
ARCHITECTURE. In an ENTITY, all in a PROCESS, FUNCTION, or
PORTS are SIGNALS by defaul PROCEDURE
Bad versus Good Multiplexer,
some difference using SIGNAL and VARIABLE.
Solution 2
o x <= 5;
o x <= y(5);
o z <= '1';
o z := y(5);
o WHILE i IN 0 TO max LOOP...
o FOR i IN 0 TO x LOOP...
o G1: FOR i IN 0 TO max GENERATE...
o G1: FOR i IN 0 TO x GENERATE...
programmable data delay circuit
• The input (d) and output (q) are 4-bit buses. Depending on the
value of sel (select), q should be one, two, three, or four clock
cycles delayed with respect to d.
a) Write a VHDL code for this circuit;
b) How many flip-flops do you expect your solution to contain?
c) Synthesize your solution and open the report file. Verify whether the
actual number of flip-flops matches your prediction.