-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoscilloscope.v
188 lines (158 loc) · 4.47 KB
/
oscilloscope.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
module oscilloscope( CLOCK_50 , SWTCH ,
signal,
oVGA_CLK ,
oVS ,
oHS,
oBLANK_n,
b_data ,
g_data,
r_data);
input CLOCK_50;
input SWTCH;
input [15:0] signal;
output oVGA_CLK;
output oVS;
output oHS;
output oBLANK_n;
output reg [7:0]b_data ;
output reg [7:0]g_data ;
output reg [7:0]r_data;
// Variables for VGA Clock
reg vga_clk_reg;
wire iVGA_CLK;
//Variables for (x,y) coordinates VGA
wire [10:0] CX;
wire [9:0] CY;
//Oscilloscope parameters
//Horizontal
parameter DivX=10.0; // number of horizontal division
parameter Ttotal=0.000025; // total time represented in the screen
parameter pixelsH=640.0; // number of horizontal pixels
parameter IncPixX=Ttotal/(pixelsH-1.0); // time between two consecutive pixels
//Amplitude
parameter DivY=8.0; // number of vertical divisions
parameter Atotal=16.0; // total volts represented in the screen
parameter pixelsV=480.0; // number of vertical pixels
parameter IncPixY=Atotal/(pixelsV-1.0); // volts between two consecutive pixels
// Sinusoidal wave amplitude
parameter Amp=4.0; // maximum amplitude of sinusoidal wave [-Amp, Amp]
parameter integer Apixels=Amp/IncPixY; // number of pixels to represent the maximum amplitude
//Vector to store the input signal (Section 6.1)
parameter integer nc = 5;
reg [15:0] capturedVals [(nc*256)-1:0]; // vector with values of input signal
integer i = 0; // index of the vector
//Read the signal values from the vector (Section 6.2)
integer j = 0; // read the correct element of the vector
parameter integer nf=2; //Vector points between two consecutive pixels
// Sinusoidal movement parameters
parameter integer cf = 1; //number of frames for each phase change
integer cf_count = 0; //Counter to count from 0 to cf
//integer mov = (nc*256)-nf; //Phase of sinusoidal wave for each new frames
integer mov = 0;
//Value of the current pixel (Section 6.2 and 6.3)
reg [9:0] ValforVGA;
reg [9:0] oldValforVGA;
//////////////////////////////////////////////////////////////////////////////////////////
// 25 MHz clock for the VGA clock
always @(posedge CLOCK_50)
begin
vga_clk_reg = ~vga_clk_reg;
end
assign iVGA_CLK = vga_clk_reg;
assign oVGA_CLK = ~iVGA_CLK;
// instance VGA controller
VGA_Controller VGA_ins( .reset(1'b0),
.vga_clk(iVGA_CLK),
.BLANK_n(oBLANK_n),
.HS(oHS),.VS(oVS),
.CoorX(CX),
.CoorY(CY)
);
// Store input signal in a vector (Section 6.1)
always@(negedge CLOCK_50)
begin
if(i<((nc*256)-1))
begin
i<=i+1;
capturedVals[i]<=signal;
end
end
// Read the correct point of the signal stored in the vector and calculate the pixel associated given the amplitude and the parameters of the oscilloscope (Section 6.2)
always@(negedge iVGA_CLK)
begin
if(oBLANK_n)
begin
if(j<(nc*256)-nf)
begin
j <= j + nf;
end
else
begin
j<=0;
end
ValforVGA <= 239 + Apixels - ((2*Apixels*capturedVals[j])>>16);
end
else
begin
j<=mov;
end
end
// Calculate the RGB values
always@(negedge iVGA_CLK)
begin
oldValforVGA<=ValforVGA;
if(CY==ValforVGA)
begin
r_data<=8'd255;
b_data<=0;
g_data<=0;
end
else if((CY<oldValforVGA && CY>ValforVGA) || (CY>oldValforVGA && CY<ValforVGA))
begin
r_data<=8'd255;
b_data<=0;
g_data<=0;
end
//display the vertical guide lines
else if (CX==63||CX==127||CX==191||CX==255||CX==319||CX==383||CX==447||CX==511||CX==575||CX==639)
begin
r_data<=8'd255;
b_data<=255;
g_data<=255;
end
//display the horizontal guide lines
else if (CY==59||CY==119||CY==179||CY==239||CY==299||CY==359||CY==419||CY==479)
begin
r_data<=255;
b_data<=255;
g_data<=255;
end
//Everything else is black
else
begin
r_data<=0;
b_data<=0;
g_data<=0;
end
end
// To force that a displaced signal is sent through the VGA connector after cf frames
always@(negedge oVS && SWTCH)
begin
if(cf_count==cf)
begin
cf_count<=0;
if(mov<=(nc*256)-nf)
begin
mov <= mov + nf;
end
else
begin
mov<=0;
end
end
else
begin
cf_count <= cf_count + 1;
end
end
endmodule