Changeset 10037 for firmware/FTU/counter
- Timestamp:
- 10/25/10 15:29:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FTU/counter/FTU_rate_counter.vhd
r9939 r10037 15 15 -- Revision: 16 16 -- Revision 0.01 - File Created 17 -- Revision 0.02 - counter range changed from 16 to 30 bit, 19.10.2010, Q. Weitzel 18 -- Revision 0.03 - no local clock division anymore, 20.10.2010, Q. Weitzel 17 19 -- Additional Comments: 18 20 -- … … 39 41 trigger : in std_logic; 40 42 prescaling : in std_logic_vector(7 downto 0); 41 counts : out integer range 0 to 2** 16- 1 := 0;43 counts : out integer range 0 to 2**30 - 1 := 0; 42 44 overflow : out std_logic := '0'; 43 45 new_rate : out std_logic … … 49 51 signal counting_period : integer range 0 to 128*COUNTER_FREQUENCY := 128*COUNTER_FREQUENCY; 50 52 signal period_finished : std_logic := '0'; 51 signal trigger_counts : integer range 0 to 2**16 - 1 := 0; 52 signal clk_1M_sig : std_logic; 53 signal trigger_counts : integer range 0 to 2**30 - 1 := 0; 53 54 signal overflow_sig : std_logic := '0'; 54 55 signal new_rate_sig : std_logic := '0'; 55 56 component Clock_Divider 57 port( 58 clock_in : IN STD_LOGIC; 59 clock_out : OUT STD_LOGIC 60 ); 61 end component; 62 56 63 57 begin 64 58 65 Inst_Clock_Divider : Clock_Divider 66 port map ( 67 clock_in => clk, 68 clock_out => clk_1M_sig 69 ); 70 71 process(cntr_reset, clk_1M_sig) 59 process(cntr_reset, clk) 72 60 73 61 variable clk_cntr : integer range 0 to 128*COUNTER_FREQUENCY := 0; … … 83 71 overflow <= '0'; 84 72 85 elsif rising_edge(clk _1M_sig) then73 elsif rising_edge(clk) then 86 74 87 75 if (clk_cntr < counting_period - 1) then … … 106 94 else 107 95 if rising_edge(trigger) then 108 if (trigger_counts < 2** 16- 1) then96 if (trigger_counts < 2**30 - 1) then 109 97 trigger_counts <= trigger_counts + 1; 110 98 else … … 121 109 --calculate counting period from prescaling value 122 110 --default is 0.5s - 128s if CNTR_FREQ_DIVIDER = 1 123 if (prescaling = "00000000") then 124 counting_period <= COUNTER_FREQUENCY / (2 * CNTR_FREQ_DIVIDER); 125 elsif (prescaling = "11111111") then 126 counting_period <= 128 * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER); 111 --if (prescaling = "00000000") then 112 --counting_period <= COUNTER_FREQUENCY / (2 * CNTR_FREQ_DIVIDER); 113 --elsif (prescaling = "11111111") then 114 --counting_period <= 128 * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER); 115 --else 116 --counting_period <= ((conv_integer(unsigned(prescaling)) + 1) / 2) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER); 117 --end if; 118 if ((conv_integer(unsigned(prescaling))) mod 2 = 0) then 119 counting_period <= ((((conv_integer(unsigned(prescaling)) / 2)) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER)) + (COUNTER_FREQUENCY / (2 * CNTR_FREQ_DIVIDER))); 127 120 else 128 counting_period <= (( conv_integer(unsigned(prescaling)) + 1) / 2) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER);121 counting_period <= (((conv_integer(unsigned(prescaling)) - 1) / 2) + 1) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER); 129 122 end if; 130 123 end if; … … 134 127 135 128 end Behavioral; 136 137 ----------------------------------------------------------------------------------138 139 library IEEE;140 use IEEE.STD_LOGIC_1164.ALL;141 use IEEE.STD_LOGIC_ARITH.ALL;142 use IEEE.STD_LOGIC_UNSIGNED.ALL;143 144 library ftu_definitions;145 USE ftu_definitions.ftu_array_types.all;146 USE ftu_definitions.ftu_constants.all;147 148 entity Clock_Divider is149 generic(150 divider : integer := INT_CLK_FREQUENCY / COUNTER_FREQUENCY151 );152 port(153 clock_in : in std_logic;154 clock_out : out std_logic := '0'155 );156 end entity Clock_Divider;157 158 architecture RTL of Clock_Divider is159 160 begin161 162 process (clock_in)163 variable Z: integer range 0 to divider - 1;164 begin165 if rising_edge(clock_in) then166 if (Z < divider - 1) then167 Z := Z + 1;168 else169 Z := 0;170 end if;171 if (Z = 0) then172 clock_out <= '1';173 end if;174 if (Z = divider / 2) then175 clock_out <= '0';176 end if;177 end if;178 end process;179 180 end architecture RTL;
Note:
See TracChangeset
for help on using the changeset viewer.