I'm trying to set up a simple bruteforce convolution processor with my DE0 Nano Altera FPGA board. Here's what my code looks like :
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.numeric_bit.all;
ENTITY Convolution IS
PORT( clock : IN std_logic;
audio_in : IN unsigned(15 downto 0);
audio_out : OUT unsigned(31 downto 0) );
END Convolution;
ARCHITECTURE Convolution_Core OF Convolution IS
constant impulse_length : integer := 10;
type array16 is array(0 to impulse_length-1) of unsigned(15 downto 0);
type array32 is array(0 to impulse_length-1) of unsigned(31 downto 0);
constant impulse : array16 := (x"FFFF", x"FFFE", x"FFFD", x"FFFC",
x"FFFB", x"FFFA", x"FFF9", x"FFF8",
x"FFF7", x"FFF6");
signal audio_buffer : array16 := (others=> (others=>'0'));
signal seq_buffer : unsigned(31 downto 0);
BEGIN
process(clock)
begin
if rising_edge(clock) then
-- buffer the audio input in audio_buffer
for i in 0 to (impulse_length-2) loop
audio_buffer(i) <= audio_buffer(i+1);
end loop;
audio_buffer(impulse_length-1) <= audio_in;
for i in 0 to (impulse_length-1) loop
if i = 0 then
seq_buffer <= audio_buffer(i) * impulse(impulse_length-1-i);
else
seq_buffer <= seq_buffer + audio_buffer(i) * impulse(impulse_length-1-i);
end if;
end loop;
end if;
end process;
audio_out <= seq_buffer;
END Convolution_Core;
My problem is : the index of impulse(impulse_length-1-i
) doesn't decrease during the successive for loops, but the index of audio_buffer(i)
does. That's what I fond out simulating the code and figuring out why my results are wrong.
I tried to put (impulse_length-1-i
) into a signal to be able to watch it in ModelSim, and it starts at max/min 32 bits signed range (+/- 2 147 483 647) and the next cycle jumps to zero, and stays at zero.
I also tried to use a variable j
inside the process, to be able to initiate it at zero at the beginning of the process and use it as an index for my arrays instead of i and increment it after the actual calculation, but that made ModelSim to report a fatal error, can't figure out why neither.
Could someone explain me what I did wrong ?
Thanx in advance.