Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
lpass1 Source File
1/* First-order low-pass filter (RC)
2 y[n] = y[n-1] + k(x[n] - y[n-1])
3 Pole at (1-k)
4
5 Corner frequency (fc) set by:
6 fc = k / [(1-k)*2*PI*dt]
7
8 e.g.:
9 dt = 20 ns
10 k = 0.5**21
11 fc ~= 3.7946 Hz
12
13 No need for saturated arithmetic, since gain is strictly less than unity.
14*/
15
16module lpass1 #(
17 parameter dwi = 16,
18 parameter klog2 = 21, // Actual k is 0.5**klog2; max 31
19 parameter TRIM_SHIFT = 2
20) (
21 input clk,
22 input [TRIM_SHIFT-1:0] trim_sh, // Move corner up in steps of 2x; Extra logic
23 // should disappear if hardcoded
24 input signed [dwi-1:0] din,
25 output signed [dwi-1:0] dout
26);
27 wire [4:0] full_sh = klog2 - trim_sh;
28
29 reg signed [dwi+klog2-1:0] dout_r=0;
30 wire signed [dwi+klog2:0] sub = (din<<<full_sh) - dout_r; // Shift din to buy precision
31
32 always @(posedge clk) begin
33 dout_r <= dout_r + (sub>>>full_sh);
34 end
35
36 assign dout = dout_r>>>full_sh;
37
38endmodule