summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Nordby <jononor@gmail.com>2025-08-09 00:01:44 +0200
committerJon Nordby <jononor@gmail.com>2025-08-09 00:09:19 +0200
commitc479b10723a1a4a5ecbc6e69d3dcc6fc7c23e125 (patch)
tree04f4d3538ec1a7056af26e7c5d969c90548d6924
parentaf24fc893090c12af3d8e2a16fb2d86267e0955a (diff)
pdm: Using 255 seems pretty nice
Lower values have much larger DC offsets on output
-rw-r--r--bindings/test_galearn_pdm.py2
-rw-r--r--cocotb_try/cic3_pdm.v21
2 files changed, 10 insertions, 13 deletions
diff --git a/bindings/test_galearn_pdm.py b/bindings/test_galearn_pdm.py
index 6fbbc4c..b55fc53 100644
--- a/bindings/test_galearn_pdm.py
+++ b/bindings/test_galearn_pdm.py
@@ -137,7 +137,7 @@ def test_dc():
out = numpy.zeros(shape=len(pdm_input)//DECIMATION, dtype=numpy.int16)
# Process using filter
- n_samples = galearn_pdm.process(pdm_input, out, 64, 0)
+ n_samples = galearn_pdm.process(pdm_input, out, 255, 0)
out = out / (2**12)
# Compensate for delay through filter
diff --git a/cocotb_try/cic3_pdm.v b/cocotb_try/cic3_pdm.v
index 3d23d44..9e96742 100644
--- a/cocotb_try/cic3_pdm.v
+++ b/cocotb_try/cic3_pdm.v
@@ -102,21 +102,18 @@ module cic3_pdm (
// Bypass DC removal
pcm_out <= scaled_out;
end else begin
- // Calculate the updated accumulator value first
- reg signed [19:0] new_accumulator;
+ // Simple leaky integrator with sign extension
case (dc_alpha)
- 8'd1: new_accumulator = dc_accumulator - (dc_accumulator >>> 12) + {{4{scaled_out[15]}}, scaled_out};
- 8'd16: new_accumulator = dc_accumulator - (dc_accumulator >>> 8) + {{4{scaled_out[15]}}, scaled_out};
- 8'd64: new_accumulator = dc_accumulator - (dc_accumulator >>> 6) + {{4{scaled_out[15]}}, scaled_out};
- 8'd255: new_accumulator = dc_accumulator - (dc_accumulator >>> 4) + {{4{scaled_out[15]}}, scaled_out};
- default: new_accumulator = dc_accumulator - (dc_accumulator >>> 8) + {{4{scaled_out[15]}}, scaled_out};
+ 8'd1: dc_accumulator <= dc_accumulator - (dc_accumulator >>> 12) + {{4{scaled_out[15]}}, scaled_out};
+ 8'd16: dc_accumulator <= dc_accumulator - (dc_accumulator >>> 8) + {{4{scaled_out[15]}}, scaled_out};
+ 8'd64: dc_accumulator <= dc_accumulator - (dc_accumulator >>> 6) + {{4{scaled_out[15]}}, scaled_out};
+ 8'd128: dc_accumulator <= dc_accumulator - (dc_accumulator >>> 5) + {{4{scaled_out[15]}}, scaled_out};
+ 8'd255: dc_accumulator <= dc_accumulator - (dc_accumulator >>> 4) + {{4{scaled_out[15]}}, scaled_out};
+ default: dc_accumulator <= dc_accumulator - (dc_accumulator >>> 8) + {{4{scaled_out[15]}}, scaled_out};
endcase
- // Update accumulator
- dc_accumulator <= new_accumulator;
-
- // Output = input - NEW DC estimate (not old one)
- pcm_out <= scaled_out - new_accumulator[19:4];
+ // Output = input - DC estimate (using OLD estimate to avoid combinational loop)
+ pcm_out <= scaled_out - dc_accumulator[19:4];
end
pcm_valid <= 1;
end