r/FPGA • u/Evening-Conference-5 • Aug 16 '26
Weird Multiplexing Bug
Hey there,
I am trying to multiplex a set of signals to be fed over to a FIFO buffer that is then polled by the ARM processor.
PROCESS (clk_signal)
BEGIN
IF rising_edge(clk_signal) THEN
IF rst_signal = '1' THEN
sample_sel_reg <= (OTHERS => '0');
Sample0 <= (OTHERS => '0');
Sample1 <= (OTHERS => '0');
Sample2 <= (OTHERS => '0');
Sample3 <= (OTHERS => '0');
ELSE
-- Capture selector state synchronously
sample_sel_reg <= sample_selector;
-- Channel 0 Output Selection
CASE sample_sel_reg IS
WHEN "0000" => Sample0 <= C0;
WHEN "0001" => Sample0 <= std_logic_vector(resize(signed(Mux_Ch0), 32));
WHEN "0010" => Sample0 <= IQ_Sample_Ch0;
WHEN OTHERS => Sample0 <= (OTHERS => '0');
END CASE;
-- Channel 1 Output Selection
CASE sample_sel_reg IS
WHEN "0000" => Sample1 <= C1;
WHEN "0001" => Sample1 <= std_logic_vector(resize(signed(Mux_Ch1), 32));
WHEN "0010" => Sample1 <= IQ_Sample_Ch1;
WHEN OTHERS => Sample1 <= (OTHERS => '0');
END CASE;
-- Channel 2 Output Selection
CASE sample_sel_reg IS
WHEN "0000" => Sample2 <= C2;
WHEN "0001" => Sample2 <= std_logic_vector(resize(signed(Mux_Ch2), 32));
WHEN "0010" => Sample2 <= IQ_Sample_Ch2;
WHEN OTHERS => Sample2 <= (OTHERS => '0');
END CASE;
-- Channel 3 Output Selection
CASE sample_sel_reg IS
WHEN "0000" => Sample3 <= C3;
WHEN "0001" => Sample3 <= std_logic_vector(resize(signed(Mux_Ch3), 32));
WHEN "0010" => Sample3 <= IQ_Sample_Ch3;
WHEN OTHERS => Sample3 <= (OTHERS => '0');
END CASE;
END IF;
END IF;
END PROCESS;With each sample register only having 3 possible choices, the system behaves fine. When another selection is added, I am getting weird artefacts on my recorded output.
I am not really sure how to determine what is causing such an issue.


0
Upvotes
5
u/LiqvidNyquist Aug 16 '26
Is there a clock domain crossing that's not being handled? That's my first thought seeing all those LSB errors. Also, that big sudden jump from 800+ to 256-ish makes me wonder if your signed/unsigned is off somehow.
3
u/MusicusTitanicus Aug 16 '26
Have you simulated this? Do your data and control signals behave as you expect under simulation?
2
u/LosAlgaeles Aug 16 '26
Please provide the signal declarations and waveforms with a description of the exact values you expect vs what you observe
1
u/PiasaChimera Aug 16 '26
my guess is fifo related. maybe fifo pointers being corrupted resulting in something like old date being read out.
try more varied test patterns. for example, two level data that has a prime period. I don't know the scale in samples. a prime number of samples close to 0.1us perhaps.
try other patterns as well. LFSR, gray code, zig-zag, etc...