- Timestamp:
- 08/24/10 13:39:00 (14 years ago)
- Location:
- firmware/FTU
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FTU/FTU_control.vhd
r9880 r9890 42 42 ram_dob : IN STD_LOGIC_VECTOR(15 downto 0); 43 43 rate_array : IN rate_array_type; 44 overflow_array : in STD_LOGIC_VECTOR(7 downto 0); 45 new_rates : IN std_logic; 44 46 reset : OUT std_logic; 45 47 config_start : OUT std_logic; … … 73 75 "0000000000000000");--patch D 74 76 75 signal rate_array_sig : rate_array_type; -- initialized in FTU_top 77 signal rate_array_sig : rate_array_type; -- initialized in FTU_top 76 78 signal cntr_reset_sig : STD_LOGIC := '0'; 77 signal prescaling_sig : STD_LOGIC_VECTOR(7 downto 0) := "000 00000";79 signal prescaling_sig : STD_LOGIC_VECTOR(7 downto 0) := "00011101"; -- 29 78 80 79 81 signal ram_ena_sig : STD_LOGIC := '0'; -- RAM enable for port A … … 87 89 88 90 --counter to loop through RAM 89 signal ram_ada_cntr : INTEGER range 0 to 2**RAM_ADDR_WIDTH_A := 0; 90 signal ram_adb_cntr : INTEGER range 0 to 2**RAM_ADDR_WIDTH_B := 0; 91 signal ram_dac_cntr : INTEGER range 0 to (NO_OF_DAC - NO_OF_DAC_NOT_USED + 2) := 0; 92 signal ram_enable_cntr : INTEGER range 0 to (NO_OF_ENABLE + 1) := 0; 93 91 signal ram_ada_cntr : INTEGER range 0 to 2**RAM_ADDR_WIDTH_A := 0; 92 signal ram_adb_cntr : INTEGER range 0 to 2**RAM_ADDR_WIDTH_B := 0; 93 signal ram_dac_cntr : INTEGER range 0 to (NO_OF_DAC - NO_OF_DAC_NOT_USED + 2) := 0; 94 signal ram_enable_cntr : INTEGER range 0 to (NO_OF_ENABLE + 1) := 0; 95 signal ram_counter_cntr : INTEGER range 0 to (NO_OF_COUNTER + 2) := 0; --includes overflow register 96 94 97 signal wait_cntr : INTEGER range 0 to 2**RAM_ADDR_WIDTH_A := 0; 98 99 signal new_rates_sig : STD_LOGIC := '0'; 100 signal new_rates_busy : STD_LOGIC := '0'; 95 101 96 102 signal new_DACs_in_RAM : STD_LOGIC := '0'; … … 98 104 signal new_prescaling_in_RAM : STD_LOGIC := '0'; 99 105 100 type FTU_control_StateType is (IDLE, INIT, RUNNING, CONFIG_ENABLE, CONFIG_DAC, CONFIG_COUNTER, RESET_ALL);106 type FTU_control_StateType is (IDLE, INIT, RUNNING, CONFIG_ENABLE, CONFIG_DAC, CONFIG_COUNTER, WRITE_RATES, RESET_ALL); 101 107 signal FTU_control_State : FTU_control_StateType; 102 108 … … 117 123 config_start_sig <= '0'; 118 124 ram_ena_sig <= '0'; 119 ram_wea_sig <= "0"; 125 ram_wea_sig <= "0"; 120 126 if (clk_ready = '1') then 121 127 FTU_control_State <= INIT; … … 124 130 when INIT => -- load default config data to RAM, see also ftu_definitions.vhd for more info 125 131 reset_sig <= '0'; 132 new_rates_busy <= '1'; 126 133 config_start_sig <= '0'; 127 134 ram_ena_sig <= '1'; … … 175 182 new_enables_in_RAM <= '1'; 176 183 new_prescaling_in_RAM <= '1'; 184 cntr_reset_sig <= '1'; 185 new_rates_busy <= '0'; 177 186 FTU_control_State <= RUNNING; 178 187 end if; 179 188 180 189 when RUNNING => -- count triggers and react to commands from FTM 190 cntr_reset_sig <= '0'; 181 191 reset_sig <= '0'; 182 192 config_start_sig <= '0'; 183 if (new_DACs_in_RAM = '1') then 184 ram_enb_sig <= '1'; 185 ram_adb_sig <= conv_std_logic_vector((NO_OF_ENABLE + NO_OF_COUNTER), RAM_ADDR_WIDTH_B); 186 FTU_control_State <= CONFIG_DAC; 187 elsif (new_DACs_in_RAM = '0' and new_enables_in_RAM = '1') then 188 ram_enb_sig <= '1'; 189 ram_adb_sig <= conv_std_logic_vector(0, RAM_ADDR_WIDTH_B); 190 FTU_control_State <= CONFIG_ENABLE; 191 elsif (new_DACs_in_RAM = '0' and new_enables_in_RAM = '0' and new_prescaling_in_RAM = '1') then 192 ram_ena_sig <= '1'; 193 ram_ada_sig <= conv_std_logic_vector((NO_OF_ENABLE*RAM_ADDR_RATIO + NO_OF_COUNTER*RAM_ADDR_RATIO + (NO_OF_DAC - NO_OF_DAC_NOT_USED)*RAM_ADDR_RATIO), RAM_ADDR_WIDTH_A); 194 FTU_control_State <= CONFIG_COUNTER; 195 else 196 FTU_control_State <= RUNNING; 193 if (new_rates_sig = '1') then 194 FTU_control_State <= WRITE_RATES; 195 else 196 if (new_DACs_in_RAM = '1') then 197 ram_enb_sig <= '1'; 198 ram_adb_sig <= conv_std_logic_vector((NO_OF_ENABLE + NO_OF_COUNTER), RAM_ADDR_WIDTH_B); 199 FTU_control_State <= CONFIG_DAC; 200 elsif (new_DACs_in_RAM = '0' and new_enables_in_RAM = '1') then 201 ram_enb_sig <= '1'; 202 ram_adb_sig <= conv_std_logic_vector(0, RAM_ADDR_WIDTH_B); 203 FTU_control_State <= CONFIG_ENABLE; 204 elsif (new_DACs_in_RAM = '0' and new_enables_in_RAM = '0' and new_prescaling_in_RAM = '1') then 205 ram_ena_sig <= '1'; 206 ram_ada_sig <= conv_std_logic_vector((NO_OF_ENABLE*RAM_ADDR_RATIO + NO_OF_COUNTER*RAM_ADDR_RATIO + (NO_OF_DAC - NO_OF_DAC_NOT_USED)*RAM_ADDR_RATIO), RAM_ADDR_WIDTH_A); 207 FTU_control_State <= CONFIG_COUNTER; 208 else 209 FTU_control_State <= RUNNING; 210 end if; 197 211 end if; 198 212 199 213 when CONFIG_COUNTER => 200 214 wait_cntr <= wait_cntr + 1; 215 new_rates_busy <= '1'; 201 216 if (wait_cntr = 0) then 202 217 FTU_control_State <= CONFIG_COUNTER; 203 218 elsif (wait_cntr = 1) then 204 219 prescaling_sig <= ram_doa; 220 FTU_control_State <= CONFIG_COUNTER; 221 else 205 222 cntr_reset_sig <= '1'; 206 FTU_control_State <= CONFIG_COUNTER;207 else208 cntr_reset_sig <= '0';209 223 ram_ada_sig <= (others => '0'); 210 224 wait_cntr <= 0; 211 225 new_prescaling_in_RAM <= '0'; 212 226 ram_ena_sig <= '0'; 227 new_rates_busy <= '0'; 213 228 FTU_control_State <= RUNNING; 214 229 end if; … … 216 231 when CONFIG_ENABLE => 217 232 ram_enable_cntr <= ram_enable_cntr + 1; 233 new_rates_busy <= '1'; 218 234 if (ram_enable_cntr = 0) then 219 235 ram_adb_sig <= conv_std_logic_vector(ram_enable_cntr + 1, RAM_ADDR_WIDTH_B); … … 222 238 ram_adb_sig <= conv_std_logic_vector(ram_enable_cntr + 1, RAM_ADDR_WIDTH_B); 223 239 enable_array_sig(ram_enable_cntr - 1) <= ram_dob; 224 FTU_control_State <= CONFIG_ENABLE; 240 FTU_control_State <= CONFIG_ENABLE; 225 241 else 226 242 ram_adb_sig <= (others => '0'); … … 228 244 new_enables_in_RAM <= '0'; 229 245 ram_enb_sig <= '0'; 246 cntr_reset_sig <= '1'; 247 new_rates_busy <= '0'; 230 248 FTU_control_State <= RUNNING; 231 249 end if; 232 250 233 251 when CONFIG_DAC => 252 new_rates_busy <= '1'; 234 253 if (ram_dac_cntr <= (NO_OF_DAC - NO_OF_DAC_NOT_USED + 2)) then 235 254 ram_dac_cntr <= ram_dac_cntr + 1; … … 254 273 ram_dac_cntr <= 0; 255 274 new_DACs_in_RAM <= '0'; 275 cntr_reset_sig <= '1'; 276 new_rates_busy <= '0'; 256 277 FTU_control_State <= RUNNING; 257 278 elsif (config_ready = '0' and config_started = '1') then … … 263 284 end if; 264 285 end if; 265 286 287 when WRITE_RATES => -- write trigger/patch rates to RAM B and overflow register to RAM A 288 new_rates_busy <= '1'; 289 ram_counter_cntr <= ram_counter_cntr + 1; 290 if (ram_counter_cntr < NO_OF_COUNTER) then 291 ram_enb_sig <= '1'; 292 ram_web_sig <= "1"; 293 ram_adb_sig <= conv_std_logic_vector((NO_OF_ENABLE + ram_counter_cntr), RAM_ADDR_WIDTH_B); 294 ram_dib_sig <= conv_std_logic_vector(rate_array_sig(ram_counter_cntr), 16); 295 FTU_control_State <= WRITE_RATES; 296 elsif (ram_counter_cntr = NO_Of_COUNTER) then 297 ram_dib_sig <= (others => '0'); 298 ram_adb_sig <= (others => '0'); 299 ram_enb_sig <= '0'; 300 ram_web_sig <= "0"; 301 ram_ena_sig <= '1'; 302 ram_wea_sig <= "1"; 303 ram_ada_sig <= conv_std_logic_vector(NO_OF_ENABLE*RAM_ADDR_RATIO + NO_OF_COUNTER*RAM_ADDR_RATIO + (NO_OF_DAC - NO_OF_DAC_NOT_USED)*RAM_ADDR_RATIO + 1, RAM_ADDR_WIDTH_A); 304 ram_dia_sig <= overflow_array; 305 FTU_control_State <= WRITE_RATES; 306 else 307 ram_ena_sig <= '0'; 308 ram_wea_sig <= "0"; 309 ram_counter_cntr <= 0; 310 new_rates_busy <= '0'; 311 FTU_control_State <= RUNNING; 312 end if; 313 266 314 when RESET_ALL => -- reset/clear and start from scratch 267 315 reset_sig <= '1'; … … 272 320 end process FTU_control_FSM; 273 321 322 detect_new_rates: process(new_rates, new_rates_busy) 323 begin 324 if (new_rates_busy = '0' and rising_edge(new_rates)) then 325 new_rates_sig <= '1'; 326 else 327 new_rates_sig <= '0'; 328 end if; 329 end process detect_new_rates; 330 274 331 reset <= reset_sig; 275 332 … … 280 337 281 338 rate_array_sig <= rate_array; 339 282 340 cntr_reset <= cntr_reset_sig; 283 341 prescaling <= prescaling_sig; -
firmware/FTU/FTU_top.vhd
r9880 r9890 97 97 98 98 --rate counter signals 99 signal cntr_reset_sig : STD_LOGIC; -- initialized in FTU_control 100 signal rate_array_sig : rate_array_type := (0,0,0,0,0);101 signal prescaling_sig : STD_LOGIC_VECTOR(7 downto 0); 99 signal cntr_reset_sig : STD_LOGIC; -- initialized in FTU_control 100 signal rate_array_sig : rate_array_type; -- initialized by counters 101 signal prescaling_sig : STD_LOGIC_VECTOR(7 downto 0); -- initialized in FTU_control 102 102 signal overflow_array : STD_LOGIC_VECTOR(7 downto 0) := "00000000"; 103 signal new_rate_A_sig : STD_LOGIC; -- initialized by patch A counter 104 signal new_rate_B_sig : STD_LOGIC; -- initialized by patch B counter 105 signal new_rate_C_sig : STD_LOGIC; -- initialized by patch C counter 106 signal new_rate_D_sig : STD_LOGIC; -- initialized by patch D counter 107 signal new_rate_t_sig : STD_LOGIC; -- initialized by trigger counter 108 signal new_rates_sig : STD_LOGIC := '0'; 103 109 104 110 signal clk_50M_sig : STD_LOGIC; -- generated by internal DCM … … 133 139 prescaling : in std_logic_vector(7 downto 0); 134 140 counts : out integer range 0 to 2**16 - 1; 135 overflow : out std_logic 141 overflow : out std_logic; 142 new_rate : out std_logic 136 143 ); 137 144 end component; … … 146 153 ram_dob : IN STD_LOGIC_VECTOR(15 downto 0); 147 154 rate_array : IN rate_array_type; 155 overflow_array : in STD_LOGIC_VECTOR(7 downto 0); 156 new_rates : IN std_logic; 148 157 reset : OUT std_logic; 149 158 config_start : OUT std_logic; … … 206 215 enables_D <= enable_array_sig(3)(8 downto 0); 207 216 217 new_rates_sig <= new_rate_A_sig and new_rate_B_sig and new_rate_C_sig and new_rate_D_sig and new_rate_t_sig; 218 208 219 --differential input buffer for patch A 209 220 IBUFDS_LVDS_33_A : IBUFDS_LVDS_33 … … 261 272 prescaling => prescaling_sig, 262 273 counts => rate_array_sig(0), 263 overflow => overflow_array(0) 274 overflow => overflow_array(0), 275 new_rate => new_rate_A_sig 264 276 ); 265 277 … … 271 283 prescaling => prescaling_sig, 272 284 counts => rate_array_sig(1), 273 overflow => overflow_array(1) 285 overflow => overflow_array(1), 286 new_rate => new_rate_B_sig 274 287 ); 275 288 … … 281 294 prescaling => prescaling_sig, 282 295 counts => rate_array_sig(2), 283 overflow => overflow_array(2) 296 overflow => overflow_array(2), 297 new_rate => new_rate_C_sig 284 298 ); 285 299 … … 291 305 prescaling => prescaling_sig, 292 306 counts => rate_array_sig(3), 293 overflow => overflow_array(3) 307 overflow => overflow_array(3), 308 new_rate => new_rate_D_sig 294 309 ); 295 310 … … 301 316 prescaling => prescaling_sig, 302 317 counts => rate_array_sig(4), 303 overflow => overflow_array(4) 318 overflow => overflow_array(4), 319 new_rate => new_rate_t_sig 304 320 ); 305 321 … … 313 329 ram_dob => ram_dob_sig, 314 330 rate_array => rate_array_sig, 331 overflow_array => overflow_array, 332 new_rates => new_rates_sig, 315 333 reset => reset_sig, 316 334 config_start => config_start_sig, -
firmware/FTU/FTU_top_tb.vhd
r9880 r9890 210 210 wait for 5ns; 211 211 trigger_sig <= '0'; 212 wait for 100us; 212 wait for 99us; 213 trigger_sig <= '1'; 214 wait for 5ns; 215 trigger_sig <= '0'; 216 wait for 1us; 213 217 trigger_sig <= '1'; 214 218 wait for 5ns; -
firmware/FTU/counter/FTU_rate_counter.vhd
r9880 r9890 39 39 trigger : in std_logic; 40 40 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 43 44 ); 44 45 end FTU_rate_counter; … … 51 52 signal clk_1M_sig : std_logic; 52 53 signal overflow_sig : std_logic := '0'; 54 signal new_rate_sig : std_logic := '0'; 53 55 54 56 component Clock_Divider … … 67 69 ); 68 70 69 process(cntr_reset, clk_1M_sig) 71 process(cntr_reset, clk_1M_sig) 72 70 73 variable clk_cntr : integer range 0 to 128*COUNTER_FREQUENCY := 0; 74 71 75 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; 75 87 period_finished <= '1'; 88 new_rate_sig <= '0'; 89 counts <= 0; 90 overflow <= '0'; 91 76 92 elsif rising_edge(clk_1M_sig) then 77 93 if (clk_cntr < counting_period - 1) then 78 94 clk_cntr := clk_cntr + 1; 79 95 period_finished <= '0'; 96 new_rate_sig <= '0'; 80 97 else 81 98 clk_cntr := 0; 82 99 period_finished <= '1'; 100 new_rate_sig <= '1'; 83 101 counts <= trigger_counts; 102 overflow <= overflow_sig; 84 103 end if; 85 104 end if; … … 90 109 if rising_edge(period_finished) then 91 110 trigger_counts <= 0; 111 overflow_sig <= '0'; 92 112 else 93 113 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; 95 120 end if; 96 121 end if; 97 122 end process; 98 99 overflow <= overflow_sig;123 124 new_rate <= new_rate_sig; 100 125 101 126 end Behavioral; -
firmware/FTU/ftu_definitions.vhd
r9880 r9890 57 57 --internal FPGA clock frequency and rate counter frequency 58 58 constant INT_CLK_FREQUENCY : integer := 50000000; -- 50MHz 59 constant COUNTER_FREQUENCY : integer := 1000000; -- 1MHZ, has to be smaller than INT_CLK_FREQUENCY 59 constant COUNTER_FREQUENCY : integer := 1000000; -- has to be smaller than INT_CLK_FREQUENCY 60 constant CNTR_FREQ_DIVIDER : integer := 500000; 60 61 61 62 --32byte dual-port RAM, port A: 8byte, port B: 16byte
Note:
See TracChangeset
for help on using the changeset viewer.