1 ------------------------------------------------------------------------------- 2 -- File : SyncTrigRate.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2014-04-16 5 -- Last update: 2017-01-26 6 ------------------------------------------------------------------------------- 7 -- Description: This module measures the trigger rate of a trigger 8 ------------------------------------------------------------------------------- 9 -- This file is part of 'SLAC Firmware Standard Library'. 10 -- It is subject to the license terms in the LICENSE.txt file found in the 11 -- top-level directory of this distribution and at: 12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 13 -- No part of 'SLAC Firmware Standard Library', including this file, 14 -- may be copied, modified, propagated, or distributed except according to 15 -- the terms contained in the LICENSE.txt file. 16 ------------------------------------------------------------------------------- 19 use ieee.std_logic_1164.
all;
20 use ieee.std_logic_unsigned.
all;
21 use ieee.std_logic_arith.
all;
26 --! @ingroup base_sync 29 TPD_G : := 1 ns;
-- Simulation FF output delay 30 COMMON_CLK_G : := false;
-- true if locClk & refClk are the same clock 35 USE_DSP48_G : := "no";
-- "no" for no DSP48 implementation, "yes" to use DSP48 slices 38 -- Trigger Input (locClk domain) 40 -- Trigger Rate Output (locClk domain) 46 locClkEn :
in sl := '1';
48 locRst :
in sl := '1';
57 type RegType is record 61 timer : range 0 to TIMEOUT_C;
68 constant REG_INIT_C : RegType := ( 73 trigCntDly => (others => '0'), 74 rate => (others => '0'), 75 rateMax => (others => '0'), 76 rateMin => (others => '0'));
78 signal r : RegType := REG_INIT_C;
82 signal updated : sl := '0';
84 signal trigCntSync : slv(CNT_WIDTH_G-1 downto 0) := (others => '0');
88 BYPASS_ONE_SHOT : if (ONE_SHOT_G = false) generate 110 if rising_edge(locClk) then 111 -- Check the clock enable 113 -- Check for a trigger 115 -- Increment the counter 116 trigCnt <= trigCnt + 1 after TPD_G;
131 dout => trigCntSync
);
133 comb :
process (r,
refRst, trigCntSync)
is 134 variable v : RegType;
136 -- Latch the current value 139 -- Reset strobing signals 144 if r.timer = TIMEOUT_C then 147 -- Update the rate measurement 149 v.rate := trigCntSync - r.trigCntDly;
150 -- Keep a delayed copy of trigCntSync 151 v.trigCntDly := trigCntSync;
153 -- Increment the timer 154 v.timer := r.timer + 1;
157 -- Check for update previous clock cycle 158 if (r.updated = '1') then 161 -- Check if first time after reset 162 if (r.armed = '0') then 165 -- Pass the current values to the statistics measurements 169 -- Compare for max. value 170 if (r.rate > r.rateMax) then 171 -- Update the statistics measurement 174 -- Compare for min. value 175 if (r.rate < r.rateMin) then 176 -- Update the statistics measurement 184 -- Re-arm and reset statistics measurements only 190 -- Register the variable for next clock cycle 197 if rising_edge(refClk) then 198 r <= rin after TPD_G;
222 wr_en => r.updateStat,
234 wr_en => r.updateStat,
in dinslv( DATA_WIDTH_G- 1 downto 0)
out doutslv( DATA_WIDTH_G- 1 downto 0)
REFRESH_RATE_Greal := 1.0E+0
COMMON_CLK_Gboolean := false
COMMON_CLK_Gboolean := false
out trigRateOutMinslv( CNT_WIDTH_G- 1 downto 0)
CNT_WIDTH_Gpositive := 32
ONE_SHOT_Gboolean := false
out trigRateOutMaxslv( CNT_WIDTH_G- 1 downto 0)
USE_DSP48_Gstring := "no"
REF_CLK_FREQ_Greal := 200.0E+6
out trigRateOutslv( CNT_WIDTH_G- 1 downto 0)
DATA_WIDTH_Ginteger range 1 to ( 2** 24):= 16