Forum Discussion
Altera_Forum
Honored Contributor
13 years ago@kaz
I hope I understand you right. You mean to say the following:signal counter : integer 0 to 1024 := 0;
signal data_in_d : signed(11 downto 0) := (others => '0');
signal sum: signed(21 downto 0) := (others => '0);
signal avg : std_logic_vector (11 downto 0);
type type1 is array (1 to 31) of std_logic_vector(11 downto 0);
signal stage: type1 := (others => (others => '0'));
signal sub_result: signed(12 downto 0) := (others => '0');
signal sum_new: signed(16 downto 0) := (others => '0');
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));
end if;
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));
state <= out_2;
endif;
end process; Am I right?