Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec-tests / vhdl_json / vhdl_files / 2-exportOK / valencia / d-latch-and-gate.vhd @ 47142ed7

History | View | Annotate | Download (2.88 KB)

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
    q1 <= '1';
13
    storage: process (d0, d1, d2, d3, en, clk) is
14
      variable stored_d0, stored_d1, stored_d2, stored_d3: bit;
15
    begin
16
      if en = '1' and clk = '1' then
17
        stored_d0 := d0;
18
        stored_d1 := d1;
19
        stored_d2 := d2;
20
        stored_d3 := d3;
21
      end if;
22
      q0 <= stored_d0 after 5 ns;
23
      q1 <= stored_d1 after 5 ns;
24
      q2 <= stored_d2 after 5 ns;
25
      q3 <= stored_d3 after 5 ns;
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 2 ns;
40
    end if;
41
  end process latch_behavior;
42
end architecture basic;
43

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

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

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

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