-
Notifications
You must be signed in to change notification settings - Fork 0
/
max.v
39 lines (35 loc) · 953 Bytes
/
max.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
`timescale 1ns / 1ps
module max #(parameter numInput=10, inputWidth=16)
(input clk,
input [numInput*inputWidth-1:0] data,
input i_valid,
output reg [31:0] o_data,
output reg o_valid);
reg [inputWidth-1:0] maxValue;
reg [numInput*inputWidth-1:0] buffer;
integer counter;
always @(posedge clk)
begin
o_valid <= 1'b0;
if(i_valid)
begin
maxValue <= data[inputWidth-1:0];
counter = 1;
buffer <= data;
end
else if(counter == numInput)
begin
counter <= 0;
o_valid <= 1'b1;
end
else if(counter != 0)
begin
counter <= counter + 1;
if(buffer[counter*inputWidth+:inputWidth] > maxValue)
begin
maxValue <= buffer[counter*inputWidth+:inputWidth];
o_data <= counter - 1;
end
end
end
endmodule