From 43926574da1f2423e059487b0eb6c0c254c2dd2b Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 4 Oct 2023 16:29:55 -0700 Subject: [PATCH] shuttler: remove sdm constants --- artiq/gateware/shuttler.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/artiq/gateware/shuttler.py b/artiq/gateware/shuttler.py index 9d772cd72..9728a0a1d 100644 --- a/artiq/gateware/shuttler.py +++ b/artiq/gateware/shuttler.py @@ -100,12 +100,15 @@ class SigmaDeltaModulator(Module): self.x = Signal(x_width) self.y = Signal(y_width) - # The SDM cannot represent any sample >0x7ffc with pulse modulation - # Allowing pulse modulation on values >0x7ffc may overflow the - # accumulator, so the DAC code becomes 0x2000 -> -10.V. + # SDM can at most output the max DAC code `Replicate(1, y_width-1)`, + # which represents the sample of value + # `Replicate(1, y_width-1) << (x_width-y_width)`. + # + # If the input sample exceeds such limit, SDM may overflow. x_capped = Signal(x_width) - self.comb += If((self.x & 0xfffc) == 0x7ffc, - x_capped.eq(0x7ffc), + max_dac_code = Replicate(1, (y_width-1)) + self.comb += If(self.x[x_width-y_width:] == max_dac_code, + x_capped.eq(Cat(Replicate(0, x_width-y_width), max_dac_code)), ).Else( x_capped.eq(self.x), )