| 1 |
2 |
panda_emc |
-----------------------------------------------------------------------------------------------
|
| 2 |
|
|
--
|
| 3 |
|
|
-- Copyright (C) 2011 Peter Lemmens, PANDA collaboration
|
| 4 |
|
|
-- p.j.j.lemmens@rug.nl
|
| 5 |
|
|
-- http://www-panda.gsi.de
|
| 6 |
|
|
--
|
| 7 |
|
|
-- As a reference, please use:
|
| 8 |
|
|
-- E. Guliyev, M. Kavatsyuk, P.J.J. Lemmens, G. Tambave, H. Loehner,
|
| 9 |
|
|
-- "VHDL Implementation of Feature-Extraction Algorithm for the PANDA Electromagnetic Calorimeter"
|
| 10 |
|
|
-- Nuclear Inst. and Methods in Physics Research, A ....
|
| 11 |
|
|
--
|
| 12 |
|
|
--
|
| 13 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
| 14 |
|
|
-- it under the terms of the GNU Lesser General Public License as published by
|
| 15 |
|
|
-- the Free Software Foundation; either version 3 of the License, or
|
| 16 |
|
|
-- (at your option) any later version.
|
| 17 |
|
|
--
|
| 18 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 19 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
|
|
-- GNU Lesser General Public License for more details.
|
| 22 |
|
|
--
|
| 23 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 24 |
|
|
-- along with this program; if not, write to the Free Software
|
| 25 |
|
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
|
| 26 |
|
|
--
|
| 27 |
|
|
-----------------------------------------------------------------------------------------------
|
| 28 |
|
|
-- Company : KVI (Kernfysisch Versneller Instituut -- Groningen, The Netherlands
|
| 29 |
|
|
-- Author : P.J.J. Lemmens
|
| 30 |
|
|
-- Design Name : Feature Extraction
|
| 31 |
|
|
-- Module Name : adc_flow_control.vhd
|
| 32 |
|
|
-- Description : The SIS3301/2 has several options for external triggering and turn on/off
|
| 33 |
|
|
-- It also has some requirements concerning (vme-)memory use, the most
|
| 34 |
|
|
-- important of which is that memory can only be written 2x64-bit chunks/words
|
| 35 |
|
|
-- These 64-bit chunks are written into a 32bit-wide data-fifo accompanied by
|
| 36 |
|
|
-- 32bit addresses written into a address-fifo. These write-actions have to
|
| 37 |
|
|
-- be done in groups of 4, in which each cycle contains a data-write-cycle
|
| 38 |
|
|
-- and the 2nd and 4th contain a address-write cycle. If this rule is not
|
| 39 |
|
|
-- observed, the interface fpga get screwed-up and the board has to be reset.
|
| 40 |
|
|
-- The flow-state-machine in this module takes care of this in that is keeps
|
| 41 |
|
|
-- resets pending until the proper moment and adds dummy-writecycles when
|
| 42 |
|
|
-- you run out of data unexcpetedly.
|
| 43 |
|
|
--
|
| 44 |
|
|
--
|
| 45 |
|
|
-----------------------------------------------------------------------------------------------
|
| 46 |
|
|
library IEEE;
|
| 47 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 48 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 49 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
| 50 |
|
|
|
| 51 |
|
|
entity adc_flowcontrol is
|
| 52 |
|
|
port( rst : in std_logic;
|
| 53 |
|
|
clk : in std_logic;
|
| 54 |
|
|
program_in : in std_logic;
|
| 55 |
|
|
data_available : in std_logic;
|
| 56 |
|
|
start_adc : in std_logic;
|
| 57 |
|
|
ext_trigger : in std_logic;
|
| 58 |
|
|
soft_trigger : in std_logic;
|
| 59 |
|
|
running : out std_logic;
|
| 60 |
|
|
chain_enable : out std_logic;
|
| 61 |
|
|
sync_init_out : out std_logic;
|
| 62 |
|
|
sync_rst_out : out std_logic;
|
| 63 |
|
|
rst_addr_gen_out : out std_logic;
|
| 64 |
|
|
write_count : out std_logic_vector(15 downto 0)
|
| 65 |
|
|
);
|
| 66 |
|
|
end adc_flowcontrol;
|
| 67 |
|
|
|
| 68 |
|
|
architecture Behavioral of adc_flowcontrol is
|
| 69 |
|
|
|
| 70 |
|
|
type flow_state_type is (reset_state, program_state, idle_state, start_state, word_a, word_b, word_c, word_d, no_data);
|
| 71 |
|
|
signal flow_state_S : flow_state_type := idle_state;
|
| 72 |
|
|
|
| 73 |
|
|
signal rst_S : std_logic := '1';
|
| 74 |
|
|
signal old_rst_S : std_logic := '1';
|
| 75 |
|
|
signal rst_pulse_S : std_logic := '1';
|
| 76 |
|
|
signal rst_pending_S : std_logic := '0';
|
| 77 |
|
|
signal rst_out_S : std_logic := '0';
|
| 78 |
|
|
signal clk_S : std_logic := '0';
|
| 79 |
|
|
signal program_in_S : std_logic := '0';
|
| 80 |
|
|
signal old_program_in_S : std_logic := '0';
|
| 81 |
|
|
signal program_pulse_S : std_logic := '1';
|
| 82 |
|
|
signal program_out_S : std_logic := '0';
|
| 83 |
|
|
signal data_available_S : std_logic := '0';
|
| 84 |
|
|
signal start_adc_S : std_logic := '0';
|
| 85 |
|
|
signal old_start_adc_S : std_logic := '0';
|
| 86 |
|
|
signal ext_trigger_S : std_logic := '0';
|
| 87 |
|
|
signal old_ext_trigger_S : std_logic := '0';
|
| 88 |
|
|
signal soft_trigger_S : std_logic := '0';
|
| 89 |
|
|
signal old_soft_trigger_S : std_logic := '0';
|
| 90 |
|
|
signal trigger_pulse_S : std_logic := '0';
|
| 91 |
|
|
signal start_pulse_S : std_logic := '0';
|
| 92 |
|
|
signal terminate_S : std_logic := '0';
|
| 93 |
|
|
signal chain_enable_S : std_logic := '0';
|
| 94 |
|
|
signal rst_addr_gen_S : std_logic := '0';
|
| 95 |
|
|
signal running_S : std_logic := '0';
|
| 96 |
|
|
signal write_count_S : std_logic_vector(15 downto 0) := (others => '0');
|
| 97 |
|
|
|
| 98 |
|
|
begin
|
| 99 |
|
|
|
| 100 |
|
|
clk_S <= clk;
|
| 101 |
|
|
rst_S <= rst;
|
| 102 |
|
|
program_in_S <= program_in;
|
| 103 |
|
|
data_available_S <= data_available;
|
| 104 |
|
|
start_adc_S <= start_adc;
|
| 105 |
|
|
ext_trigger_S <= ext_trigger;
|
| 106 |
|
|
soft_trigger_S <= soft_trigger;
|
| 107 |
|
|
chain_enable <= chain_enable_S;
|
| 108 |
|
|
running <= running_S;
|
| 109 |
|
|
write_count <= write_count_S;
|
| 110 |
|
|
|
| 111 |
|
|
sync_init_out <= program_out_S;
|
| 112 |
|
|
sync_rst_out <= rst_out_S;
|
| 113 |
|
|
rst_addr_gen_out <= rst_addr_gen_S;
|
| 114 |
|
|
|
| 115 |
|
|
fsm_flow_state_control : process(clk_S, rst, rst_S, program_in, program_in_S)
|
| 116 |
|
|
begin
|
| 117 |
|
|
if rising_edge(clk_S) then
|
| 118 |
|
|
|
| 119 |
|
|
case flow_state_S is
|
| 120 |
|
|
when idle_state =>
|
| 121 |
|
|
if (rst = '1') or (rst_pulse_S = '1') or (program_pulse_S = '1') then
|
| 122 |
|
|
flow_state_S <= reset_state;
|
| 123 |
|
|
elsif (start_pulse_S = '1') then
|
| 124 |
|
|
flow_state_S <= start_state;
|
| 125 |
|
|
write_count_S <= (others => '0');
|
| 126 |
|
|
else
|
| 127 |
|
|
flow_state_S <= flow_state_S;
|
| 128 |
|
|
end if;
|
| 129 |
|
|
when no_data =>
|
| 130 |
|
|
if (rst_pulse_S = '1') or (program_pulse_S = '1') then
|
| 131 |
|
|
flow_state_S <= reset_state;
|
| 132 |
|
|
elsif (trigger_pulse_S) = '1' then
|
| 133 |
|
|
terminate_S <= '0';
|
| 134 |
|
|
flow_state_S <= idle_state;
|
| 135 |
|
|
elsif (data_available_S = '1') then
|
| 136 |
|
|
flow_state_S <= word_a;
|
| 137 |
|
|
else
|
| 138 |
|
|
flow_state_S <= flow_state_S;
|
| 139 |
|
|
end if;
|
| 140 |
|
|
when reset_state =>
|
| 141 |
|
|
if (rst = '0') then
|
| 142 |
|
|
rst_pending_S <= '0';
|
| 143 |
|
|
flow_state_S <= program_state;
|
| 144 |
|
|
else
|
| 145 |
|
|
flow_state_S <= no_data;
|
| 146 |
|
|
end if;
|
| 147 |
|
|
when program_state =>
|
| 148 |
|
|
if ((rst = '1')) then
|
| 149 |
|
|
flow_state_S <= reset_state;
|
| 150 |
|
|
else
|
| 151 |
|
|
flow_state_S <= idle_state;
|
| 152 |
|
|
end if;
|
| 153 |
|
|
when start_state =>
|
| 154 |
|
|
if (rst_pulse_S = '1') or (program_pulse_S = '1') then
|
| 155 |
|
|
flow_state_S <= reset_state;
|
| 156 |
|
|
elsif (data_available_S = '1') then
|
| 157 |
|
|
flow_state_S <= word_a;
|
| 158 |
|
|
else
|
| 159 |
|
|
flow_state_S <= no_data;
|
| 160 |
|
|
end if;
|
| 161 |
|
|
when word_a =>
|
| 162 |
|
|
if (rst_pulse_S = '1') or (program_pulse_S = '1') then
|
| 163 |
|
|
rst_pending_S <= '1';
|
| 164 |
|
|
elsif (trigger_pulse_S) = '1' then
|
| 165 |
|
|
terminate_S <= '1';
|
| 166 |
|
|
end if;
|
| 167 |
|
|
flow_state_S <= word_b;
|
| 168 |
|
|
write_count_S <= write_count_S + 1;
|
| 169 |
|
|
when word_b =>
|
| 170 |
|
|
if (rst_pulse_S = '1') or (program_pulse_S = '1') then
|
| 171 |
|
|
rst_pending_S <= '1';
|
| 172 |
|
|
elsif (trigger_pulse_S) = '1' then
|
| 173 |
|
|
terminate_S <= '1';
|
| 174 |
|
|
end if;
|
| 175 |
|
|
flow_state_S <= word_c;
|
| 176 |
|
|
write_count_S <= write_count_S + 1;
|
| 177 |
|
|
when word_c =>
|
| 178 |
|
|
if (rst_pulse_S = '1') or (program_pulse_S = '1') then
|
| 179 |
|
|
rst_pending_S <= '1';
|
| 180 |
|
|
elsif (trigger_pulse_S) = '1' then
|
| 181 |
|
|
terminate_S <= '1';
|
| 182 |
|
|
end if;
|
| 183 |
|
|
flow_state_S <= word_d;
|
| 184 |
|
|
write_count_S <= write_count_S + 1;
|
| 185 |
|
|
when word_d =>
|
| 186 |
|
|
if (rst_pulse_S = '1') or (program_pulse_S = '1') or (rst_pending_S = '1') then
|
| 187 |
|
|
rst_pending_S <= '0';
|
| 188 |
|
|
flow_state_S <= reset_state;
|
| 189 |
|
|
elsif (terminate_S = '1') or (trigger_pulse_S = '1') then
|
| 190 |
|
|
terminate_S <= '0';
|
| 191 |
|
|
flow_state_S <= idle_state;
|
| 192 |
|
|
elsif (data_available_S = '0') then
|
| 193 |
|
|
flow_state_S <= no_data;
|
| 194 |
|
|
else
|
| 195 |
|
|
flow_state_S <= word_a; -- running_S and chain_enable are allready '1'
|
| 196 |
|
|
end if;
|
| 197 |
|
|
write_count_S <= write_count_S + 1;
|
| 198 |
|
|
end case;
|
| 199 |
|
|
end if;
|
| 200 |
|
|
end process;
|
| 201 |
|
|
|
| 202 |
|
|
output_signals : process(flow_state_S)
|
| 203 |
|
|
begin
|
| 204 |
|
|
case flow_state_S is
|
| 205 |
|
|
when idle_state =>
|
| 206 |
|
|
chain_enable_S <= '0';
|
| 207 |
|
|
running_S <= '0';
|
| 208 |
|
|
rst_out_S <= '0';
|
| 209 |
|
|
program_out_S <= '0';
|
| 210 |
|
|
rst_addr_gen_S <= '0';
|
| 211 |
|
|
when no_data =>
|
| 212 |
|
|
chain_enable_S <= '0';
|
| 213 |
|
|
running_S <= '1';
|
| 214 |
|
|
rst_out_S <= '0';
|
| 215 |
|
|
program_out_S <= '0';
|
| 216 |
|
|
rst_addr_gen_S <= '0';
|
| 217 |
|
|
when reset_state =>
|
| 218 |
|
|
chain_enable_S <= '0';
|
| 219 |
|
|
running_S <= '0';
|
| 220 |
|
|
rst_out_S <= '1';
|
| 221 |
|
|
program_out_S <= '0';
|
| 222 |
|
|
rst_addr_gen_S <= '0';
|
| 223 |
|
|
when program_state =>
|
| 224 |
|
|
chain_enable_S <= '0';
|
| 225 |
|
|
running_S <= '0';
|
| 226 |
|
|
rst_out_S <= '0';
|
| 227 |
|
|
program_out_S <= '1';
|
| 228 |
|
|
rst_addr_gen_S <= '0';
|
| 229 |
|
|
when start_state =>
|
| 230 |
|
|
chain_enable_S <= '0';
|
| 231 |
|
|
running_S <= '0';
|
| 232 |
|
|
rst_out_S <= '0';
|
| 233 |
|
|
program_out_S <= '0';
|
| 234 |
|
|
rst_addr_gen_S <= '1';
|
| 235 |
|
|
when word_a =>
|
| 236 |
|
|
chain_enable_S <= '1';
|
| 237 |
|
|
running_S <= '1';
|
| 238 |
|
|
rst_out_S <= '0';
|
| 239 |
|
|
program_out_S <= '0';
|
| 240 |
|
|
rst_addr_gen_S <= '0';
|
| 241 |
|
|
when word_b =>
|
| 242 |
|
|
chain_enable_S <= '1';
|
| 243 |
|
|
running_S <= '1';
|
| 244 |
|
|
rst_out_S <= '0';
|
| 245 |
|
|
program_out_S <= '0';
|
| 246 |
|
|
rst_addr_gen_S <= '0';
|
| 247 |
|
|
when word_c =>
|
| 248 |
|
|
chain_enable_S <= '1';
|
| 249 |
|
|
running_S <= '1';
|
| 250 |
|
|
rst_out_S <= '0';
|
| 251 |
|
|
program_out_S <= '0';
|
| 252 |
|
|
rst_addr_gen_S <= '0';
|
| 253 |
|
|
when word_d =>
|
| 254 |
|
|
chain_enable_S <= '1';
|
| 255 |
|
|
running_S <= '1';
|
| 256 |
|
|
rst_out_S <= '0';
|
| 257 |
|
|
program_out_S <= '0';
|
| 258 |
|
|
rst_addr_gen_S <= '0';
|
| 259 |
|
|
when others =>
|
| 260 |
|
|
chain_enable_S <= '0';
|
| 261 |
|
|
running_S <= '0';
|
| 262 |
|
|
rst_out_S <= '1';
|
| 263 |
|
|
program_out_S <= '0';
|
| 264 |
|
|
rst_addr_gen_S <= '0';
|
| 265 |
|
|
end case;
|
| 266 |
|
|
end process;
|
| 267 |
|
|
|
| 268 |
|
|
fsm_edge_detect : process(clk_S)
|
| 269 |
|
|
begin
|
| 270 |
|
|
if rising_edge(clk_S) then
|
| 271 |
|
|
|
| 272 |
|
|
old_rst_S <= rst_S;
|
| 273 |
|
|
old_program_in_S <= program_in_S;
|
| 274 |
|
|
old_start_adc_S <= start_adc_S;
|
| 275 |
|
|
old_ext_trigger_S <= ext_trigger_S;
|
| 276 |
|
|
old_soft_trigger_S <= soft_trigger_S;
|
| 277 |
|
|
|
| 278 |
|
|
if (old_rst_S = '0' and rst_S = '1') then
|
| 279 |
|
|
rst_pulse_S <= '1';
|
| 280 |
|
|
else
|
| 281 |
|
|
rst_pulse_S <= '0';
|
| 282 |
|
|
end if;
|
| 283 |
|
|
|
| 284 |
|
|
if (old_program_in_S = '0' and program_in_S = '1') then
|
| 285 |
|
|
program_pulse_S <= '1';
|
| 286 |
|
|
else
|
| 287 |
|
|
program_pulse_S <= '0';
|
| 288 |
|
|
end if;
|
| 289 |
|
|
|
| 290 |
|
|
if (old_start_adc_S = '0' and start_adc_S = '1') then
|
| 291 |
|
|
start_pulse_S <= '1';
|
| 292 |
|
|
else
|
| 293 |
|
|
start_pulse_S <= '0';
|
| 294 |
|
|
end if;
|
| 295 |
|
|
|
| 296 |
|
|
if ((old_ext_trigger_S = '0' and ext_trigger_S = '1') or (old_soft_trigger_S = '0' and soft_trigger_S = '1')) then
|
| 297 |
|
|
trigger_pulse_S <= '1';
|
| 298 |
|
|
else
|
| 299 |
|
|
trigger_pulse_S <= '0';
|
| 300 |
|
|
end if;
|
| 301 |
|
|
end if;
|
| 302 |
|
|
end process;
|
| 303 |
|
|
|
| 304 |
|
|
end Behavioral;
|