source: trunk/3DEES/amplitude.v@ 179

Last change on this file since 179 was 178, checked in by demin, 11 years ago

adapt to 6ch

File size: 2.8 KB
RevLine 
[107]1module amplitude
[123]2 #(
3 parameter width = 12 // bit width of the input data
4 )
[107]5 (
[123]6 input wire clock, frame, reset,
[178]7 input wire [width-1:0] min_data,
8 input wire [width-1:0] max_data,
[123]9 input wire [width-1:0] inp_data,
10 output wire [width-1:0] out_data,
[178]11 output wire [1:0] out_flag
[107]12 );
13
[123]14 reg int_case_reg, int_case_next;
15 reg out_flag_reg, out_flag_next;
16 reg int_flag_reg, int_flag_next;
17 reg [width-1:0] int_mini_reg, int_mini_next;
18 reg [width-1:0] out_data_reg, out_data_next;
[155]19 reg [width-1:0] inp_data_reg [1:0], inp_data_next [1:0];
[107]20
[123]21 wire int_comp_wire;
22 reg int_comp_reg, int_comp_next;
23
[178]24 reg [5:0] int_cntr_reg, int_cntr_next;
25
[155]26 assign int_comp_wire = (inp_data_reg[1] < inp_data);
[123]27
[107]28 always @(posedge clock)
29 begin
30 if (reset)
31 begin
[123]32 int_case_reg <= 1'b0;
33 int_mini_reg <= {(width){1'b0}};
[155]34 inp_data_reg[0] <= {(width){1'b0}};
35 inp_data_reg[1] <= {(width){1'b0}};
[123]36 out_data_reg <= {(width){1'b0}};
37 out_flag_reg <= 1'b0;
38 int_flag_reg <= 1'b0;
39 int_comp_reg <= 1'b0;
[178]40 int_cntr_reg <= 6'd0;
[107]41 end
42 else
43 begin
[123]44 int_case_reg <= int_case_next;
45 int_mini_reg <= int_mini_next;
[155]46 inp_data_reg[0] <= inp_data_next[0];
47 inp_data_reg[1] <= inp_data_next[1];
[123]48 out_data_reg <= out_data_next;
49 out_flag_reg <= out_flag_next;
50 int_flag_reg <= int_flag_next;
51 int_comp_reg <= int_comp_next;
[178]52 int_cntr_reg <= int_cntr_next;
[107]53 end
54 end
55
56 always @*
57 begin
[123]58 int_case_next = int_case_reg;
59 int_mini_next = int_mini_reg;
[155]60 inp_data_next[0] = inp_data_reg[0];
61 inp_data_next[1] = inp_data_reg[1];
[123]62 out_data_next = out_data_reg;
63 out_flag_next = out_flag_reg;
64 int_flag_next = int_flag_reg;
65 int_comp_next = int_comp_reg;
[178]66 int_cntr_next = int_cntr_reg;
[107]67
[123]68 case (int_case_reg)
[107]69 0:
70 begin
71 if (frame)
72 begin
[155]73 inp_data_next[0] = inp_data;
74 inp_data_next[1] = inp_data_reg[0];
[123]75 int_comp_next = int_comp_wire;
76 out_data_next = {(width){1'b0}};
77 out_flag_next = 1'b0;
[107]78 // minimum
[178]79 if ((~int_comp_reg) & (int_comp_wire) & int_cntr_reg[5])
[107]80 begin
[155]81 int_mini_next = inp_data_reg[0];
[123]82 int_flag_next = 1'b1;
[107]83 end
[178]84 // maximum after minimum
[123]85 else if ((int_comp_reg) & (~int_comp_wire) & (int_flag_reg))
[107]86 begin
[155]87 out_data_next = inp_data_reg[0] - int_mini_reg;
[123]88 int_flag_next = 1'b0;
89 int_case_next = 1'b1;
[107]90 end
[178]91 else if (~int_cntr_reg[5])
92 begin
93 int_cntr_next = int_cntr_reg + 6'd1;
94 end
[107]95 end
96 end
97
98 1:
99 begin
[178]100 if (out_data_reg > min_data)
101 begin
102 int_cntr_next = 6'b0;
103// out_flag_next = 1'b1;
104 out_flag_next = (inp_data_reg[1] < max_data);
105 end
[123]106 int_case_next = 1'b0;
[107]107 end
108
109 endcase
110 end
111
[123]112 assign out_data = out_data_reg;
[178]113 assign out_flag = {~int_cntr_reg[5], out_flag_reg};
[107]114
115endmodule
Note: See TracBrowser for help on using the repository browser.