CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
time_multiplex_8to1.vhd
Go to the documentation of this file.
1 ----------------------------------------------------------------------------------
12 
13 ----------------------------------------------------------------------------------
14 library IEEE;
15 use IEEE.STD_LOGIC_1164.ALL;
16 
17 library work;
18 use work.CMXpackage.all;
19 
20 
21 -- Uncomment the following library declaration if using
22 -- arithmetic functions with Signed or Unsigned values
23 use IEEE.NUMERIC_STD.ALL;
24 
25 -- Uncomment the following library declaration if instantiating
26 -- any Xilinx primitives in this code.
27 --library UNISIM;
28 --use UNISIM.VComponents.all;
29 
31  ---generic
32  --- (
33  --- ratio : integer := 8 -- input length : output length ratio
34  --- );
35  port (
36  DATA_in : in std_logic_vector(16*8-1 downto 0);
37  send_align : in std_logic;
38  BCID : in std_logic_vector(11 downto 0);
39  DATA_out : out std_logic_vector(17 downto 0);
40  subtick_counter_out : out unsigned(2 downto 0);
41  clk_slow : in std_logic; -- DATA_in is synced to this clock
42  clk_fast : in std_logic; -- DATA_out is synced to this clock
43  pll_locked : in std_logic); -- from the MMCM; used to define when
44  -- to start
45 end time_multiplex_8to1;
46 
47 architecture Behavioral of time_multiplex_8to1 is
48 
49  signal subtick_counter : unsigned(2 downto 0);
50  signal subtick_counter_next : unsigned(2 downto 0);
51 
52 
53  signal pll_locked_s1, pll_locked_synced : std_logic;
54 
55  signal DATA_out_next : std_logic_vector(16 downto 0);
56 
57  signal send_align_reg : std_logic;
58 
59  --the select signal that combines the send_align bit and the subtick counter
60  signal sel: std_logic_vector(3 downto 0);
61 
62 begin
63 
64  DATA_out(17)<='0'; --the K character only possibly appears on the LS byte.
65  --never on the higher byte so the flag for the
66 
68 
69 
70  --combine the two signals into one as the input to the multiplexer
71  sel<=send_align_reg& std_logic_vector(subtick_counter);
72 
73 
74  --normally when no align data is to be sent the multiplexer picks off the
75  --successive chunks of the input data starting with the MS word '0' is added
76  --in the front to signify that the data (lower byte) is not a K character
77  --however when the align bit is set first 3 words are the same but then
78  --a K character is spliced in in st 3 and BCID on st 4, the rest of the data
79  --is zeroed
80  with sel select
81  DATA_out_next <=
82  ('0' & DATA_in( 8*16 - 1 downto 7*16)) when "0000", --subtick: 0 --send_align from previous event
83  ('0' & DATA_in( 8*16 - 1 downto 7*16)) when "1000", --but thats ok sice
84  ('0' & DATA_in( 7*16 - 1 downto 6*16)) when "0001", --subtick: 1 --till subtick 3 no difference
85  ('0' & DATA_in( 7*16 - 1 downto 6*16)) when "1001", --still old send_align_reg
86  ('0' & DATA_in( 6*16 - 1 downto 5*16)) when "0010", --subtick: 2
87  ('0' & DATA_in( 6*16 - 1 downto 5*16)) when "1010", --still old send_align_reg
88  ('0' & DATA_in( 5*16 - 1 downto 4*16)) when "0011", --subtick: 3
89  ('1' & DATA_in( 5*16 - 1 downto 4*16+8) & "10111100") when "1011", --add K
90  ('0' & DATA_in( 4*16 - 1 downto 3*16)) when "0100", --subtick: 4
91  ('0' & BCID & DATA_in( 3*16 + 3 downto 3*16)) when "1100", --add BCID
92  ('0' & DATA_in( 3*16 - 1 downto 2*16)) when "0101", --subtick: 5
93  ('0' & DATA_in( 3*16 - 1 downto 2*16)) when "1101", --continue sending
94  ('0' & DATA_in( 2*16 - 1 downto 1*16)) when "0110", --subtick: 6
95  ('0' & DATA_in( 2*16 - 1 downto 1*16)) when "1110",
96  ('0' & DATA_in( 1*16 - 1 downto 0*16)) when "0111", --subtick: 7
97  ('0' & DATA_in( 1*16 - 1 downto 0*16)) when "1111";
98 
99  --process to sync the pll locked signal to the clk_slow
100  process (clk_slow, pll_locked)
101  begin -- process
102  if pll_locked = '0' then
103  pll_locked_s1<='0';
104  pll_locked_synced<='0';
105  elsif rising_edge(clk_slow) then
107  pll_locked_s1<='1';
108  end if;
109  end process;
110 
111 
112 
113 
114  --process to select a range of the input data and register it into the output
115  --data
117  begin
118  if rising_edge(clk_fast) then
119  if pll_locked_synced /= '1' then
120  subtick_counter<=to_unsigned(0,3);
121  DATA_out(16 downto 0)<=(others => '0');
122  send_align_reg<='0';
123  else
124  DATA_out(16 downto 0) <= DATA_out_next;
126  if subtick_counter=to_unsigned(2,3) then --note the 2; alignment word is not used till second half of the serialisation
128  end if;
129  end if;
130  end if;
131  end process;
132 
134 
135 end Behavioral;
136 
_library_ workwork
Definition: sys_monitor.vhd:15
in BCIDstd_logic_vector (11 downto 0)
unsigned (2 downto 0) subtick_counter
_library_ IEEEIEEE
Definition: sys_monitor.vhd:8
out subtick_counter_outunsigned (2 downto 0)
unsigned (2 downto 0) subtick_counter_next
in DATA_instd_logic_vector (16 * 8 - 1 downto 0)
std_logic_vector (16 downto 0) DATA_out_next
out DATA_outstd_logic_vector (17 downto 0)
std_logic_vector (3 downto 0) sel