mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-11-14 21:58:44 +08:00
3b2fee43ea
This is a new LF edge detection algorithm for the FPGA. - It uses a low-pass IIR filter to clean the signal (see https://fail0verflow.com/blog/2014/proxmark3-fpga-iir-filter.html) - The algorithm is able to detect consecutive peaks in the same direction - It uses an envelope follower to dynamically adjust the peak thresholds - The main threshold used in the envelope follower can be set from the ARM side fpga/lf_edge_detect.v, fpga/lp20khz_1MSa_iir_filter.v, fpga/min_max_tracker.v: New file. fpga/lo_edge_detect.v, fpga/fpga_lf.v: Modify accordingly. armsrc/apps.h (FPGA_CMD_SET_USER_BYTE1, FPGA_CMD_SET_EDGE_DETECT_THRESHOLD): New FPGA command. fpga/fpga_lf.v: Modify accordingly/Add a 8bit user register. fpga/fpga_lf.bit: Update accordingly. fpga/tests: New directory for testbenches fpga/tests/Makefile: New file. It compiles the testbenches and runs all the tests by default (comparing with the golden output) fpga/tests/tb_lp20khz_1MSa_iir_filter.v, fpga/tests/tb_min_max_tracker.v, fpga/tests/tb_lf_edge_detect.v: New testbenches fpga/tests/plot_edgedetect.py: New script to plot the results from the edge detection tests. fpga/tests/tb_data: New directory for data and golden outputs
74 lines
No EOL
1.5 KiB
Verilog
74 lines
No EOL
1.5 KiB
Verilog
//-----------------------------------------------------------------------------
|
|
// Copyright (C) 2014 iZsh <izsh at fail0verflow.com>
|
|
//
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
// the license.
|
|
//-----------------------------------------------------------------------------
|
|
// testbench for min_max_tracker
|
|
`include "min_max_tracker.v"
|
|
|
|
`define FIN "tb_tmp/data.filtered.gold"
|
|
`define FOUT_MIN "tb_tmp/data.min"
|
|
`define FOUT_MAX "tb_tmp/data.max"
|
|
|
|
module min_max_tracker_tb;
|
|
|
|
integer fin;
|
|
integer fout_min, fout_max;
|
|
integer r;
|
|
|
|
reg clk;
|
|
reg [7:0] adc_d;
|
|
wire [7:0] min;
|
|
wire [7:0] max;
|
|
|
|
initial
|
|
begin
|
|
clk = 0;
|
|
fin = $fopen(`FIN, "r");
|
|
if (!fin) begin
|
|
$display("ERROR: can't open the data file");
|
|
$finish;
|
|
end
|
|
fout_min = $fopen(`FOUT_MIN, "w+");
|
|
fout_max = $fopen(`FOUT_MAX, "w+");
|
|
if (!$feof(fin))
|
|
adc_d = $fgetc(fin); // read the first value
|
|
end
|
|
|
|
always
|
|
# 1 clk = !clk;
|
|
|
|
// input
|
|
initial
|
|
begin
|
|
while (!$feof(fin)) begin
|
|
@(negedge clk) adc_d <= $fgetc(fin);
|
|
end
|
|
|
|
if ($feof(fin))
|
|
begin
|
|
# 3 $fclose(fin);
|
|
$fclose(fout_min);
|
|
$fclose(fout_max);
|
|
$finish;
|
|
end
|
|
end
|
|
|
|
initial
|
|
begin
|
|
// $monitor("%d\t min: %x, max: %x", $time, min, max);
|
|
end
|
|
|
|
// output
|
|
always @(negedge clk)
|
|
if ($time > 2) begin
|
|
r = $fputc(min, fout_min);
|
|
r = $fputc(max, fout_max);
|
|
end
|
|
|
|
// module to test
|
|
min_max_tracker tracker(clk, adc_d, 8'd127, min, max);
|
|
|
|
endmodule |