1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2014 iZsh <izsh at fail0verflow.com>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // testbench for lf_edge_detect
9 `include "lf_edge_detect.v"
11 `define FIN "tb_tmp/data.filtered.gold"
12 `define FOUT_MIN "tb_tmp/data.min"
13 `define FOUT_MAX "tb_tmp/data.max"
14 `define FOUT_STATE "tb_tmp/data.state"
15 `define FOUT_TOGGLE "tb_tmp/data.toggle"
16 `define FOUT_HIGH "tb_tmp/data.high"
17 `define FOUT_HIGHZ "tb_tmp/data.highz"
18 `define FOUT_LOWZ "tb_tmp/data.lowz"
19 `define FOUT_LOW "tb_tmp/data.low"
21 module lf_edge_detect_tb
;
23 integer fin
, fout_state
, fout_toggle
;
24 integer fout_high
, fout_highz
, fout_lowz
, fout_low
, fout_min
, fout_max
;
34 wire [7:0] high_threshold
;
35 wire [7:0] highz_threshold
;
36 wire [7:0] lowz_threshold
;
37 wire [7:0] low_threshold
;
44 fin
= $fopen(`FIN, "r");
46 $display("ERROR: can't open the data file");
49 fout_min
= $fopen(`FOUT_MIN, "w+");
50 fout_max
= $fopen(`FOUT_MAX, "w+");
51 fout_state
= $fopen(`FOUT_STATE, "w+");
52 fout_toggle
= $fopen(`FOUT_TOGGLE, "w+");
53 fout_high
= $fopen(`FOUT_HIGH, "w+");
54 fout_highz
= $fopen(`FOUT_HIGHZ, "w+");
55 fout_lowz
= $fopen(`FOUT_LOWZ, "w+");
56 fout_low
= $fopen(`FOUT_LOW, "w+");
58 adc_d
= $fgetc(fin
); // read the first value
67 while (!$feof(fin
)) begin
68 @(negedge clk
) adc_d
<= $fgetc(fin
);
88 // $monitor("%d\t S: %b, E: %b", $time, edge_state, edge_toggle);
94 r
= $fputc(min
, fout_min
);
95 r
= $fputc(max
, fout_max
);
96 r
= $fputc(edge_state
, fout_state
);
97 r
= $fputc(edge_toggle
, fout_toggle
);
98 r
= $fputc(high_threshold
, fout_high
);
99 r
= $fputc(highz_threshold
, fout_highz
);
100 r
= $fputc(lowz_threshold
, fout_lowz
);
101 r
= $fputc(low_threshold
, fout_low
);
105 lf_edge_detect
detect(clk
, adc_d
, 8'd127,
107 high_threshold
, highz_threshold
,
108 lowz_threshold
, low_threshold
,
109 edge_state
, edge_toggle
);