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