Forum Discussion
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- @kaz I think its better if I go with block average approach then because I don't want my resolution to be bad. As you said in one of the previous posts Just to make sure and clear, can you modify the code for one state below for block averager and average the block results. --- Quote End --- here is my suggestion
signal counter : integer 0 to 1023 := 0;
signal data_in_d : signed(11 downto 0) := (others => '0');
signal sum: signed(21 downto 0) := (others => '0);
-clocked process
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;
avg will get updated every 1024 samples. if you then want to average the avg (or sum) then use previous method of say 32 samples of avg enabled on the counter = 0 pulse you might also run counter from 0 to 1024 instead of 0 to 1023 for more accurate result (I believe)