Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| dt-code [2011/01/10 12:52] – Funktionale Beschreibung des Multiplexers eingefügt. beckmanf | dt-code [2025/04/10 16:09] (current) – bilder in dokuwiki beckmanf | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | === VHDL Code Beispiele | + | ===== VHDL Entity and Architecture ===== |
| - | == Entity | + | VHDL splits interface (entity) |
| <code vhdl> | <code vhdl> | ||
| Line 11: | Line 11: | ||
| a_i : in std_ulogic; | a_i : in std_ulogic; | ||
| b_i : in std_ulogic; | b_i : in std_ulogic; | ||
| - | | + | |
| - | end first; | + | end and_gate; |
| architecture rtl of and_gate is | architecture rtl of and_gate is | ||
| begin | begin | ||
| y_o <= a_i and b_i; | y_o <= a_i and b_i; | ||
| - | end rtl; | + | end architecture |
| - | | + | |
| </ | </ | ||
| + | Listing 1: Entity and Architecture for and_gate | ||
| + | |||
| + | The code in listing 1 describes the full code for a circuit called " | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| - | == Strukturelle Beschreibung von Schaltungen | + | Figure 1 shows the block " |
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | The architecture with the name " | ||
| + | |||
| + | ===== Instantiation and hierarchical design ===== | ||
| + | |||
| + | Circuits are very often composed of subcircuits. And the subcircuits can themself be composed of subcircuits. This is called hierarchical design. The following example shows a block " | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Figure 3 shows the block interface of a circuit " | ||
| + | |||
| + | This " | ||
| + | Assume that we have defined not only the " | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Figure 4 shows a schematic of a multiplexer using and_gate, or_gate and the inv_gate. The corresponding VHDL code is shown in listing 2. | ||
| <code vhdl> | <code vhdl> | ||
| Line 35: | Line 66: | ||
| end mux; | end mux; | ||
| - | architecture structure of mux is | + | architecture structure of mux is |
| - | + | ||
| - | component and_gate | + | |
| - | port( | + | |
| - | a_i : in std_ulogic; | + | |
| - | b_i : in std_ulogic; | + | |
| - | y_o : out std_ulogic); | + | |
| - | + | ||
| - | component or_gate | + | |
| - | port( | + | |
| - | a_i : in std_ulogic; | + | |
| - | b_i : in std_ulogic; | + | |
| - | y_o : out std_ulogic); | + | |
| - | + | ||
| - | component inv_gate | + | |
| - | port( | + | |
| - | a_i : in std_ulogic; | + | |
| - | y_o : out std_ulogic); | + | |
| - | | + | |
| signal s1 : std_ulogic; | signal s1 : std_ulogic; | ||
| signal s2 : std_ulogic; | signal s2 : std_ulogic; | ||
| signal s3 : std_ulogic; | signal s3 : std_ulogic; | ||
| - | | ||
| begin | begin | ||
| - | inv_gate_i0 : inv_gate | + | inv_gate_i0 : work.inv_gate |
| port map( | port map( | ||
| a_i => s_i, | a_i => s_i, | ||
| y_o => s1); | y_o => s1); | ||
| | | ||
| - | and_gate_i0 : and_gate | + | and_gate_i0 : work.and_gate |
| port map( | port map( | ||
| a_i => s1, | a_i => s1, | ||
| Line 71: | Line 83: | ||
| y_o => s2); | y_o => s2); | ||
| | | ||
| - | and_gate_i1 : and_gate | + | and_gate_i1 : work.and_gate |
| port map( | port map( | ||
| a_i => s_i, | a_i => s_i, | ||
| Line 77: | Line 89: | ||
| y_o => s3); | y_o => s3); | ||
| | | ||
| - | or_gate_i0 : or_gate | + | or_gate_i0 : work.or_gate |
| port map( | port map( | ||
| a_i => s2, | a_i => s2, | ||
| Line 83: | Line 95: | ||
| y_o => y_o); | y_o => y_o); | ||
| - | end mux; | + | end architecture structure; |
| </ | </ | ||
| - | == Funktionale Beschreibung mit Concurrent Signal Assignments == | + | Listing 2: Structural VHDL code that instantiates and_gate, or_gate and inv_gate |
| - | Eine alternative Beschreibung des Multiplexers mit Funktionen und | + | The instantiation code introduces the name of the instance. In this example the names of the "and_gate" |
| - | Concurrent Signal Assignments. Die Funktionen | + | |
| - | sind im package ieee.std_logic_1164 definiert. | + | |
| - | <code vhdl> | + | ===== Signals ===== |
| - | architecture rtl-1 of mux is | + | Note the signals |
| - | signal | + | |
| - | begin | + | |
| - | s1 <= not s_i; | + | Signals are defined between " |
| - | s2 <= s1 and a_i; | + | |
| - | s3 <= s_i and b_i; | + | |
| - | y_o <= s2 or s3; | + | |
| - | end rtl-1 | + | ===== Multiplexer Code - the real thing ===== |
| - | </ | + | |
| - | == Funktionale Beschreibung mit einem Prozess == | + | The previous code example |
| - | + | ||
| - | Ein Prozess enthält sequentielle Anweisungen. Ein Prozess wird immer ausgeführt, | + | |
| - | sich ein Signal | + | |
| - | + | ||
| - | Die Sequenz der Anweisungen | + | |
| - | Das bedeutet der Prozess berechnet die neuen Werte der Signale und diese werden dann alle | + | |
| - | zeitgleich zugewiesen. Im folgenden Beispiel wurde die Anweisung s3 <= s_i and b_i durch einen | + | |
| - | Prozess ersetzt. Die Funktion hat sich dadurch nicht geändert. | + | |
| <code vhdl> | <code vhdl> | ||
| + | library ieee; | ||
| + | use ieee.std_logic_1164.all; | ||
| - | architecture rtl-2 of mux is | + | entity |
| - | signal s1, s2, s3 : std_ulogic; | + | port ( |
| - | begin | + | a_i : in std_ulogic; |
| + | b_i : in std_ulogic; | ||
| + | s_i : in std_ulogic; | ||
| + | y_o : out std_ulogic); | ||
| + | end mux; | ||
| - | s1 <= not s_i; | + | architecture rtl of mux is |
| - | s2 <= s1 and a_i; | + | |
| - | -- s3 replaced with process | + | |
| - | y_o <= s2 or s3; | + | |
| - | + | ||
| - | s3_and_p : process (s_i, b_i) | + | |
| begin | begin | ||
| - | s3 <= ' | + | y_o <= a_i when s_i = '0' |
| - | if s_i = '1' | + | end architecture; |
| - | s3 <= ' | + | |
| - | end if; | + | |
| - | end process s3_and_p; | + | |
| - | + | ||
| - | end rtl-2 | + | |
| </ | </ | ||
| - | == Komplette funtkionale Beschreibung in einem Prozess == | + | Listing |
| - | + | ||
| - | Alternativ lässt sich auch die ganze Multiplexerfunktion in einem | + | |
| - | Prozess beschreiben. Die Lesbarkeit wird durch diese Beschreibung häufig erhöht. | + | |
| - | + | ||
| - | <code vhdl> | + | |
| - | + | ||
| - | architecture rtl-3 of mux is | + | |
| - | + | ||
| - | begin | + | |
| - | + | ||
| - | mux_p : process (s_i, a_i, b_i) | + | |
| - | begin | + | |
| - | y_o <= ' | + | |
| - | if s_i = ' | + | |
| - | y_o <= b_i; | + | |
| - | else | + | |
| - | y_o <= a_i; | + | |
| - | end if; | + | |
| - | end process mux_p; | + | |
| - | + | ||
| - | end rtl-3 | + | |
| - | </ | + | |
| - | + | ||
| - | == Prozess mit einem case statement == | + | |
| - | + | ||
| - | Alternativ lässt sich auch ein case statement | + | |
| - | + | ||
| - | <code vhdl> | + | |
| - | + | ||
| - | architecture rtl-4 of mux is | + | |
| - | + | ||
| - | begin | + | |
| - | + | ||
| - | mux_p : process (s_i, a_i, b_i) | + | |
| - | begin | + | |
| - | y_o <= ' | + | |
| - | case s_i is | + | |
| - | when ' | + | |
| - | when ' | + | |
| - | when others => y_o <= ' | + | |
| - | end case; | + | |
| - | end process mux_p; | + | |
| - | + | ||
| - | end rtl-4 | + | |
| - | </ | + | |
| - | + | ||
| - | == Conditional Signal Assignment == | + | |
| - | + | ||
| - | Dann gibt es noch das Conditional Signal Assignment. | + | |
| - | + | ||
| - | <code vhdl> | + | |
| - | + | ||
| - | architecture rtl-5 of mux is | + | |
| - | + | ||
| - | begin | + | |
| - | + | ||
| - | y_o <= b_i when s_i = ' | + | |
| - | + | ||
| - | end rtl-5 | + | |
| - | </ | + | |
| - | + | ||
| - | == Selected Signal Assignment == | + | |
| - | + | ||
| - | Noch eine alternative ist das selected signal assignment. | + | |
| - | + | ||
| - | <code vhdl> | + | |
| - | + | ||
| - | architecture rtl-6 of mux is | + | |
| - | + | ||
| - | begin | + | |
| - | + | ||
| - | with s_i select | + | |
| - | y_o <= a_i when ' | + | |
| - | y_o <= b_i when ' | + | |
| - | + | ||
| - | end rtl-6 | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||