source: trunk/MultiChannelUSB/analyser.v@ 98

Last change on this file since 98 was 90, checked in by demin, 15 years ago

full rewrite

File size: 2.5 KB
RevLine 
[44]1module analyser
2 (
[90]3 input wire clock, frame, reset,
4 input wire [12:0] cfg_data,
[44]5 input wire [1:0] uwt_flag,
[90]6 input wire [11:0] uwt_data,
7 output wire ana_good,
8 output wire [11:0] ana_data,
9 output wire [11:0] ana_base
[44]10 );
11
[90]12 reg state_reg, state_next;
[84]13 reg [4:0] counter_reg, counter_next;
[90]14 reg good_reg, good_next;
15 reg [11:0] data_reg, data_next;
[44]16
[90]17 reg [19:0] buffer_reg [31:0];
18 reg [19:0] buffer_next [31:0];
19
20 wire [19:0] sample = {8'd0, uwt_data};
21 wire [11:0] baseline = buffer_reg[31][16:5];
[76]22 wire counter_max = (&counter_reg);
23
[90]24 integer i;
25
26 always @(posedge clock)
[44]27 begin
28 if (reset)
29 begin
[90]30 state_reg <= 1'b0;
[84]31 counter_reg <= 5'd0;
[90]32 good_reg <= 1'b0;
33 data_reg <= 12'd0;
34 for(i = 0; i <= 31; i = i + 1)
35 begin
36 buffer_reg[i] <= 20'hfffff;
37 end
[44]38 end
39 else
40 begin
41 state_reg <= state_next;
42 counter_reg <= counter_next;
[90]43 good_reg <= good_next;
44 data_reg <= data_next;
45
46 for(i = 0; i <= 31; i = i + 1)
47 begin
48 buffer_reg[i] <= buffer_next[i];
49 end
[44]50 end
51 end
52
53 always @*
54 begin
55 state_next = state_reg;
56 counter_next = counter_reg;
[90]57 good_next = good_reg;
58 data_next = data_reg;
59
60 for(i = 0; i <= 31; i = i + 1)
61 begin
62 buffer_next[i] = buffer_reg[i];
63 end
64
[44]65 case (state_reg)
[90]66 0: // skip first 32 samples
[44]67 begin
[90]68 if (frame)
[44]69 begin
[84]70 counter_next = counter_reg + 5'd1;
[76]71 if (counter_max)
[44]72 begin
[90]73 state_next = 1'b1;
[44]74 end
75 end
76 end
77
[90]78 1:
[44]79 begin
[90]80 if (frame)
[44]81 begin
[90]82
83 if (cfg_data[12])
[44]84 begin
[90]85 if (uwt_data > baseline)
86 begin
87 data_next = uwt_data - baseline;
88 end
89 else
90 begin
91 data_next = 12'd0;
92 end
[44]93 end
[90]94 else
95 begin
96 if (uwt_data > cfg_data[11:0])
97 begin
98 data_next = uwt_data - cfg_data[11:0];
99 end
100 else
101 begin
102 data_next = 12'd0;
103 end
104 end
[44]105
[90]106
107 for(i = 0; i < 31; i = i + 1)
[76]108 begin
[90]109 buffer_next[i+1] = buffer_reg[i] + sample;
[76]110 end
[90]111 buffer_next[0] = sample;
112
113 good_next = uwt_flag[0] & counter_max;
114
115 // skip first 32 baseline samples
116 // skip 32 samples after peak
117 if (counter_max)
[84]118 begin
[90]119 if (uwt_flag[0])
120 begin
121 counter_next = 5'd0;
122 end
[84]123 end
[90]124 else
125 begin
126 counter_next = counter_reg + 5'd1;
127 end
128 end
[44]129 end
130 endcase
131 end
132
[90]133 assign ana_good = good_reg;
134 assign ana_data = data_reg;
135 assign ana_base = baseline;
[89]136
[44]137endmodule
Note: See TracBrowser for help on using the repository browser.