source: trunk/MultiChannelUSB/analyser.v@ 46

Last change on this file since 46 was 45, checked in by demin, 15 years ago

add fourth channel and switch from 32 to 24 bit histogram

File size: 2.0 KB
Line 
1module analyser
2 (
3 input wire clk, reset,
4 input wire data_ready,
5 input wire [1:0] uwt_flag,
6 input wire [11:0] uwt_data,
7 output wire peak_ready,
8 output wire [11:0] peak
9 );
10
11 reg [1:0] state_reg, state_next;
12 reg [3:0] counter_reg, counter_next;
13 reg peak_ready_reg, peak_ready_next;
14 reg [11:0] peak_reg, peak_next;
15 reg [15:0] buffer [15:0];
16 wire [15:0] sample;
17 wire [11:0] baseline;
18
19 integer i;
20
21 assign sample = {4'd0, uwt_data};
22 assign baseline = buffer[15][15:4];
23
24 always @(posedge clk)
25 begin
26 if (reset)
27 begin
28 state_reg <= 2'd0;
29 counter_reg <= 4'd0;
30 peak_ready_reg <= 1'b0;
31 peak_reg <= 12'd0;
32
33 for(i = 0; i <= 15; i = i + 1)
34 begin
35 buffer[i] <= 12'd0;
36 end
37 end
38 else
39 begin
40 state_reg <= state_next;
41 counter_reg <= counter_next;
42 peak_ready_reg <= peak_ready_next;
43 peak_reg <= peak_next;
44
45 if (data_ready & uwt_flag[1])
46 begin
47 for(i = 0; i < 15; i = i + 1)
48 begin
49 buffer[i+1] <= buffer[i] + sample;
50 end
51 buffer[0] <= sample;
52 end
53 end
54 end
55
56 always @*
57 begin
58 state_next = state_reg;
59 counter_next = counter_reg;
60 peak_ready_next = 1'b0;
61 peak_next = 12'd0;
62 case (state_reg)
63 0: // skip first 16 samples
64 begin
65 if (data_ready)
66 begin
67 counter_next = counter_reg + 4'd1;
68 if (&counter_reg)
69 begin
70 state_next = 2'd1;
71 end
72 end
73 end
74
75 1: // skip first 16 minima
76 begin
77 if (data_ready & uwt_flag[1])
78 begin
79 counter_next = counter_reg + 4'd1;
80 if (&counter_reg)
81 begin
82 state_next = 2'd2;
83 end
84 end
85 end
86
87 2: // calculate peak height
88 begin
89 if (data_ready & uwt_flag[0])
90 begin
91 peak_next = uwt_data - baseline;
92 peak_ready_next = 1'b1;
93 end
94 end
95
96 default:
97 begin
98 state_next = 2'd0;
99 end
100 endcase
101 end
102
103 assign peak_ready = peak_ready_reg;
104 assign peak = peak_reg;
105endmodule
Note: See TracBrowser for help on using the repository browser.