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

Subversion Repositories ttl_library

[/] [ttl_library/] [trunk/] [Testbench/] [Testbench_169.vhd] - Blame information for rev 4

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 SN74LS169N: Synch. bidirectional 4-bit binary ctr   --
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_169 is     -- Top-level bench
17
generic(
18
    StimClk  : std_logic      := '1';
19
    CheckClk : std_logic      := '1';
20
    Period   : time           := 100 ns;
21
    Finish   : time           :=  20 us;
22
    SevLevel : severity_level := failure
23
);
24
end entity;
25
 
26
architecture Test of Testbench_169 is
27
    signal RS      : std_logic;
28
    signal CLK     : 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
    signal UD      : std_logic := '1';
35
    signal X, Y, Z : std_logic;
36
    signal W       : std_logic_vector(3 downto 0);
37
 
38
    alias  P       : unsigned(3 downto 0) is B(3 downto 0);
39
    alias  CP      : std_logic is CLK;
40
 
41
    constant modulus  : natural := 10;
42
    constant limit    : unsigned(3 downto 0) := to_unsigned(modulus-1, 4);
43
    constant decade   : boolean := false;
44
 
45
    begin
46
    CEP <= J(0);
47
    CET <= J(1);
48
    X <= and_reduce(W) and not CET;
49
    Y <= nor_reduce(W) and not CET;
50
    Z <= not X when UD = '1' else not Y;
51
    D <= Z & W;
52
 
53
    process(CP, RS) is     -- Generate control signals
54
        variable T2, T3 : natural := 0;
55
    begin
56
        if    RS = '0' then
57
            PE <= '0';
58
        elsif rising_edge(CP) then
59
            if T2 = 37 then
60
                PE <= '0';
61
                T2 := 0;
62
            else
63
                PE <= '1';
64
                T2 := T2 + 1;
65
            end if;
66
 
67
            if T3 = 41 then
68
                UD <= not UD;
69
                T3 := 0;
70
            else
71
                T3 := T3 + 1;
72
            end if;
73
        end if;
74
    end process;
75
 
76
    -----------------------------------------------------------------------
77
    -- Standard testbench components
78
    -----------------------------------------------------------------------
79
    TB: TTLBench
80
    generic map(
81
        StimClk  => StimClk,
82
        CheckClk => CheckClk,
83
        Period   => Period,
84
        Finish   => Finish,
85
        SevLevel => SevLevel
86
    )
87
    port map(
88
        J    => J,
89
        B    => B,
90
        CLK  => CLK,
91
        RS   => RS,
92
        D    => D,
93
        E    => E
94
    );
95
 
96
    -----------------------------------------------------------------------
97
    -- Generate expected results (with zero delays)
98
    -----------------------------------------------------------------------
99
 
100
    process(CP) is
101
        variable SW : std_logic_vector(3 downto 0);
102
        variable R  : unsigned(3 downto 0);
103
    begin
104
        if CP'event and CP = '1' then       -- Everything is synchronous
105
            SW := (PE, CEP, CET, UD);
106
            case SW is
107
                when "0000" | "0001" | "0010" | "0011" |
108
                     "0100" | "0101" | "0110" | "0111"=>              -- Load
109
                    R := unsigned(P);
110
                when "1001" =>              -- Count up
111
                    if decade then
112
                        case R is
113
                            when "1001" => R := "0000";
114
                            when "1011" => R := "0100";
115
                            when "1101" => R := "0100";
116
                            when others => R := R + 1;
117
                        end case;
118
                    else
119
                        R := R + 1;
120
                    end if;
121
                when "1000" =>              -- Count down
122
                    if decade then
123
                        case R is
124
                            when "0000" => R := "1001";
125
                            when "1010" => R := "0001";
126
                            when "1100" => R := "0011";
127
                            when "1110" => R := "0101";
128
                            when others => R := R - 1;
129
                        end case;
130
                    else
131
                        R := R - 1;
132
                    end if;
133
                when others =>              -- No change
134
                    null;
135
            end case;
136
        end if;
137
        W <= std_logic_vector(R);
138
    end process;
139
 
140
    -----------------------------------------------------------------------
141
    -- Device Under Test...                        
142
    -----------------------------------------------------------------------
143
    DUT: SN74LS169N
144
    port map(
145
    X_1  => UD,    -- U_D\
146
    X_2  => CP,    -- CP
147
    X_3  => B(0),  -- P0
148
    X_4  => B(1),  -- P1
149
    X_5  => B(2),  -- P2
150
    X_6  => B(3),  -- P3
151
    X_7  => CEP,   -- CEP\
152
    X_8  => open,  -- GND
153
    X_9  => PE,    -- PE\
154
    X_10 => CET,   -- CET\
155
    X_11 => E(3),  -- Q3
156
    X_12 => E(2),  -- Q2
157
    X_13 => E(1),  -- Q1
158
    X_14 => E(0),  -- Q0
159
    X_15 => E(4),  -- TC\
160
    X_16 => open   -- Vcc
161
);
162
 
163
end architecture Test;

powered by: WebSVN 2.1.0

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