Forum Discussion
Altera_Forum
Honored Contributor
9 years agoOk, I have tried the code, but the operation is not as expected. This is the code:
--stimulus:
stim_proc: process
begin
wait for 10 ns;
reset_n_i <= '1';
wait for 15 ns;
enable_i <= '1';
tdc_i <= "0000111111111111111111111000000001111111111111100000000111111000";
wait for 100 ns;
tdc_i <= "0000000011111111111000000000111111100000111110000011110000111000";
wait for 1 ms;
reset_n_i <= '0';
wait for 1 ms;
reset_n_i <= '1';
wait for 1 ms;
enable_i <= '0';
wait for 1 ms;
enable_i <= '1';
wait for 1 ms;
assert False report "End simulation!" severity Failure;
end process;
p_check_tdc_out: process(reset_n_i, clk_128meg_i)
begin
if (reset_n_i = '0') then
tdc_fall_s <= (others => '0');
tdc_rise_fall_s <= (others => '0');
tdc_rise_s <= (others => '0');
elsif (clk_128meg_i'event and clk_128meg_i = '1') then
if (enable_i = '1') then
this_loop: for i in 1 to 10 loop
if (tdc_i(cnt_s) = '0') then
tdc_fall_s <= std_logic_vector(unsigned(tdc_fall_s) + 1); -- calculate the num of zeros (fall time)
elsif (tdc_i(cnt_s)= '1') then
tdc_rise_fall_s <= std_logic_vector(unsigned(tdc_rise_fall_s) + 1); -- calculate the num of 1s (rise - fall time)
exit this_loop when (tdc_i (cnt_s) = '0');
end if;
end loop;
tdc_rise_s <= std_logic_vector(unsigned(tdc_fall_s) + unsigned(tdc_rise_fall_s)); -- calculate the total number of bits for a sequence (rise time)
else
tdc_fall_s <= (others => '0');
tdc_rise_fall_s <= (others => '0');
tdc_rise_s <= (others => '0');
end if;
end if;
end process;
p_outp_check: process(clk_128meg_i)
begin
if (clk_128meg_i'event and clk_128meg_i = '0') then
assert rise_o = tdc_rise_s report " Wrong output : Rise time should be obtained" severity error;
assert rise_fall_o = tdc_rise_fall_s " Wrong output : Rise-fall time should be obtained" severity error;
end if;
end process;
end beh;
So, what I need my code to do is to calculate the number of zeros and 1s for a sequence of bits (000111111) which is actually doing the wrong way (its calculating the zeros and ones till the bit width length of tdc_fall_s and tdc_rise_fall_s). And the code should exit the loop when it sees the next zero after checking all the bits in the sequence (but its not doing so). Can you help me to solve this