source: trunk/MultiChannelUSB/analyser.v@ 101

Last change on this file since 101 was 100, checked in by demin, 15 years ago

multiple fixes

File size: 3.5 KB
RevLine 
[44]1module analyser
2 (
[90]3 input wire clock, frame, reset,
[100]4 input wire [24:0] cfg_data,
[44]5 input wire [1:0] uwt_flag,
[90]6 input wire [11:0] uwt_data,
[100]7 output wire ana_dead,
[90]8 output wire ana_good,
9 output wire [11:0] ana_data,
10 output wire [11:0] ana_base
[44]11 );
12
[100]13 reg [2:0] state_reg, state_next;
[84]14 reg [4:0] counter_reg, counter_next;
[100]15 reg dead_reg, dead_next;
[90]16 reg good_reg, good_next;
17 reg [11:0] data_reg, data_next;
[44]18
[100]19 reg [19:0] sample_reg, sample_next;
20
[90]21 reg [19:0] buffer_reg [31:0];
22 reg [19:0] buffer_next [31:0];
23
24 wire [11:0] baseline = buffer_reg[31][16:5];
[76]25 wire counter_max = (&counter_reg);
26
[90]27 integer i;
28
29 always @(posedge clock)
[44]30 begin
31 if (reset)
32 begin
[100]33 state_reg <= 3'd0;
[84]34 counter_reg <= 5'd0;
[100]35 sample_reg = 20'd0;
36 dead_reg <= 1'b0;
[90]37 good_reg <= 1'b0;
38 data_reg <= 12'd0;
[100]39
40 for (i = 0; i <= 31; i = i + 1)
[90]41 begin
42 buffer_reg[i] <= 20'hfffff;
43 end
[44]44 end
45 else
46 begin
47 state_reg <= state_next;
48 counter_reg <= counter_next;
[100]49 sample_reg <= sample_next;
50 dead_reg <= dead_next;
[90]51 good_reg <= good_next;
52 data_reg <= data_next;
53
[100]54 for (i = 0; i <= 31; i = i + 1)
[90]55 begin
56 buffer_reg[i] <= buffer_next[i];
57 end
[44]58 end
59 end
60
61 always @*
62 begin
63 state_next = state_reg;
64 counter_next = counter_reg;
[100]65 sample_next = sample_reg;
66 dead_next = dead_reg;
[90]67 good_next = good_reg;
68 data_next = data_reg;
69
[100]70 for (i = 0; i <= 31; i = i + 1)
[90]71 begin
72 buffer_next[i] = buffer_reg[i];
73 end
74
[44]75 case (state_reg)
[90]76 0: // skip first 32 samples
[44]77 begin
[90]78 if (frame)
[44]79 begin
[84]80 counter_next = counter_reg + 5'd1;
[76]81 if (counter_max)
[44]82 begin
[100]83 state_next = 3'd1;
[44]84 end
85 end
86 end
87
[100]88 1: // skip first 32 baseline samples
[44]89 begin
[90]90 if (frame)
[44]91 begin
[100]92 for (i = 0; i < 31; i = i + 1)
93 begin
94 buffer_next[i+1] = buffer_reg[i] + {8'd0, uwt_data};
95 end
96 buffer_next[0] = {8'd0, uwt_data};
[90]97
[100]98 counter_next = counter_reg + 5'd1;
99 if (counter_max)
[44]100 begin
[100]101 state_next = 3'd2;
102 end
103 end
104 end
105
106 2:
107 begin
108 if (frame)
109 begin
110
111 if (cfg_data[24])
112 begin
[90]113 if (uwt_data > baseline)
114 begin
115 data_next = uwt_data - baseline;
116 end
117 else
118 begin
119 data_next = 12'd0;
120 end
[44]121 end
[90]122 else
123 begin
[100]124 if (uwt_data > cfg_data[23:12])
[90]125 begin
[100]126 data_next = uwt_data - cfg_data[23:12];
[90]127 end
128 else
129 begin
130 data_next = 12'd0;
131 end
132 end
[100]133
134 sample_next = {8'd0, uwt_data};
[44]135
[100]136 dead_next = 1'b1;
137 good_next = 1'b0;
138
139 state_next = 3'd3;
140 end
141 end
142
143 3:
144 begin
145
146 // if (sample - baseline < threshold)
147 if (data_reg < cfg_data[11:0])
148 begin
149 for (i = 0; i < 31; i = i + 1)
[76]150 begin
[100]151 buffer_next[i+1] = buffer_reg[i] + sample_reg;
[76]152 end
[100]153 buffer_next[0] = sample_reg;
154 dead_next = 1'b0;
155 end
[90]156
[100]157 state_next = 3'd2;
158
159 // skip 32 samples after peak
160 if (counter_max)
161 begin
162 if (uwt_flag[0])
[84]163 begin
[100]164 counter_next = 5'd0;
165 state_next = 3'd4;
[84]166 end
[90]167 end
[100]168 else
169 begin
170 counter_next = counter_reg + 5'd1;
171 end
[44]172 end
[100]173
174 4:
175 begin
176 good_next = dead_reg;
177 state_next = 2'd2;
178 end
[44]179 endcase
180 end
181
[100]182 assign ana_dead = dead_reg;
[90]183 assign ana_good = good_reg;
184 assign ana_data = data_reg;
185 assign ana_base = baseline;
[89]186
[44]187endmodule
Note: See TracBrowser for help on using the repository browser.