source: trunk/MultiChannelUSB/analyser.v@ 86

Last change on this file since 86 was 84, checked in by demin, 15 years ago

improve timings in all components

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