-
Notifications
You must be signed in to change notification settings - Fork 1
/
Average8.v
56 lines (51 loc) · 1.19 KB
/
Average8.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 14:54:06 02/15/2014
// Design Name:
// Module Name: Average8
// Project Name:
// Target Devices:
// Tool versions:
// Description: Averages 8 times
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Average8(
input CLK,
input [7:0] SampleIN,
output [7:0] AverageOUT
);
// hold the 8 averages
reg [7:0] Average [7:0];
reg [7:0] AverageOUT_;
reg [2:0] AvgIndex;
reg [10:0] Adder;
// averages all values
initial begin
Adder = 0;
AvgIndex = 0;
repeat(8) begin // reset data
Average[AvgIndex] = 0;
AvgIndex = AvgIndex+1;
end
AvgIndex = 0;
end
assign AverageOUT = AverageOUT_;
// take in values
always @ (posedge CLK) begin
// add this value to the set
Average[AvgIndex] <= SampleIN;
AvgIndex <= AvgIndex+1;
Adder <= (Average[0]+Average[1]+Average[2]+Average[3]+
Average[4]+Average[5]+Average[6]+Average[7]) >> 3;
AverageOUT_ <= Adder;
end
endmodule