1 ----------------------------------------------------------------------------------
5 -- Create Date: 15:
54:
09 02/16/2016
7 -- Module Name: TTC_cntr - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
19 ----------------------------------------------------------------------------------
21 use IEEE.STD_LOGIC_1164.
ALL;
22 use IEEE.STD_LOGIC_ARITH.
ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
24 use IEEE.std_logic_misc.
all;
27 -- Uncomment the following library declaration if using
28 -- arithmetic functions with or values
29 --use IEEE.NUMERIC_STD.ALL;
31 -- Uncomment the following library declaration if instantiating
32 -- any Xilinx primitives in this code.
34 use UNISIM.VComponents.
all;
36 use UNIMACRO.vcomponents.
all;
45 AMC_if_data : in (15 downto 0);
46 Cntr_DATA : in array12x16;
47 Cntr_ADDR : out (11 downto 0);
48 ipb_addr : in (15 downto 0);
49 ipb_rdata : out (31 downto 0));
52 signal div : (11 downto 0) := (others =>'0');
53 signal div_l : (10 downto 0) := (others =>'0');
54 signal div_l2 : (10 downto 0) := (others =>'0');
55 signal CntrRstCycle : := '0';
56 signal counter_wa : (10 downto 0) := (others => '0');
57 signal counter_ra : (10 downto 0) := (others => '0');
58 signal counter_DIA : (31 downto 0) := (others => '0');
59 signal counter_DOA : (31 downto 0) := (others => '0');
60 signal counter_DOB : (31 downto 0) := (others => '0');
61 signal we_counter : (1 downto 0) := (others => '0');
62 signal buffer_DOB : (31 downto 0) := (others => '0');
63 signal buffer_RSTB : := '0';
64 signal we_buffer : (1 downto 0) := (others => '0');
65 signal startSyncRegs : (3 downto 0) := (others =>'0');
66 signal DataType : (1 downto 0) := (others => '0');
67 signal DataType_l : (1 downto 0) := (others => '0');
68 signal DataType_l2 : (1 downto 0) := (others => '0');
69 signal DataType_q : (1 downto 0) := (others => '0');
70 signal tmp : (31 downto 0) := (others => '0');
71 signal ec_div : (1 downto 0) := (others => '0');
72 signal start : := '0';
73 signal data : (31 downto 0) := (others => '0');
74 signal DB_cmd_l : := '0';
75 signal carry_m : := '0';
76 signal DB_en : := '0';
77 signal carry_h : := '0';
78 signal sr : (4 downto 0) := (others => '0');
79 signal toggle : := '0';
80 signal toggle_q : := '0';
81 signal ec_rdata : := '0';
82 signal ec_wdata : := '0';
86 process(UsrClk, Cntr_Data, CntrRstCycle)
87 variable CntrDataOR : (15 downto 0);
89 CntrDataOR := AMC_if_data;
91 CntrDataOR := CntrDataOR or Cntr_Data(i);
93 if(CntrRstCycle = '1')then
94 data <= (others => '0');
95 tmp <= (others => '0');
96 elsif(UsrClk'event and UsrClk = '1')then
97 if(ec_div(0) = '1')then
99 tmp(15 downto 0) <= CntrDataOR;
101 if(ec_div(1) = '1')then
102 if(DataType = "11")then
103 tmp(31 downto 16) <= (others => '0');
105 tmp(31 downto 16) <= CntrDataOR;
110 --i_sample_data : SRL16E
112 -- Q => sample_data, -- SRL data output
113 -- A0 => '1', -- Select[0] input
114 -- A1 => '0', -- Select[1] input
115 -- A2 => '0', -- Select[2] input
116 -- A3 => '0', -- Select[3] input
117 -- CE => '1', -- Clock enable input
118 -- CLK => UsrClk, -- Clock input
119 -- D => ec_div -- SRL data input
123 Q => ec_div
(1),
-- SRL data output
124 A0 => '0',
-- Select[0] input
125 A1 => '0',
-- Select[1] input
126 A2 => '1',
-- Select[2] input
127 A3 => '0',
-- Select[3] input
128 CE => '1',
-- Clock enable input
129 CLK => UsrClk,
-- Clock input
130 D => ec_div
(0) -- SRL data input
133 process(UsrClk, CntrRstCycle)
135 if(CntrRstCycle = '1')then
136 startSyncRegs <= (others => '0');
138 div <= (others => '0');
139 div_l <= (others => '0');
140 div_l2 <= (others => '0');
142 elsif(UsrClk'event and UsrClk = '1')then
143 startSyncRegs <= startSyncRegs(2 downto 0) & start;
144 -- if(startSyncRegs(3 downto 2) = "
01")
then
145 -- start_edge <= '1';
147 -- start_edge <= '0';
149 -- rst_ec_div <= start_edge;
150 if(startSyncRegs(3 downto 2) = "01")then
155 if(ec_div /= "00")then
156 div <= div + 1 + DataType(1);
158 if(div(11 downto 3) = "110000101" or div(11 downto 5) = "1100010")then
159 DataType <= "00";
-- 32 counter
160 elsif(div(11 downto 6) = "111000" or div(11 downto 9) = "110")then
161 DataType <= "01";
-- register
162 elsif(div(11 downto 10) /= "11" and div(7 downto 5) = "010")then
163 DataType <= "11";
-- register of daq_link
165 DataType <= "10";
-- 48 counter
167 if(ec_div(0) = '1')then
168 div_l <= div(11 downto 1);
170 DataType_l <= DataType;
171 DataType_l2 <= DataType_l;
175 g_counter: for i in 0 to 1 generate
176 i_counter : BRAM_TDP_MACRO
178 BRAM_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
179 DEVICE =>
"7SERIES",
-- Target Device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
180 WRITE_MODE_A =>
"READ_FIRST",
-- "WRITE_FIRST",
"READ_FIRST" or "NO_CHANGE"
181 READ_WIDTH_A =>
16,
-- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
182 READ_WIDTH_B =>
16,
-- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
183 WRITE_WIDTH_A =>
16,
-- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
184 WRITE_WIDTH_B =>
16) -- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
186 DOA => counter_DOA
(i*16+15
downto i*16
),
-- Output port-A data, width defined by READ_WIDTH_A parameter
187 DOB => counter_DOB
(i*16+15
downto i*16
),
-- Output port-B data, width defined by READ_WIDTH_B parameter
188 ADDRA => counter_wa,
-- Input port-A address, width defined by Port A depth
189 ADDRB => ipb_addr
(10 downto 0),
-- Input port-B address, width defined by Port B depth
190 CLKA => clk125,
-- 1-bit input port-A clock
191 CLKB => clk125,
-- 1-bit input port-B clock
192 DIA => counter_DIA
(i*16+15
downto i*16
),
-- Input port-A data, width defined by WRITE_WIDTH_A parameter
193 DIB => x"0000",
-- Input port-B data, width defined by WRITE_WIDTH_B parameter
194 ENA => '1',
-- 1-bit input port-A enable
195 ENB => ec_rdata,
-- 1-bit input port-B enable
196 REGCEA => '0',
-- 1-bit input port-A output register enable
197 REGCEB => '0',
-- 1-bit input port-B output register enable
198 RSTA => '0',
-- 1-bit input port-A reset
199 RSTB => ipb_addr
(15),
-- 1-bit input port-B reset
200 WEA => we_counter,
-- Input port-A write enable, width defined by Port A depth
201 WEB => "
00"
-- Input port-B write enable, width defined by Port B depth
203 i_buffer : BRAM_TDP_MACRO
205 BRAM_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
206 DEVICE =>
"7SERIES",
-- Target Device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
207 WRITE_MODE_A =>
"READ_FIRST",
-- "WRITE_FIRST",
"READ_FIRST" or "NO_CHANGE"
208 READ_WIDTH_A =>
16,
-- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
209 READ_WIDTH_B =>
16,
-- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
210 WRITE_WIDTH_A =>
16,
-- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
211 WRITE_WIDTH_B =>
16) -- Valid values are 1-36 (19-36 only valid when BRAM_SIZE="36Kb")
213 DOA =>
open,
-- Output port-A data, width defined by READ_WIDTH_A parameter
214 DOB => buffer_DOB
(i*16+15
downto i*16
),
-- Output port-B data, width defined by READ_WIDTH_B parameter
215 ADDRA => counter_wa,
-- Input port-A address, width defined by Port A depth
216 ADDRB => ipb_addr
(10 downto 0),
-- Input port-B address, width defined by Port B depth
217 CLKA => clk125,
-- 1-bit input port-A clock
218 CLKB => clk125,
-- 1-bit input port-B clock
219 DIA => counter_DIA
(i*16+15
downto i*16
),
-- Input port-A data, width defined by WRITE_WIDTH_A parameter
220 DIB => x"0000",
-- Input port-B data, width defined by WRITE_WIDTH_B parameter
221 ENA => '1',
-- 1-bit input port-A enable
222 ENB => ec_rdata,
-- 1-bit input port-B enable
223 REGCEA => '0',
-- 1-bit input port-A output register enable
224 REGCEB => '0',
-- 1-bit input port-B output register enable
225 RSTA => '0',
-- 1-bit input port-A reset
226 RSTB => buffer_RSTB,
-- 1-bit input port-B reset
227 WEA => we_buffer,
-- Input port-A write enable, width defined by Port A depth
228 WEB => "
00"
-- Input port-B write enable, width defined by Port B depth
231 buffer_RSTB <= not ipb_addr(15);
232 we_counter(1) <= we_counter(0);
233 we_buffer(1) <= we_buffer(0);
234 ipb_rdata <= counter_DOB or buffer_DOB;
237 if(ipb_clk'event and ipb_clk = '1')then
238 toggle <= not toggle;
243 if(clk125'event and clk125 = '1')then
245 ec_rdata <= toggle xor toggle_q;
246 if(DB_cmd = '1' and ec_wdata = '1')then
248 elsif(sr(0) = '1' and and_reduce(counter_wa) = '1')then
251 if(sr(0) = '1' and and_reduce(counter_wa) = '1')then
255 DataType_q <= DataType_l2;
257 if(resetCntr = '1')then
258 counter_wa <= (others => '0');
259 elsif(CntrRstCycle = '1')then
260 counter_wa <= counter_wa + 1;
261 elsif(sr(0) = '1')then
262 counter_wa <= div_l2;
263 elsif(DataType_q(1) = '1')then
264 counter_wa(0) <= (sr(2) or sr(4)) and not sr(3);
266 if(resetCntr = '1')then
268 elsif(and_reduce(counter_wa) = '1')then
271 if(CntrRstCycle = '1')then
273 elsif(sr(3 downto 0) = x"0")then
276 sr <= sr(3 downto 0) & '0';
279 if(DataType_q(0) = '0' and counter_DOA(15 downto 0) > counter_DIA(15 downto 0))then
286 if(carry_m = '1' and counter_DOA(31 downto 16) = x"ffff")then
292 if(CntrRstCycle = '1')then
293 counter_DIA <= (others => '0');
294 elsif(sr(0) = '1')then
296 elsif(sr(3) = '1' and DataType_q(0) = '0')then
297 counter_DIA(31 downto 16) <= counter_DOA(31 downto 16) + carry_m;
298 elsif(sr(4) = '1')then
299 counter_DIA <= x"0000" & (counter_DOA(15 downto 0) + carry_h);
301 we_counter(0) <= sr(3) or (sr(4) and DataType_q(1) and not DataType_q(0)) or CntrRstCycle;
302 we_buffer(0) <= (DB_en and(sr(3) or (sr(4) and DataType_q(1) and not DataType_q(0)))) or CntrRstCycle;
309 Q => ec_wdata,
-- SRL data output
310 A0 => '1',
-- Select[0] input
311 A1 => '0',
-- Select[1] input
312 A2 => '0',
-- Select[2] input
313 A3 => '0',
-- Select[3] input
314 CE => '1',
-- Clock enable input
315 CLK => clk125,
-- Clock input
316 D => ec_rdata
-- SRL data input