diff --git a/src/moving_average.vhd b/src/moving_average.vhd index f17a7eb..66d848e 100644 --- a/src/moving_average.vhd +++ b/src/moving_average.vhd @@ -66,13 +66,22 @@ begin overflow <= '1'; end if; if (enable = '1') then - accumulator <= accumulator + unsigned("0" & data_in) - unsigned("0" & fifo_out) when (fifo_full = '1') else accumulator + unsigned("0" & data_in); + if (fifo_full = '1') then + accumulator <= accumulator + unsigned("0" & data_in) - unsigned("0" & fifo_out); + else + accumulator <= accumulator + unsigned("0" & data_in); + end if; end if; end if; end if; end process; - average <= std_logic_vector(((log2c(WINDOW_SIZE)-1 downto 0 => '0') & accumulator(DATA_WIDTH-1 downto log2c(WINDOW_SIZE))) + 1) - when (ENABLE_ROUNDING and accumulator(log2c(WINDOW_SIZE)-1) = '1') - else std_logic_vector(((log2c(WINDOW_SIZE)-1 downto 0 => '0') & accumulator(DATA_WIDTH-1 downto log2c(WINDOW_SIZE)))); + average_prc: process(all) + begin + if (ENABLE_ROUNDING and accumulator(log2c(WINDOW_SIZE)-1) = '1') then + average <= std_logic_vector(((log2c(WINDOW_SIZE)-1 downto 0 => '0') & accumulator(DATA_WIDTH-1 downto log2c(WINDOW_SIZE))) + 1); + else + average <= std_logic_vector(((log2c(WINDOW_SIZE)-1 downto 0 => '0') & accumulator(DATA_WIDTH-1 downto log2c(WINDOW_SIZE)))); + end if; + end process; end architecture;