-
Notifications
You must be signed in to change notification settings - Fork 1
/
integrator.v
54 lines (48 loc) · 1.17 KB
/
integrator.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
// Generic integrator
// by Tomek Szczęsny 2022
//
// Digital integrator adds each "in" value to "out" register on "clk" posedge.
// This integrator works with signed integers. Output register may be wider
// than input register.
// The output register wraps on overflow (see testbench).
//
// +------------------+
// clk --->| |
// clr --->| integrator |
// in[n] ===>| |===> out[m]
// +------------------+
//
// Parameters:
// n - bit size of input wire (16)
// m - bit size of output reg, must be greater or equal to "n" (17)
//
// Ports:
// clk - input clock. Each posedge fetches "in" and updates "out".
// clr - asynchronously resets "out" register to zero.
// in[n] - input data
// out[m] - output data
//
// Resources:
// m x SB_LUT
// m x SB_DFFR
`ifndef _integrator_v_
`define _integrator_v_
module integrator (
input wire clk,
input wire clr,
input wire signed [n-1:0] in,
output reg signed [m-1:0] out = 0
);
parameter n = 16;
parameter m = 17;
always @ (posedge clk, posedge clr)
begin
if (clr == 1)
begin
out <= 0;
end else begin
out <= out + in;
end
end
endmodule
`endif