I am trying to implement a chain of CIC/FIR filters on an ZYNQ FPGA. Using the Xilinx FIR compiler works fine so far but I am unable to properly get all the math.
At the moment I have 2 chains of filters:
$5\times$ downsampling, passband $12.5\text{MHz}$:
→ FIR filter 2, 5x downsampling, input 17.7.0, output 17.7$625\times$ downsampling, passband $100\text{kHz}$:
→ CIC filter, $25\times$ downsampling, input 14 bit, output 16 bit
→ Compensation FIR filter, no downsampling, input 17.7, output 17.7
→ FIR filter 1, $5\times$ downsampling, input 17.7.0, output 17.7
→ FIR filter 2, $5\times$ downsampling, input 17.7.0, output 17.7
I have a 14 bit, $20\text{kHz}$ signal that I feed into both chains:
If I feed it into the first chain I sign extend the 14bit value to 17bits and add 7 zero-bits at the end (.7). I get a nice output that wins me one bit.
If I feed the signal into the second chain I directly feed the 14bit signal into the CIC filter and left-shift the output signal to only keep the 16 MSBs. I then sign extend that 16bit value to 17bit (yes I could have also just kept the first 17bits of the CIC return value, if that would be better, please tell me) and add 7 zero-bits at the end (.7) as well. The filters win me 1-2 bit until the output of the "FIR filter 1" but at the output of the "FIR filter 2" I have an output where I lost 8bit (upper 8 non-sign bits are 0). This is the exact same FIR filter that gives me +1 bit in the first ($5\times$ downsampling) chain ... This broken chain also seems to have a lot of jitter after one period ... (I can exclude overflows as the source of error as the Xilinx FIR compiler guarantees no overflows).
How can this be, what am I missing?
In the same question I would like to ask:
Let's assume all the chains finally work properly. I then will have different bit growth. Initially I knew that 14bit correspond to $2.2\text{Vpp}$ which means that 12.86bits correspond to $1\text{V}$. But now I suddenly have a 17.7bit output. How do I know where my $1\text{V}$ reference level is now? Because it has shifted some. I am quite sure that accounting just for the DC gain yields wrong results.
My waveforms:
Output $5\times$ chain:
Chain $625\times$:
I am very grateful for any hints and will gladly add more information if some more is required.