File size: 1,667 Bytes
7df9186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
`timescale 1ns / 1ns

module parab_tb;

reg clk, trace;
integer cc, endcc;
initial begin
	if ($test$plusargs("vcd")) begin
		$dumpfile("parab.vcd");
		$dumpvars(5, parab_tb);
	end
	trace = $test$plusargs("trace");
	endcc = 3300;
	if (trace) endcc = 410000;
	for (cc=0; cc<endcc; cc=cc+1) begin
		clk=0; #5;
		clk=1; #5;
	end
	$display("WARNING: Not a self-checking testbench. Will always pass.");
	$display("PASS");
	$finish(0);
end

reg gate=0, reset=0;
always @(posedge clk) begin
	gate <= cc%4==3;
	reset <= cc%393216==3;
end

// See explanation in parab.v
parameter dw = 20;
parameter dx = 16;
parameter ow = 20;
parameter cw = 24;

// Ignore the test bench clock rate and gate rate.  Estimate the real-life
// use case is 10000 gates/sec, and a typical sweep will cover 100 to 220 Hz
// in 9.83 seconds (393216 clock cycles in simulation).
// Thus initial dphase is 100/10000 revolutions/gate
// and ddphase is 120/10000/(9.83*10000) revolutions/gate/gate
reg [dw-1:0] dphase = 10490;  // 100/10000*2^dw
reg [dw-1:0] ddphase = 8385;  // 120/10000/(9.83*10000)*2^(dw+dx)

wire [ow-1:0] phase;
wire error, gate_o;
parab #(.dw(dw), .dx(dx), .ow(ow)) dut(
	.clk(clk), .gate(gate), .reset(reset),
	.dphase(dphase), .ddphase(ddphase),
	.gate_o(gate_o), .phase(phase), .error(error)
);

reg [dw-1:0] amp_max = 20000;
reg [dw-1:0] amp_slope = 5;
reg [cw-1:0] chirp_len = 98304;

wire [dw-1:0] amp;
wire ramp_error;
ramps #(.dw(dw), .cw(cw)) rut(
	.clk(clk), .gate(gate), .reset(reset),
	.duration(chirp_len), .amp_slope(amp_slope), .amp_max(amp_max),
	.amp(amp), .error(ramp_error)
);

always @(negedge clk) if (trace & gate_o) $display("%d %d", phase, amp);

endmodule