OpenCores
URL https://opencores.org/ocsvn/ttl_library/ttl_library/trunk

Subversion Repositories ttl_library

[/] [ttl_library/] [trunk/] [Testbench/] [Testbench_163.vhd] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 david237
-----------------------------------------------------------------------
2
-- Bipolar TTL models (VHDL)                                         --
3
-- David R Brooks                                                    --
4
-- June, 2016.  Perth, Australia                                     --
5
-- Compliance: VHDL 2008                                             --
6
-- Testbench for SN74LS163N: Synch. presettable 4-bit binary counter --
7
-----------------------------------------------------------------------
8
 
9
library ieee;
10
    use ieee.std_logic_1164.all;
11
    use ieee.std_logic_misc.all;
12
    use ieee.numeric_std.all;
13
    use work.LSTTL.all;
14
    use work.TTLPrivate.all;
15
 
16
entity Testbench_163 is     -- Top-level bench
17
generic(
18
    StimClk  : std_logic      := '1';
19
    CheckClk : std_logic      := '1';
20
    Period   : time           :=  30 ns;
21
    Finish   : time           :=  20 us;
22
    SevLevel : severity_level := failure
23
);
24
end entity;
25
 
26
architecture Test of Testbench_163 is
27
    signal RS, NRS : std_logic;
28
    signal CLK, R  : std_logic;
29
    signal J,  B   : unsigned(6 downto 0);          -- Test stimuli
30
    signal D,  E   : std_logic_vector(4 downto 0);  -- Expected & actual results
31
    signal PE      : std_logic := '1';
32
    signal CEP     : std_logic := '1';
33
    signal CET     : std_logic := '1';
34
 
35
    alias  P       : unsigned(3 downto 0) is B(3 downto 0);
36
    alias  CP      : std_logic is CLK;
37
 
38
    constant modulus  : natural := 16;
39
    constant asyncrst : boolean := false;
40
    constant limit    : unsigned(3 downto 0) := to_unsigned(modulus-1, 4);
41
 
42
    begin
43
    RS  <= NRS and R;
44
    CEP <= J(0);
45
    CET <= J(1);
46
 
47
    process(CLK) is     -- Generate control signals
48
        variable T2, T3 : natural := 0;
49
    begin
50
        if rising_edge(CLK) then
51
            if T2 = 37 then
52
                PE <= '0';
53
                T2 := 0;
54
            else
55
                PE <= '1';
56
                T2 := T2 + 1;
57
            end if;
58
 
59
            if T3 = 41 then
60
                R  <= '0';
61
                T3 := 0;
62
            else
63
                R  <= '1';
64
                T3 := T3 + 1;
65
            end if;
66
        end if;
67
    end process;
68
 
69
    -----------------------------------------------------------------------
70
    -- Standard testbench components
71
    -----------------------------------------------------------------------
72
    TB: TTLBench
73
    generic map(
74
        StimClk  => StimClk,
75
        CheckClk => CheckClk,
76
        Period   => Period,
77
        Finish   => Finish,
78
        SevLevel => SevLevel
79
    )
80
    port map(
81
        J    => J,
82
        B    => B,
83
        CLK  => CLK,
84
        RS   => NRS,
85
        D    => D,
86
        E    => E
87
    );
88
 
89
    -----------------------------------------------------------------------
90
    -- Generate expected results (with zero delays)
91
    -----------------------------------------------------------------------
92
 
93
    process(CP, RS) is
94
        variable N : unsigned(3 downto 0);
95
    begin
96
        if asyncrst and (RS = '0') then
97
            N := (others => '0');
98
        elsif rising_edge(CP) then
99
            if RS = '0' then
100
                N := (others => '0');
101
            elsif PE = '0' then
102
                N := unsigned(P);
103
            elsif (CEP and CET) = '1' then
104
                if modulus = 16 then     -- Simple binary count
105
                    N := N + 1;
106
                else                     -- Decade count, cover illegal cases
107
                    case N is
108
                        when "1001"          => N := "0000";
109
                        when "1011" | "1101" => N := "0100";
110
                        when "1111"          => N := "1000";
111
                        when others          => N := N + 1;
112
                    end case;
113
                end if;
114
            end if;
115
        end if;
116
 
117
        D(3 downto 0) <= std_logic_vector(N);        -- Export results
118
        if now > 1 ns and N = limit then
119
            D(4) <= CET;
120
        else
121
            D(4) <= '0';
122
        end if;
123
    end process;
124
 
125
    -----------------------------------------------------------------------
126
    -- Device Under Test...                        
127
    -----------------------------------------------------------------------
128
    DUT: SN74LS163N
129
    port map(
130
    X_1  => RS,    -- R\
131
    X_2  => CP,    -- CP
132
    X_3  => B(0),  -- P0
133
    X_4  => B(1),  -- P1
134
    X_5  => B(2),  -- P2
135
    X_6  => B(3),  -- P3
136
    X_7  => CEP,   -- CEP
137
    X_8  => open,  -- GND
138
    X_9  => PE,    -- PE\
139
    X_10 => CET,   -- CET
140
    X_11 => E(3),  -- Q3
141
    X_12 => E(2),  -- Q2
142
    X_13 => E(1),  -- Q1
143
    X_14 => E(0),  -- Q0
144
    X_15 => E(4),  -- TC
145
    X_16 => open   -- Vcc
146
);
147
 
148
end architecture Test;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.