Hallo
Ich arbeite gerade dieses Tutorial durch:
https://www.youtube.com/watch?v=3epKbSGbMCA&index=36&list=PL7kkolCtIBKLukrBsEDwKRTE64JvaJDhM
In dieser Lesson wurde ein 4Bit Comparator gebaut, und zwar aus
einzelnen 1 bit Comparatoren.
Dazu wurde dann eine Procedure verwendet und mit Hilfe einer for
Schleife kaskadiert.
1 | library IEEE;
|
2 | use IEEE.std_logic_1164.all;
|
3 | use IEEE.std_logic_unsigned.all;
|
4 |
|
5 |
|
6 | entity comp4bit is
|
7 | port
|
8 | (
|
9 | x: in std_logic_vector(3 downto 0);
|
10 | y: in std_logic_vector(3 downto 0);
|
11 | gt: out std_logic;
|
12 | lt: out std_logic;
|
13 | eq: out std_logic
|
14 | );
|
15 | end comp4bit;
|
16 |
|
17 | architecture comp4bit_arch of comp4bit is
|
18 | procedure comp1bit
|
19 | (
|
20 | x: in std_logic;
|
21 | y: in std_logic;
|
22 | Gin: in std_logic;
|
23 | Lin: in std_logic;
|
24 | Gout: out std_logic;
|
25 | Lout: out std_logic;
|
26 | Eout: out std_logic
|
27 | ) is
|
28 | begin
|
29 | Gout := (x AND not y) or (x AND Gin) or (not y AND Gin);
|
30 | Eout := (not x AND not y AND not Gin AND not Lin) or (x AND y AND not Gin AND not Lin);
|
31 | Lout := (not x AND y) or (not x AND Lin) or (y AND Lin);
|
32 | end procedure;
|
33 | begin
|
34 | process(x, y)
|
35 | variable G, L, E: std_logic_vector(4 downto 0);
|
36 |
|
37 | begin
|
38 | G(0) := '0';
|
39 | L(0) := '0';
|
40 |
|
41 | for i in 0 to 3 loop
|
42 | comp1bit(x(i), y(i), G(i), L(i), G(i+1), L(i+1), E(i+1));
|
43 | end loop;
|
44 |
|
45 | gt <= G(4);
|
46 | lt <= L(4);
|
47 | eq <= E(4);
|
48 | end process;
|
49 | end comp4bit_arch;
|
Es funktioniert auch alles.
Nur wollte ich Fragen, ob man die Definition der Procedure auch in eine
eigene Datei auslagern kann, oder sogar eine entity in eine procedure
einfügen? Denn wenn es eine aufwändigere Definition wird, als hier diese
paar AND, NOT und OR Gatter, wird es ziemlich unübersichtlich...