Project

General

Profile

Download (1.82 KB) Statistics
| Branch: | Tag: | Revision:
1
--- Adapted 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;
(17-17/45)