summaryrefslogtreecommitdiff
path: root/cocotb_try
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 /cocotb_try
parentaf24fc893090c12af3d8e2a16fb2d86267e0955a (diff)
pdm: Using 255 seems pretty nice
Lower values have much larger DC offsets on output
Diffstat (limited to 'cocotb_try')
-rw-r--r--cocotb_try/cic3_pdm.v21
1 files changed, 9 insertions, 12 deletions
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