-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdassign3_3.tb
103 lines (85 loc) · 2.6 KB
/
dassign3_3.tb
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
//--------------------------------------------------------------------
// Timescale
// Means that if you do #1 in the initial block of your
// testbench, time is advanced by 1ns instead of 1ps
//--------------------------------------------------------------------
`timescale 1ns / 1ps
//--------------------------------------------------------------------
// Design assignment #2, problem #1 sample testbench.
//--------------------------------------------------------------------
module dassign3_3_tb();
parameter length = 576;
parameter words = 3;
//----------------------------------------------------------------
// Signal Declarations
//----------------------------------------------------------------
// clock
wire clk;
// morse rom
reg [0:length-1] signal[0:words-1];
reg [0:length-1] word;
// morse input
reg in;
// morse output
wire [4:0] letter;
wire [6:0] display;
wire done;
// variables for testing
reg [7:0] ascii;
reg printed=0;
integer i,w;
//----------------------------------------------------------------
// Instantiate modules
//----------------------------------------------------------------
clock_gen clock_gen(clk);
decoder decoder(clk, in, letter, display, done);
//----------------------------------------------------------------
// Test Stimulus
//----------------------------------------------------------------
initial begin
// Export timing information
// Warning: slow!
// $dumpfile("timing3_3.vcd");
// $dumpvars;
$readmemb("./signal_rom", signal);
// Flush the pipeline
for(i=8'b0; i<5; i=i+1) begin
@(posedge clk); #1
in=1;
@(posedge clk); #1
in=0;
end
for(i=8'b0; i<50; i=i+1) begin
@(posedge clk); #1
in=0;
end
// Parse morse code signal
for(w=8'b0; w<words; w=w+1) begin
word = signal[w];
for(i=8'b0; i<length; i=i+1) begin
// Wait for rising edge of clock
@(posedge clk);
// Decoder indicates done
if (done & !printed) begin
ascii = letter+65;
$display("%s", ascii);
printed = 1;
end else if (!done) begin
printed = 0;
end
#1 in = word[i];
end
end
$finish;
end
endmodule
// Clock generation. Period set via parameter:
// clock changes every half_period ticks
// full clock period = 2*half_period
module clock_gen(clk);
parameter half_period = 31;
output clk;
reg clk;
initial clk = 1;
always #half_period clk = ~clk;
endmodule