otsdaq_prepmodernization  v2_05_02_indev
ClockLatchSignals.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 11:13:58 09/23/2016
6 -- Design Name:
7 -- Module Name: ClockLatchSignals - Behavioral
8 -- Project Name:
9 -- Target Devices:
10 -- Tool versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 library IEEE;
21 use IEEE.NUMERIC_STD.ALL;
22 use IEEE.STD_LOGIC_1164.ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.ALL;
24 
25 -- Uncomment the following library declaration if using
26 -- arithmetic functions with Signed or Unsigned values
27 --use IEEE.NUMERIC_STD.ALL;
28 
29 -- Uncomment the following library declaration if instantiating
30 -- any Xilinx primitives in this code.
31 --library UNISIM
32 --use UNISIM.VComponents.all;
33 
35  Port ( clk : in STD_LOGIC;
36  rst : in STD_LOGIC;
37  signals : out STD_LOGIC_VECTOR (7 downto 0));
38 end ClockLatchSignals;
39 
40 --So, this is a module that creates signals to latch the DCMs. Upon reset, this module will loop through the signals one at
41 --a time starting with 0 and going to 7. To latch your clocks, simply attach a signal from this module to the dcm. If there are
42 --multiple DCMs, attach signal 0 to the first, signal 1 to the second, and so on. Each DCM is given about 16 clocks to latch.
43 
44 --ERROR: The last latch signal does not stay high for more than a clock or two. Since I don't need so many signals, I am just giong
45 --use the module, but it should be fixed for anyone who wants to use this signal.
46 
47 --ERROR: For the first few clock cycles, the latch signals read U.
48 
49 architecture Behavioral of ClockLatchSignals is
50 signal delay : unsigned(3 downto 0) := (others => '0'); --creates the delay for each latch.
51 signal clock_place : unsigned(2 downto 0) := (others => '0'); --Holds our place so we can tell which clock we need to latch next
52 signal triggered : std_logic; --Set true after start of rst.
53 signal done : std_logic; --Sets when the trigger is finished. Triggered is not reset until rst is low.
54 --triggered and done are both reset when trigger is high, done is high, and rst is low.
55 begin
56 
57 
58 
59  process(clk) begin
60 
61  if(rst = '1' and triggered = '0') then -- new trigger
62  triggered <= '1';
63  done <= '0';
64  end if;
65 
66  if(triggered = 'U') then
67  triggered <= '0';
68  end if;
69 
70  if(done = 'U') then
71  done <= '0';
72  end if;
73 
74  if(triggered = '1' and done = '0') then --In the middle of a trigger. This is going to be the most complicated part here.
75 
76  if(delay = "1111") then --If the latch time has past
77  delay <= "0000";--Reset the delay.
78  if(clock_place = "111") then --If the end of the trigger has been reached,
79  clock_place <= "000";
80  done <= '1';
81  else --As long as the end of the trigger has not been reached.
82  clock_place <= clock_place + 1; --Change the clock place to latch the next clock.
83  end if;
84 
85  --This is where I have the code that simply checks the current latch clock and turns on that latch signal.
86 
87  if(clock_place = "000") then
88  signals<= "00000001";
89  end if;
90 
91  if(clock_place = "001") then
92  signals<= "00000010";
93  end if;
94 
95  if(clock_place = "010") then
96  signals<= "00000100";
97  end if;
98 
99  if(clock_place = "011") then
100  signals<= "00001000";
101  end if;
102 
103  if(clock_place = "100") then
104  signals<= "00010000";
105  end if;
106 
107  if(clock_place = "101") then
108  signals<= "00100000";
109  end if;
110 
111  if(clock_place = "110") then
112  signals<= "01000000";
113  end if;
114 
115  if(clock_place = "111") then
116  signals<= "10000000";
117  end if;
118 
119  else --We are in the middle of a trigger delaying until the current clock latches.
120  delay <= delay + 1;
121  end if;
122 
123  end if;
124 
125  if(triggered = '1' and done = '1') then --When the reset signal turns off, reset everything when we are done latching.
126  triggered <= '0';
127  done <= '0';
128  signals<= "00000000";
129  end if;
130 
131  end process;
132 
133 end Behavioral;
134