Changeset 9890 for firmware/FTU/counter


Ignore:
Timestamp:
08/24/10 13:39:00 (14 years ago)
Author:
weitzel
Message:
overflow register implemented for FTU rate counter
File:
1 edited

Legend:

Unmodified
Added
Removed
  • firmware/FTU/counter/FTU_rate_counter.vhd

    r9880 r9890  
    3939    trigger    : in  std_logic;
    4040    prescaling : in  std_logic_vector(7 downto 0);
    41     counts     : out integer range 0 to 2**16 - 1;
    42     overflow   : out std_logic
     41    counts     : out integer range 0 to 2**16 - 1 := 0;
     42    overflow   : out std_logic := '0';
     43    new_rate   : out std_logic
    4344  );
    4445end FTU_rate_counter;
     
    5152  signal clk_1M_sig      : std_logic;
    5253  signal overflow_sig    : std_logic := '0';
     54  signal new_rate_sig    : std_logic := '0';
    5355 
    5456  component Clock_Divider
     
    6769    );
    6870 
    69   process(cntr_reset, clk_1M_sig)   
     71  process(cntr_reset, clk_1M_sig)
     72
    7073    variable clk_cntr : integer range 0 to 128*COUNTER_FREQUENCY := 0;
     74
    7175  begin
    72     if (cntr_reset = '1') then
    73       counting_period <= ((conv_integer(unsigned(prescaling)) + 1) / 2)*COUNTER_FREQUENCY;
    74       clk_cntr := 0;
     76
     77    if rising_edge(cntr_reset) then
     78     
     79      --formula to calculate counting period from prescaling value
     80      if (prescaling = "00000000") then
     81        counting_period <= COUNTER_FREQUENCY / (2 * CNTR_FREQ_DIVIDER);
     82      else
     83        counting_period <= ((conv_integer(unsigned(prescaling)) + 1) / 2) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER);
     84      end if;
     85     
     86      clk_cntr := 0;     
    7587      period_finished <= '1';
     88      new_rate_sig <= '0';
     89      counts <= 0;
     90      overflow <= '0';
     91     
    7692    elsif rising_edge(clk_1M_sig) then
    7793      if (clk_cntr < counting_period - 1) then
    7894        clk_cntr := clk_cntr + 1;
    7995        period_finished <= '0';
     96        new_rate_sig <= '0';
    8097      else
    8198        clk_cntr := 0;
    8299        period_finished <= '1';
     100        new_rate_sig <= '1';
    83101        counts <= trigger_counts;
     102        overflow <= overflow_sig;
    84103      end if;
    85104    end if;
     
    90109    if rising_edge(period_finished) then
    91110      trigger_counts <= 0;
     111      overflow_sig <= '0';
    92112    else
    93113      if rising_edge(trigger) then
    94         trigger_counts <= trigger_counts + 1;
     114        if (trigger_counts < 2**16 - 1) then
     115          trigger_counts <= trigger_counts + 1;
     116        else
     117          trigger_counts <= 0;
     118          overflow_sig <= '1';
     119        end if;
    95120      end if;
    96121    end if;
    97122  end process;
    98 
    99   overflow <= overflow_sig;
     123 
     124  new_rate <= new_rate_sig;
    100125 
    101126end Behavioral;
Note: See TracChangeset for help on using the changeset viewer.