Changeset 90 for trunk/MultiChannelUSB/analyser.v
- Timestamp:
- Feb 27, 2010, 10:10:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/analyser.v
r89 r90 1 1 module analyser 2 2 ( 3 input wire cl k, reset,4 input wire data_ready,3 input wire clock, frame, reset, 4 input wire [12:0] cfg_data, 5 5 input wire [1:0] uwt_flag, 6 output wire peak_ready 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 7 10 ); 8 11 9 reg flag_reg, flag_next; 10 reg [1:0] state_reg, state_next; 12 reg state_reg, state_next; 11 13 reg [4:0] counter_reg, counter_next; 12 reg peak_ready_reg; 14 reg good_reg, good_next; 15 reg [11:0] data_reg, data_next; 13 16 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]; 14 22 wire counter_max = (&counter_reg); 15 wire peak_ready_int = (flag_reg & data_ready & uwt_flag[0] & counter_max);16 23 17 always @(posedge clk) 24 integer i; 25 26 always @(posedge clock) 18 27 begin 19 28 if (reset) 20 29 begin 21 flag_reg <= 1'b0; 22 state_reg <= 2'd0; 30 state_reg <= 1'b0; 23 31 counter_reg <= 5'd0; 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 24 38 end 25 39 else 26 40 begin 27 flag_reg <= flag_next;28 41 state_reg <= state_next; 29 42 counter_reg <= counter_next; 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 30 50 end 31 51 end … … 33 53 always @* 34 54 begin 35 flag_next = flag_reg;36 55 state_next = state_reg; 37 56 counter_next = counter_reg; 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 38 65 case (state_reg) 39 0: // skip first 16samples66 0: // skip first 32 samples 40 67 begin 41 flag_next = 1'b0; 42 if (data_ready) 68 if (frame) 43 69 begin 44 70 counter_next = counter_reg + 5'd1; 45 71 if (counter_max) 46 72 begin 47 state_next = 2'd1;73 state_next = 1'b1; 48 74 end 49 75 end 50 76 end 51 77 52 1: // skip first 16 minima78 1: 53 79 begin 54 flag_next = 1'b0; 55 if (data_ready & uwt_flag[1]) 80 if (frame) 56 81 begin 57 counter_next = counter_reg + 5'd1; 82 83 if (cfg_data[12]) 84 begin 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 93 end 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 105 106 107 for(i = 0; i < 31; i = i + 1) 108 begin 109 buffer_next[i+1] = buffer_reg[i] + sample; 110 end 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 58 117 if (counter_max) 59 118 begin 60 state_next = 2'd2; 119 if (uwt_flag[0]) 120 begin 121 counter_next = 5'd0; 122 end 61 123 end 62 end 63 end 64 65 2: 66 begin 67 flag_next = 1'b1; 68 if (data_ready) 69 begin 70 if (~counter_max) 124 else 71 125 begin 72 126 counter_next = counter_reg + 5'd1; 73 127 end 74 if (peak_ready_int) 75 begin 76 counter_next = 5'd0; 77 end 78 end 79 end 80 81 default: 82 begin 83 flag_next = 1'b0; 84 state_next = 2'd0; 85 counter_next = 5'd0; 128 end 86 129 end 87 130 endcase 88 131 end 89 132 90 assign peak_ready = peak_ready_int; 133 assign ana_good = good_reg; 134 assign ana_data = data_reg; 135 assign ana_base = baseline; 91 136 92 137 endmodule
Note:
See TracChangeset
for help on using the changeset viewer.