Project

General

Profile

Download (2.75 KB) Statistics
| Branch: | Tag: | Revision:
1
--- Extracted from https://www.ee.ryerson.ca/~courses/coe608/lectures/VHDL-intro.pdf p14-15
2

    
3
-- main entity
4
entity reg4 is
5
  port (d0, d1, d2, d3, en, clk: in bit; 
6
        q0, q1, q2, q3 : out bit );
7
end entity reg4;
8

    
9
-- main archi
10
architecture behav of reg4 is
11
  begin
12
    storage: process (d0, d1, d2, d3, en, clk) is
13
      variable stored_d0, stored_d1, stored_d2, stored_d3: bit;
14
    begin
15
      if en = '1' and clk = '1' then
16
        stored_d0 := d0;
17
        stored_d1 := d1;
18
        stored_d2 := d2;
19
        stored_d3 := d3;
20
      end if;
21
      q0 <= stored_d0 after 5 ns;
22
      q1 <= stored_d1 after 5 ns;
23
      q2 <= stored_d2 after 5 ns;
24
      q3 <= stored_d3 after 5 ns;
25
      wait;
26
    end process storage;
27
end architecture behav;
28

    
29
-- D-latch
30
entity d_latch is
31
  port (d, clk: in bit; q: out bit);
32
end entity d_latch;
33

    
34
architecture basic of d_latch is
35
begin
36
  latch_behavior : process (clk, d) is
37
  begin
38
    if clk = '1' then
39
      q <= d after 2ns;
40
    end if;
41
    wait;
42
  end process latch_behavior;
43
end architecture basic;
44

    
45
-- and-gate
46
entity and2 is
47
  port (a, b: in bit; y: out bit);
48
end entity and2;
49

    
50
architecture basic of and2 is
51
  begin
52
  and2_behavior: process (a,b) is
53
  begin
54
    y <= a and b after 2ns;
55
    wait;
56
  end process and2_behavior;
57
gnd architecture basic;
58

    
59
-- Main archi
60
architecture struct of reg4 is
61
  signal int_clk: bit;
62
  begin
63
    bit0: entity work.d_latch(basic)
64
    port map (d0, int_clk, q0);
65
    bit1: entity work.d_latch(basic)
66
    port map (d1, int_clk, q1);
67
    bit2: entity work.d_latch(basic)
68
    port map (d2, int_clk, q2);
69
    bit3: entity work.d_latch(basic)
70
    port map (d3, int_clk, q3);
71
    gate: entity work.and2(basic)
72
    port map (en, clk, int_clk);
73
end architecture struct;
74

    
75
-- Elaborated archi
76
-- architecture struct of ref4 is
77
--   signal int_clk: bit;
78
--   begin
79
--     bit0_latch_behavior : process (int_clk, d0) is
80
--     begin
81
--       if int_clk = '1' then
82
--         q0 <= d0 after 2ns;
83
--       end if;
84
--       wait;
85
--     end process bit0_latch_behavior;
86
--     bit1_latch_behavior : process (int_clk, d1) is
87
--     begin
88
--       if int_clk = '1' then
89
--         q1 <= d1 after 2ns;
90
--       end if;
91
--       wait;
92
--     end process bit1_latch_behavior;
93
--     bit2_latch_behavior : process (int_clk, d2) is
94
--     begin
95
--       if int_clk = '1' then
96
--         q2 <= d2 after 2ns;
97
--       end if;
98
--       wait;
99
--     end process bit2_latch_behavior;
100
--     bit3_latch_behavior : process (int_clk, d3) is
101
--     begin
102
--       if int_clk = '1' then
103
--         q3 <= d3 after 2ns;
104
--       end if;
105
--       wait;
106
--     end process bit3_latch_behavior;
107
--     gate_and2_behavior: process (en, clk) is
108
--     begin
109
--       int_clk <= en and clk after 2ns;
110
--       wait;
111
--     end process gate_and2_behavior;
112
-- end architecture struct;
(10-10/16)