Skip to content

Commit 1faf6f3

Browse files
author
nkrackow
committed
simply hardcode correct sizes
1 parent 4a0d325 commit 1faf6f3

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

iir.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Note: Migen translates the "out of range" pc mux selector to the last valid mux input.
66

77
from ast import Constant
8-
98
from migen import *
109

1110
N_COEFF = 3 # [b0, b1, a1] number of coefficients for a first order iir
@@ -16,9 +15,9 @@ def __init__(self):
1615
# xilinx dsp architecture (subset)
1716
self.a = a = Signal((25, True), reset_less=True)
1817
self.b = b = Signal((18, True), reset_less=True)
19-
self.c = c = Signal((len(a) + len(b), True), reset_less=True)
18+
self.c = c = Signal((41, True), reset_less=True)
2019
self.mux_p = mux_p = Signal() # accumulator mux
21-
self.m = m = Signal((len(a) + len(b), True), reset_less=True)
20+
self.m = m = Signal((43, True), reset_less=True)
2221
self.p = p = Signal((48, True), reset_less=True)
2322
self.sync += [m.eq(a * b), p.eq(m + c), If(mux_p, p.eq(m + p))]
2423

@@ -78,7 +77,7 @@ def __init__(self, w_coeff, w_data, log2_a0, n_profiles, n_channels):
7877
self.submodules.dsp = dsp = Dsp()
7978
assert w_data <= len(dsp.b)
8079
assert w_coeff <= len(dsp.a)
81-
shift_c = len(dsp.a) + len(dsp.b) - w_data
80+
shift_c = len(dsp.a) + len(dsp.b) - w_data - (w_data - log2_a0)
8281
shift_a = len(dsp.a) - w_coeff
8382
shift_b = len(dsp.b) - w_data
8483
# +1 from standard sign bit
@@ -133,7 +132,7 @@ def __init__(self, w_coeff, w_data, log2_a0, n_profiles, n_channels):
133132
ch_profile_last_ch.eq(ch_profile[channel_index - 1]),
134133
[o.eq(y1[ch_profile[ch]][ch]) for ch, o in enumerate(outp)],
135134
# clipping to positive output range
136-
y0_clipped.eq(dsp.p >> (shift_c - (w_data - log2_a0))),
135+
y0_clipped.eq(dsp.p >> shift_c),
137136
If(
138137
dsp.p[-n_sign:] != 0, # if out of output range
139138
y0_clipped.eq((1 << w_data - 1) - 1),

0 commit comments

Comments
 (0)