Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

continuous averaging using VHDL

I have a question related to VHDL programming. I want to calculate the continuous average. My example code is:


process (clk, reset)
begin
    if (reset = '1') then    
 state<=idle;   
out-val=0;    
elsif(rising_edge(clk)) then   
 case state is
when idle =>    
if req='1' then     
state= out-1;    
end if;
when out-1 =>  
  if done='1' then  
  out-val<=data-in (11 downto 0)
 state <= done-st; 
 endif;  
  
when done-st =>   
ack <='1';   
state <= idle;    
when others =>    
state <= idle;    
end case;    
end if;    
end process;

On every positive edge of clock, the value of "out-val" changes. I want to continuously take the average of "out-val". I want to take average of 32 values continuously. Is there a way where I can take average of 32 values continuously till the clock is running. Kindly let me know how can I do that. You can modify the above code as well.

Many Thanks,

90 Replies