1 |
2 |
wzab |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : Example 1 - data processor
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : ex1_proc.vhd
|
6 |
|
|
-- Author : Wojciech M. Zabolotny <wzab01@gmail.com>
|
7 |
|
|
-- Company :
|
8 |
|
|
-- License : BSD
|
9 |
|
|
-- Created : 2015-09-07
|
10 |
|
|
-- Last update: 2015-09-24
|
11 |
|
|
-- Platform :
|
12 |
|
|
-- Standard : VHDL'93/02
|
13 |
|
|
-------------------------------------------------------------------------------
|
14 |
|
|
-- Description: This file implements the data processor which demonstrates
|
15 |
|
|
-- the methodology of automatic latency balancing in VHDL
|
16 |
|
|
-- implemented pipelined blocks
|
17 |
|
|
-------------------------------------------------------------------------------
|
18 |
|
|
-- Copyright (c) 2015
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
-- Revisions :
|
21 |
|
|
-- Date Version Author Description
|
22 |
|
|
-- 2015-09-07 1.0 wzab Created
|
23 |
|
|
-------------------------------------------------------------------------------
|
24 |
|
|
library IEEE;
|
25 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
26 |
|
|
use IEEE.NUMERIC_STD.all;
|
27 |
|
|
library work;
|
28 |
|
|
use work.lateq_pkg.all;
|
29 |
|
|
use work.ex1_pkg.all;
|
30 |
|
|
use work.ex1_trees_pkg.all;
|
31 |
|
|
|
32 |
|
|
entity ex1_proc is
|
33 |
|
|
|
34 |
|
|
port (
|
35 |
|
|
din : in T_INPUT_DATA; -- data from the detector
|
36 |
|
|
position : out T_POS_INT; -- integral part of the hit position
|
37 |
|
|
wgt_charge : out T_CALC_DATA; -- fractional part of the hit position
|
38 |
|
|
charge : out T_CALC_DATA; -- hit charge
|
39 |
|
|
clk : in std_logic; -- system clock
|
40 |
|
|
rst_p : in std_logic); -- reset
|
41 |
|
|
|
42 |
|
|
end entity ex1_proc;
|
43 |
|
|
|
44 |
|
|
architecture beh of ex1_proc is
|
45 |
|
|
|
46 |
|
|
-- Input signals in internal form (with time markers)
|
47 |
|
|
signal din_int, din_int_a : T_INPUT_DATA_MRK := C_INPUT_DATA_MRK_INIT;
|
48 |
|
|
-- pragma translate_off
|
49 |
|
|
-- Time marker
|
50 |
|
|
signal s_lateq_mrk : T_LATEQ_MRK := C_LATEQ_MRK_INIT;
|
51 |
|
|
-- pragma translate_on
|
52 |
|
|
-- Output signal from the max_finder
|
53 |
|
|
signal dout_max : T_SINGLE_DATA_WITH_POS := C_SINGLE_DATA_WITH_POS_INIT;
|
54 |
|
|
-- Selected data surrounding the maximum of the signal
|
55 |
|
|
signal sel_data : T_SEL_DATA := C_SEL_DATA_INIT;
|
56 |
|
|
-- Selected data with longer data word
|
57 |
|
|
signal s_sel_data, wgt_sel_data : T_CALC_SEL_DATA := C_CALC_SEL_DATA_INIT;
|
58 |
|
|
-- Sum of charge and weighted sum of charge
|
59 |
|
|
signal chrg_sum, wgt_chrg_sum : T_CALC_DATA_MRK := C_CALC_DATA_MRK_INIT;
|
60 |
|
|
-- Sum of charge and weighted sum of charge after synchronizer
|
61 |
|
|
signal chrg_sum_b, wgt_chrg_sum_b : T_CALC_DATA_MRK := C_CALC_DATA_MRK_INIT;
|
62 |
|
|
-- Position of maximum - delayed signals after other blocks or sycnhronizers
|
63 |
|
|
signal s_position_a, s_position_b, s_position_c : T_POS_INT_MRK := C_POS_INT_MRK_INIT;
|
64 |
|
|
|
65 |
|
|
begin -- architecture beh
|
66 |
|
|
|
67 |
|
|
-- Process which generates the time markers for the input data
|
68 |
|
|
-- It is unclear. Should it be here, or in the testbench?
|
69 |
|
|
|
70 |
|
|
pgm1: process (clk) is
|
71 |
|
|
begin -- process pgm1
|
72 |
|
|
if clk'event and clk = '1' then -- rising clock edge
|
73 |
|
|
if rst_p = '1' then -- synchronous reset (active low)
|
74 |
|
|
-- pragma translate_off
|
75 |
|
|
s_lateq_mrk <= C_LATEQ_MRK_INIT;
|
76 |
|
|
-- pragma translate_on
|
77 |
|
|
din_int <= C_INPUT_DATA_MRK_INIT;
|
78 |
|
|
else
|
79 |
|
|
din_int.data_vec <= din;
|
80 |
|
|
-- pragma translate_off
|
81 |
|
|
din_int.lateq_mrk <= s_lateq_mrk;
|
82 |
|
|
s_lateq_mrk <= lateq_mrk_incr(s_lateq_mrk);
|
83 |
|
|
-- pragma translate_on
|
84 |
|
|
end if;
|
85 |
|
|
end if;
|
86 |
|
|
end process pgm1;
|
87 |
|
|
|
88 |
|
|
-- The first block is the maximum finder.
|
89 |
|
|
max_finder_1: entity work.max_finder
|
90 |
|
|
generic map (
|
91 |
|
|
N_OF_ALL_INS => C_N_CHANNELS
|
92 |
|
|
)
|
93 |
|
|
port map (
|
94 |
|
|
dins => din_int,
|
95 |
|
|
dout => dout_max,
|
96 |
|
|
clk => clk,
|
97 |
|
|
rst_p => rst_p);
|
98 |
|
|
-- Now we should correct delays between the input data
|
99 |
|
|
-- and output of the maximum finder
|
100 |
|
|
-- So we have our delay adjustment block with two channels
|
101 |
|
|
--
|
102 |
|
|
s_position_a.position <= dout_max.position;
|
103 |
|
|
-- pragma translate_off
|
104 |
|
|
s_position_a.lateq_mrk <= dout_max.lateq_mrk;
|
105 |
|
|
-- pragma translate_on
|
106 |
|
|
|
107 |
|
|
ex1_eq_mf_1: entity work.ex1_eq_mf
|
108 |
|
|
generic map (
|
109 |
4 |
wzab |
LEQ_ID => "LCEQ1")
|
110 |
2 |
wzab |
port map (
|
111 |
|
|
in0 => din_int,
|
112 |
|
|
out0 => din_int_a,
|
113 |
|
|
in1 => s_position_a,
|
114 |
|
|
out1 => s_position_b,
|
115 |
|
|
clk => clk,
|
116 |
|
|
rst_p => rst_p);
|
117 |
|
|
|
118 |
|
|
-- Now we can select channels surrounding the maximum
|
119 |
|
|
data_sel_1: entity work.data_sel
|
120 |
|
|
generic map (
|
121 |
|
|
N_SIDE_CHANS => C_N_SIDE_CHANS)
|
122 |
|
|
port map (
|
123 |
|
|
dins => din_int_a,
|
124 |
|
|
dout => sel_data,
|
125 |
|
|
sel => s_position_b.position,
|
126 |
|
|
clk => clk,
|
127 |
|
|
rst_p => rst_p);
|
128 |
|
|
|
129 |
|
|
-- Now for the selected channels we should calculate the charge and the
|
130 |
|
|
-- weighted charge
|
131 |
|
|
|
132 |
|
|
-- Generate the data multiplied by weigth (single clock delay)
|
133 |
|
|
pws1: process (clk) is
|
134 |
|
|
begin -- process pws1
|
135 |
|
|
if clk'event and clk = '1' then -- rising clock edge
|
136 |
|
|
if rst_p = '1' then -- synchronous reset (active high)
|
137 |
|
|
wgt_sel_data <= C_CALC_SEL_DATA_INIT;
|
138 |
|
|
else
|
139 |
|
|
for i in 0 to 2*C_N_SIDE_CHANS loop
|
140 |
|
|
wgt_sel_data.data_vec(i) <= resize((i-C_N_SIDE_CHANS) * signed(sel_data.data_vec(i)),C_CALC_SUM_WIDTH);
|
141 |
|
|
end loop; -- i
|
142 |
|
|
-- pragma translate_off
|
143 |
|
|
wgt_sel_data.lateq_mrk <= sel_data.lateq_mrk;
|
144 |
|
|
-- pragma translate_on
|
145 |
|
|
end if;
|
146 |
|
|
end if;
|
147 |
|
|
end process pws1;
|
148 |
|
|
|
149 |
|
|
-- Map the selected data to the calc type (no delay)
|
150 |
|
|
pws2: process(sel_data) is
|
151 |
|
|
begin -- process pws2
|
152 |
|
|
for i in 0 to 2*C_N_SIDE_CHANS loop
|
153 |
|
|
s_sel_data.data_vec(i) <= resize(signed(sel_data.data_vec(i)), C_CALC_SUM_WIDTH);
|
154 |
|
|
end loop; -- i
|
155 |
|
|
-- pragma translate_off
|
156 |
|
|
s_sel_data.lateq_mrk <= sel_data.lateq_mrk;
|
157 |
|
|
-- pragma translate_on
|
158 |
|
|
end process pws2;
|
159 |
|
|
|
160 |
|
|
-- Here we calculate the sum of charge
|
161 |
|
|
tree_adder_1: entity work.tree_adder
|
162 |
|
|
generic map (
|
163 |
|
|
N_OF_ALL_INS => 2*C_N_SIDE_CHANS+1
|
164 |
|
|
)
|
165 |
|
|
port map (
|
166 |
|
|
dins => s_sel_data,
|
167 |
|
|
dout => chrg_sum,
|
168 |
|
|
clk => clk,
|
169 |
|
|
rst_p => rst_p);
|
170 |
|
|
-- Here we calculate weighted sum of charge
|
171 |
|
|
tree_adder_2: entity work.tree_adder
|
172 |
|
|
generic map (
|
173 |
|
|
N_OF_ALL_INS => 2*C_N_SIDE_CHANS+1
|
174 |
|
|
)
|
175 |
|
|
port map (
|
176 |
|
|
dins => wgt_sel_data,
|
177 |
|
|
dout => wgt_chrg_sum,
|
178 |
|
|
clk => clk,
|
179 |
|
|
rst_p => rst_p);
|
180 |
|
|
-- Now we have to equalize delays between the position, the sum
|
181 |
|
|
-- of charge, and the weighted sum of charge
|
182 |
|
|
ex1_eq_calc_1: entity work.ex1_eq_calc
|
183 |
|
|
generic map (
|
184 |
4 |
wzab |
LEQ_ID => "LCEQ2")
|
185 |
2 |
wzab |
port map (
|
186 |
|
|
in0 => s_position_b,
|
187 |
|
|
out0 => s_position_c,
|
188 |
|
|
in1 => chrg_sum,
|
189 |
|
|
out1 => chrg_sum_b,
|
190 |
|
|
in2 => wgt_chrg_sum,
|
191 |
|
|
out2 => wgt_chrg_sum_b,
|
192 |
|
|
clk => clk,
|
193 |
|
|
rst_p => rst_p);
|
194 |
|
|
|
195 |
|
|
-- Now connect the output signals
|
196 |
|
|
charge <= chrg_sum_b.sum;
|
197 |
|
|
wgt_charge <= wgt_chrg_sum_b.sum;
|
198 |
|
|
position <= s_position_c.position;
|
199 |
|
|
end architecture beh;
|