Forum Discussion
Altera_Forum
Honored Contributor
13 years agookay. You mean like this:
process (clk, reset)
begin
if (reset = '1') then
out_val=0;
elsif(rising_edge(clk)) then
case state is
when out_1 =>
if done='1' then
data_out <= addr0 & bits;
counter <= counter + 1;
data_in_d <= signed(data_in);
if counter /= 0 then
sum <= sum + data_in_d;
else
sum <= (others => '0');
avg <= std_logic_vector(sum(21 downto 10));
stage(1) <= avg(11 downto 0);
for i in 2 to 31 loop
stage(i) <= stage(i-1);
end loop;
-- subtract last stage from input
sub_result <= resize(signed(avg),13) - signed(stage(31));
-- accumulate
sum_new <= sum_new + sub_result;
adc_a_out <= std_logic_vector(sum_new(16 downto 5));
end if;
state <= out_2;
endif;
end process;