OpenCores
URL https://opencores.org/ocsvn/mcs-4/mcs-4/trunk

Subversion Repositories mcs-4

[/] [mcs-4/] [trunk/] [rtl/] [verilog/] [common/] [counter_tb.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 rrpollack
`timescale 1ns / 1ps
2
`default_nettype none
3
////////////////////////////////////////////////////////////////////////
4
//
5
// MCS-4 common counter testbench
6
//
7
// This module is a testbench for the counter logic found in Intel MCS-4
8
// integrated circuits such as the i4004 CPU.
9
//
10
// This file is part of the MCS-4 project hosted at OpenCores:
11
//      http://www.opencores.org/cores/mcs-4/
12
//
13
// Copyright © 2012, 2021 by Reece Pollack <rrpollack@opencores.org>
14
//
15
// These materials are provided under the Creative Commons
16
// "Attribution-NonCommercial-ShareAlike" (CC BY-NC-SA) Public License.
17
// They are NOT "public domain", and are protected by copyright.
18
//
19
// This work based on materials provided by Intel Corporation and
20
// others under the same license. See the file doc/License for
21
// details of this license.
22
//
23
////////////////////////////////////////////////////////////////////////
24
 
25
module counter_tb;
26
 
27
    // Inputs
28
    reg     sysclk;
29
    reg     clk1 = 1'b0;
30
    reg     clk2 = 1'b0;
31
    wire    step;
32
 
33
    // Outputs
34
    wire q0, q0n, q1, q1n, q2, q2n;
35
 
36
    // Inter-module connections
37
    wire b01a, b01b;
38
    wire b12a, b12b;
39
 
40
    // Instantiate the Unit Under Test (UUT)
41
    counter b0 (
42
        .step_a_in(clk1),
43
        .step_b_in(step),
44
        .step_a_out(b01a),
45
        .step_b_out(b01b),
46
        .q(q0),
47
        .qn(q0n)
48
    );
49
 
50
    counter b1 (
51
        .step_a_in(b01a),
52
        .step_b_in(b01b),
53
        .step_a_out(b12a),
54
        .step_b_out(b12b),
55
        .q(q1),
56
        .qn(q1n)
57
    );
58
 
59
    counter b2 (
60
        .step_a_in(b12a),
61
        .step_b_in(b12b),
62
        .step_a_out(),
63
        .step_b_out(),
64
        .q(q2),
65
        .qn(q2n)
66
    );
67
 
68
    always begin
69
        sysclk = 1'b0;  #10;
70
        sysclk = 1'b1;  #10;
71
    end
72
 
73
    reg [4:0] clockdiv = 5'b0;
74
    always @(posedge sysclk) begin
75
        clockdiv = (clockdiv == 5'd19) ? 5'b0 : (clockdiv + 5'd1);
76
        if (clockdiv == 5'd0 )  clk1 = 1'b1;
77
        if (clockdiv == 5'd5 )  clk1 = 1'b0;
78
        if (clockdiv == 5'd10)  clk2 = 1'b1;
79
        if (clockdiv == 5'd15)  clk2 = 1'b0;
80
    end
81
 
82
    // Generate the 8 execution phase indicators
83
    reg  [0:7]  master = 8'h00;
84
    reg  [0:7]  slave  = 8'h00;
85
    reg         sync_pad;
86
    always @(*) begin
87
        if (clk2)
88
            master <= {~|slave[0:6], slave[0:6]};
89
        else
90
            sync_pad <= master[7];
91
 
92
        if (clk1)
93
            slave <= master;
94
    end
95
 
96
    wire    a12 = slave[0];
97
    wire    a22 = slave[1];
98
    wire    a32 = slave[2];
99
    wire    m12 = slave[3];
100
    wire    m22 = slave[4];
101
    wire    x12 = slave[5];
102
    wire    x22 = slave[6];
103
    wire    x32 = slave[7];
104
 
105
    assign step = x32 & clk2;
106
 
107
endmodule

powered by: WebSVN 2.1.0

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