-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprogram_counter_tb.sv.bak
More file actions
108 lines (92 loc) · 2.5 KB
/
program_counter_tb.sv.bak
File metadata and controls
108 lines (92 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//-----------------------------------------------------------------------------
//
// Title : Program Counter Testbench
// Author : vinod sake <vinosake@pdx.edu>
// Company : Student
//
//-----------------------------------------------------------------------------
//
// File : program_counter_tb.sv
// Generated : 15 Dec 2016
// Last Updated:
//-----------------------------------------------------------------------------
//
// Description : Performing Testing on program counter with diffrerent modes
//
//
//-----------------------------------------------------------------------------
`include "program_counter.sv"
`timescale 1 ns / 10 ps
module program_counter_test();
logic reset = 1'b1; // Active low reset
logic increment = 1'b0; // set high from external source
logic jump_set = 1'b0; // set high from external source
logic[15:0] jumpcount = 16'hfffe; // Input value to the counter
logic[15:0] count; // Counter output for accessing memory
// Clock
logic clock = 1'b0;
always #50 clock = !clock; // 100 time ticks per cycle = 10 MHz clock
program_counter pc_dut(
.clock(clock),
.reset(reset),
.increment(increment),
.jump_set(jump_set),
.jumpcount(jumpcount),
.count(count)
);
// Test
initial begin
// Reset
@(negedge clock) begin
reset = 1'b0;
end
checkCount(16'b0, `__LINE__);
// Check that counter doesn't increment without the signal being asserted
@(negedge clock) begin
reset = 1'b1;
end
checkCount(16'b0, `__LINE__);
// Load a value
@(negedge clock) begin
jump_set = 1'b1;
end
checkCount(16'hfffe, `__LINE__);
// Load a value while incrementing, the new value should take precendence i.e count = jumpcount
@(negedge clock) begin
jump_set = 1'b1;
increment = 1'b1;
end
checkCount(16'hfffe, `__LINE__);
// Increment
@(negedge clock) begin
jump_set = 1'b0;
increment = 1'b1;
end
checkCount(16'hffff, `__LINE__);
// Incementing further so that count should be 16'h0000
@(negedge clock) begin
increment = 1'b1;
end
checkCount(16'h0000, `__LINE__);
// Stop simulation
$finish;
end
// Waveform log file and monitoring
initial begin
$dumpfile("program_counter.vcd");
$dumpvars();
$monitor("time: %d, value: %h", $time, count);
end
task checkCount(input[15:0] expected, input integer lineNum);
begin
@(posedge clock) #5 begin
if(count === expected) begin
$display("%3d - Test passed", lineNum);
end
else begin
$display("%3d - Test failed, expected %h, got %h", lineNum, expected,count);
end
end
end
endtask
endmodule