-
Notifications
You must be signed in to change notification settings - Fork 3
/
30.v
115 lines (88 loc) · 2.36 KB
/
30.v
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
109
110
111
112
113
114
115
`timescale 100ns/1ns
`default_nettype none
`include "Uart8.v"
module test;
localparam CLOCK_FREQ = 12000000; // Alhambra board
localparam SIM_STEP_FREQ = 1 / 0.0000001 / 2; // this sim timescale 100ns
// for the simulation timeline:
// ratio SIM_STEP_FREQ MHz / CLOCK_FREQ MHz gives the output waveform in proper time
// (*but note all clocks and the timeline are approximate due to rounding)
localparam SIM_TIMESTEP_FACTOR = SIM_STEP_FREQ / CLOCK_FREQ;
reg clk;
reg en_1;
reg rx;
wire rxBusy_2;
wire rxDone_2;
wire rxErr_2;
reg [7:0] txByte_1;
wire [7:0] rxByte_2;
Uart8 #(.CLOCK_RATE(CLOCK_FREQ)) uart(
.clk(clk),
// rx interface
.rxEn(en_1),
.rx(rx),
.rxBusy(rxBusy_2),
.rxDone(rxDone_2),
.rxErr(rxErr_2),
.out(rxByte_2)
// tx interface (unused)
);
initial clk = 1'b0;
always #SIM_TIMESTEP_FACTOR clk = ~clk;
initial begin
$dumpfile(`DUMP_FILE_NAME);
$dumpvars(0, test);
// #65 == 1 rx clock period (approximately) at 9600 baud
#240
en_1 = 1'b1;
txByte_1 = 8'b11010110;
rx = 1'b0;
$display(" tx data: %8b", txByte_1);
#160
rx = 1'b1;
#360
rx = 1'b0;
#1075 // instead of #1042, this makes transmit clock sync with receive clock (a 3% difference)
rx = txByte_1[0];
$display("%7.2fms | rx first bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[1];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[2];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[3];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[4];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[5];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[6];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[7];
$display("%7.2fms | rx last bit: %1b", $realtime/10000, rx);
#530
rx = 1'b1;
#530
rx = 1'b0;
$display("%7.4fms | end of stop bit | start of start bit: %1b", $realtime/10000, rx);
#530
rx = 1'b1;
$display("%7.4fms | rx start bit glitch: %1b", $realtime/10000, rx);
#545
rx = txByte_1[0];
$display("%7.2fms | rx first bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[1];
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
#1075
rx = txByte_1[2];
#1120
$finish();
end
endmodule