Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.79 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
    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
end architecture basic;
58

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

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