Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| dt-code [2010/12/20 13:42] – created 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 | ||
| - | == Strukturelle Beschreibung von Schaltungen | + | The code in listing 1 describes the full code for a circuit called " |
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | 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; |
| </ | </ | ||
| + | |||
| + | Listing 2: Structural VHDL code that instantiates and_gate, or_gate and inv_gate | ||
| + | |||
| + | The instantiation code introduces the name of the instance. In this example the names of the " | ||
| + | |||
| + | ===== Signals ===== | ||
| + | |||
| + | Note the signals s1, s2 and s3 in listing 2 which work as internal nets in " | ||
| + | |||
| + | Signals are defined between " | ||
| + | |||
| + | ===== Multiplexer Code - the real thing ===== | ||
| + | |||
| + | The previous code example in listing 2 and listing 1 show the hierarchical design of a multiplexer. Nobody would ever do it like that - it only serves as an example for hierarchical design which is used when the subcircuits have some complexity. The multiplexer function as described in listing 2 can be written in one line of code in VHDL. Listing 3 shows the full code of " | ||
| + | |||
| + | <code vhdl> | ||
| + | library ieee; | ||
| + | use ieee.std_logic_1164.all; | ||
| + | |||
| + | entity mux is | ||
| + | port ( | ||
| + | a_i : in std_ulogic; | ||
| + | b_i : in std_ulogic; | ||
| + | s_i : in std_ulogic; | ||
| + | y_o : out std_ulogic); | ||
| + | end mux; | ||
| + | |||
| + | architecture rtl of mux is | ||
| + | begin | ||
| + | y_o <= a_i when s_i = ' | ||
| + | end architecture; | ||
| + | </ | ||
| + | |||
| + | Listing 3: Multiplexer Code in one line | ||
| + | |||
| + | |||
| + | |||