eshbonzie
Junior Member level 3
Hey guys,
Im kinda new to VHDL and trying to implement an algorithm which does the follwoing:
it compares a pixel (8 bits) with 640(640*8bits = 5120 bits) other pixels, if a match is found a matching counter is incremented to count the number of matches.
I designed an entity for this as follows:
entity MatchingalgorithmModule is
Port ( Clk : in STD_LOGIC;
En : in STD_LOGIC;
FrameLine_Bitstream : in STD_LOGIC_VECTOR (5119 downto 0);
FrameLineNumber : in STD_LOGIC_VECTOR (8 downto 0);
CenterPixel : in STD_LOGIC_VECTOR (7 downto 0);
MatchesFound : out STD_LOGIC_VECTOR (13 downto 0));
end MatchingalgorithmModule;
architecture Behavioral of MatchingalgorithmModule is
signal MatchesFound_s : STD_LOGIC_Vector(13 downto 0);
begin
process(Clk)
variable matchCount_v : integer := 0;
variable index_v : integer := 5120;
begin
if(rising_edge(Clk)) then
for i in 1 to 640 loop
if(FrameLine_Bitstream((index_v-1) downto (index_v-8)) = CenterPixel) then
matchCount_v := matchCount_v + 1;
end if;
index_v := index_v - 8 ;
end loop;
index_v := 5120;
end if;
if(Clk'event and Clk = '1') then
MatchesFound_s <= conv_std_logic_vector(matchCount_v, 14);
matchCount_v := 0;
end if;
end process;
MatchesFound <= MatchesFound_s;
end Behavioral;
I wrote a textbench to generate random values for testing the entity as follows:
stim_proc: PROCESS
VARIABLE seed1, seed2 : positive; -- Seed values for random generator
VARIABLE rand : real; -- Random real-number value in range 0 to 1.0
VARIABLE int_rand : integer; -- Random integer value in range 0..4095
VARIABLE stim : std_logic_vector(1 DOWNTO 0); -- Random 12-bit stimulus
BEGIN
for test_case_index in 8 downto 1 loop
wait until rising_edge(Clk);
UNIFORM(seed1, seed2, rand); -- generate random number
int_rand := INTEGER(TRUNC(rand*4.0));
FrameLine_Bitstream((test_case_index*2)-1 downto test_case_index*2-2) <= std_logic_vector(to_unsigned(int_rand, stim'LENGTH)); -- convert to std_logic_vector
CenterPixel <= "00000000";
--wait for Clk_period*10;
end loop;
END PROCESS;
it generates a random two by two bits for the 5120 bit input vector. The results after simulating seemed to be ok, the only thing which I worry about is
that the number of matches found decreases by one every clock cycle. Before simulating I assumed that the number of matches found should change randomly from one clock cycle to the other.
I know that a for loop is executed in one clock cycle. However I'm still curious to get some explanation about this. Is it really possible to manipulate more than
5000 bits only in one clock cycle?..if yes, what are the limits to this? also what about the previous design does it seem to be ok or is there a fatal mistake that am missing?
Thanks,
Eshbon
Im kinda new to VHDL and trying to implement an algorithm which does the follwoing:
it compares a pixel (8 bits) with 640(640*8bits = 5120 bits) other pixels, if a match is found a matching counter is incremented to count the number of matches.
I designed an entity for this as follows:
entity MatchingalgorithmModule is
Port ( Clk : in STD_LOGIC;
En : in STD_LOGIC;
FrameLine_Bitstream : in STD_LOGIC_VECTOR (5119 downto 0);
FrameLineNumber : in STD_LOGIC_VECTOR (8 downto 0);
CenterPixel : in STD_LOGIC_VECTOR (7 downto 0);
MatchesFound : out STD_LOGIC_VECTOR (13 downto 0));
end MatchingalgorithmModule;
architecture Behavioral of MatchingalgorithmModule is
signal MatchesFound_s : STD_LOGIC_Vector(13 downto 0);
begin
process(Clk)
variable matchCount_v : integer := 0;
variable index_v : integer := 5120;
begin
if(rising_edge(Clk)) then
for i in 1 to 640 loop
if(FrameLine_Bitstream((index_v-1) downto (index_v-8)) = CenterPixel) then
matchCount_v := matchCount_v + 1;
end if;
index_v := index_v - 8 ;
end loop;
index_v := 5120;
end if;
if(Clk'event and Clk = '1') then
MatchesFound_s <= conv_std_logic_vector(matchCount_v, 14);
matchCount_v := 0;
end if;
end process;
MatchesFound <= MatchesFound_s;
end Behavioral;
I wrote a textbench to generate random values for testing the entity as follows:
stim_proc: PROCESS
VARIABLE seed1, seed2 : positive; -- Seed values for random generator
VARIABLE rand : real; -- Random real-number value in range 0 to 1.0
VARIABLE int_rand : integer; -- Random integer value in range 0..4095
VARIABLE stim : std_logic_vector(1 DOWNTO 0); -- Random 12-bit stimulus
BEGIN
for test_case_index in 8 downto 1 loop
wait until rising_edge(Clk);
UNIFORM(seed1, seed2, rand); -- generate random number
int_rand := INTEGER(TRUNC(rand*4.0));
FrameLine_Bitstream((test_case_index*2)-1 downto test_case_index*2-2) <= std_logic_vector(to_unsigned(int_rand, stim'LENGTH)); -- convert to std_logic_vector
CenterPixel <= "00000000";
--wait for Clk_period*10;
end loop;
END PROCESS;
it generates a random two by two bits for the 5120 bit input vector. The results after simulating seemed to be ok, the only thing which I worry about is
that the number of matches found decreases by one every clock cycle. Before simulating I assumed that the number of matches found should change randomly from one clock cycle to the other.
I know that a for loop is executed in one clock cycle. However I'm still curious to get some explanation about this. Is it really possible to manipulate more than
5000 bits only in one clock cycle?..if yes, what are the limits to this? also what about the previous design does it seem to be ok or is there a fatal mistake that am missing?
Thanks,
Eshbon