1 |
2 |
jclaytons |
--------------------------------------
|
2 |
|
|
-- Test FPGA
|
3 |
|
|
--------------------------------------
|
4 |
|
|
--
|
5 |
|
|
--------------------------------------
|
6 |
|
|
|
7 |
|
|
library ieee;
|
8 |
|
|
use ieee.std_logic_1164.all;
|
9 |
|
|
use ieee.numeric_std.all;
|
10 |
|
|
use ieee.math_real.all;
|
11 |
|
|
|
12 |
|
|
-- synopsys translate_off
|
13 |
|
|
library xp2;
|
14 |
|
|
use xp2.components.all;
|
15 |
|
|
-- synopsys translate_on
|
16 |
|
|
|
17 |
|
|
library work;
|
18 |
|
|
use work.function_pack.all;
|
19 |
|
|
|
20 |
|
|
entity fpga is
|
21 |
|
|
port (
|
22 |
|
|
-- System Clock & Reset_n
|
23 |
|
|
sys_clk_ref : in std_logic;
|
24 |
|
|
sys_rst_n_i : in std_logic;
|
25 |
|
|
|
26 |
|
|
-- Standardized Board Inputs / Outputs
|
27 |
|
|
switch : in unsigned(7 downto 0);
|
28 |
|
|
led : out unsigned(7 downto 0);
|
29 |
|
|
exp_io : inout unsigned(39 downto 1);
|
30 |
|
|
|
31 |
|
|
-- TTL serial interface
|
32 |
|
|
uart_0_tx_o : out std_logic;
|
33 |
|
|
uart_0_rx_i : in std_logic
|
34 |
|
|
|
35 |
|
|
);
|
36 |
|
|
end fpga;
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
architecture beh of fpga is
|
40 |
|
|
|
41 |
|
|
-- Constants
|
42 |
|
|
constant SYS_CLK_RATE : real := 50000000.0; -- The clock rate at which the FPGA runs
|
43 |
|
|
constant FPGA_VERSION : unsigned(31 downto 0) := "11110000111100001111111111110001";
|
44 |
|
|
|
45 |
|
|
constant ALEX_K_BITS : natural := 32;
|
46 |
|
|
constant ALEX_K_FRAC : natural := 8;
|
47 |
|
|
constant ALEX_GAIN_ADJ : natural := 2;
|
48 |
|
|
constant DERAND_BITS : natural := 16;
|
49 |
|
|
|
50 |
|
|
----------------------------------------------------------------------------
|
51 |
|
|
--Internal signal declarations
|
52 |
|
|
----------------------------------------------------------------------------
|
53 |
|
|
|
54 |
|
|
signal sys_rst_l : std_logic;
|
55 |
|
|
|
56 |
|
|
-- Board Input & Output related
|
57 |
|
|
signal led_reg : unsigned(7 downto 0);
|
58 |
|
|
signal led_disp : unsigned(7 downto 0);
|
59 |
|
|
signal switch_l : unsigned(7 downto 0);
|
60 |
|
|
signal sys_rst : std_logic;
|
61 |
|
|
signal sys_rst_n : std_logic;
|
62 |
|
|
|
63 |
|
|
-- Clock and oscillator related
|
64 |
|
|
signal sys_clk : std_logic;
|
65 |
|
|
signal sys_clk_en : std_logic;
|
66 |
|
|
|
67 |
|
|
-- Signals for system controller
|
68 |
|
|
signal syscon_baud_clk : std_logic;
|
69 |
|
|
signal syscon_baud_lock : std_logic;
|
70 |
|
|
-- System Bus interface
|
71 |
|
|
signal syscon_ack : std_logic;
|
72 |
|
|
signal syscon_err : std_logic;
|
73 |
|
|
signal syscon_dat_rd : unsigned(31 downto 0);
|
74 |
|
|
signal syscon_dat_wr : unsigned(31 downto 0);
|
75 |
|
|
signal syscon_rst : std_logic;
|
76 |
|
|
signal syscon_cyc : std_logic;
|
77 |
|
|
signal syscon_adr : unsigned(31 downto 0);
|
78 |
|
|
signal syscon_we : std_logic;
|
79 |
|
|
|
80 |
|
|
signal sel_reg : std_logic;
|
81 |
|
|
signal reg_dat_rd : unsigned(31 downto 0);
|
82 |
|
|
signal reg_ack : std_logic;
|
83 |
|
|
signal reg_err : std_logic;
|
84 |
|
|
|
85 |
|
|
signal sel_bram : std_logic;
|
86 |
|
|
signal bram_dat_rd : unsigned(31 downto 0);
|
87 |
|
|
signal bram_ack : std_logic;
|
88 |
|
|
signal bram_err : std_logic;
|
89 |
|
|
signal bram_wait : unsigned(1 downto 0);
|
90 |
|
|
|
91 |
|
|
-- Signals for system registers
|
92 |
|
|
signal sel_sysregs : std_logic;
|
93 |
|
|
signal sysregs_ack : std_logic;
|
94 |
|
|
signal sysregs_err : std_logic;
|
95 |
|
|
signal sysregs_dat_rd : unsigned(31 downto 0);
|
96 |
|
|
signal center_f1 : unsigned(31 downto 0);
|
97 |
|
|
signal center_f2 : unsigned(31 downto 0);
|
98 |
|
|
signal center_f : unsigned(31 downto 0);
|
99 |
|
|
signal rgb_1 : unsigned(23 downto 0);
|
100 |
|
|
signal rgb_2 : unsigned(23 downto 0);
|
101 |
|
|
signal p9813_rgb : unsigned(23 downto 0);
|
102 |
|
|
signal rnrzl_enable : std_logic;
|
103 |
|
|
|
104 |
|
|
-- Signals for bit synchronizer units
|
105 |
|
|
signal speed_bit : std_logic;
|
106 |
|
|
signal alex_kp : unsigned(31 downto 0);
|
107 |
|
|
signal alex_ki : unsigned(31 downto 0);
|
108 |
|
|
signal sync_0_idle : std_logic;
|
109 |
|
|
signal sync_0_lock : std_logic;
|
110 |
|
|
signal sync_0_dat : std_logic;
|
111 |
|
|
signal sync_0_clk : std_logic;
|
112 |
|
|
signal clk_in_r1 : std_logic;
|
113 |
|
|
signal clk_in_r2 : std_logic;
|
114 |
|
|
signal clk_out : std_logic;
|
115 |
|
|
signal dat_out : std_logic;
|
116 |
|
|
signal dat_in : std_logic;
|
117 |
|
|
signal dat_rnrzl : std_logic;
|
118 |
|
|
|
119 |
|
|
-- Signals for derandomizer
|
120 |
|
|
signal derand_sr : unsigned(DERAND_BITS-1 downto 0);
|
121 |
|
|
signal pcm_dr_taps : unsigned(DERAND_BITS-1 downto 0);
|
122 |
|
|
|
123 |
|
|
-- Fun related
|
124 |
|
|
signal larson_pulse_1 : std_logic;
|
125 |
|
|
signal larson_pulse_2 : std_logic;
|
126 |
|
|
signal c1 : unsigned(7 downto 0);
|
127 |
|
|
signal c1_dir : std_logic;
|
128 |
|
|
signal c2 : unsigned(7 downto 0);
|
129 |
|
|
signal c2_dir : std_logic;
|
130 |
|
|
|
131 |
|
|
-- Test related
|
132 |
|
|
-- Signals for the randomizer and PN sequence generator
|
133 |
|
|
signal pn_freq : unsigned(32 downto 0);
|
134 |
|
|
signal pn_clk_pulse : std_logic;
|
135 |
|
|
signal pn_seq : std_logic;
|
136 |
|
|
signal rand_sr : unsigned(15 downto 0);
|
137 |
|
|
signal rand_bit : std_logic;
|
138 |
|
|
signal ber_bit : std_logic;
|
139 |
|
|
signal ber_errors : unsigned(31 downto 0);
|
140 |
|
|
signal ber_bits : unsigned(31 downto 0);
|
141 |
|
|
signal ber_center_f1 : unsigned(31 downto 0);
|
142 |
|
|
signal ber_center_f2 : unsigned(31 downto 0);
|
143 |
|
|
signal ber_center_f : unsigned(31 downto 0);
|
144 |
|
|
signal ber_rnrzl_enable : std_logic;
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
-------------------------------------------------
|
148 |
|
|
begin
|
149 |
|
|
|
150 |
|
|
-- instantiate an internal reset
|
151 |
|
|
-- intrst : internal_reset
|
152 |
|
|
-- PORT MAP (
|
153 |
|
|
-- nReset_o => sys_rst_l
|
154 |
|
|
-- );
|
155 |
|
|
sys_rst_l <= '1';
|
156 |
|
|
|
157 |
|
|
-- Reset is not complicated
|
158 |
|
|
sys_rst_n <= '0' when sys_rst_l='0' or sys_rst_n_i='0' else '1';
|
159 |
|
|
sys_rst <= '1' when sys_rst_l='0' or sys_rst_n_i='0' else '0';
|
160 |
|
|
|
161 |
|
|
-- This design uses a 50 MHz clock
|
162 |
|
|
sys_clk <= sys_clk_ref;
|
163 |
|
|
|
164 |
|
|
-- System clock enable currently not used.
|
165 |
|
|
sys_clk_en <= '1';
|
166 |
|
|
|
167 |
|
|
------------------------------
|
168 |
|
|
-- Assign LED outputs
|
169 |
|
|
led_disp <= led_reg xor (c1 or c2);
|
170 |
|
|
led <= not led_disp;
|
171 |
|
|
|
172 |
|
|
------------------------------
|
173 |
|
|
-- Invert switch inputs. On this board, active or "on" is low...
|
174 |
|
|
switch_l <= not switch;
|
175 |
|
|
|
176 |
|
|
------------------------------
|
177 |
|
|
-- Provide a default of "high impedance" for all the potentially
|
178 |
|
|
-- unused pins
|
179 |
|
|
|
180 |
|
|
exp_io <= (others=>'Z');
|
181 |
|
|
|
182 |
|
|
-------------------------
|
183 |
|
|
-- A clock enable pulse
|
184 |
|
|
c1_clkgen: entity work.dds_constant_squarewave
|
185 |
|
|
generic map(
|
186 |
|
|
OUTPUT_FREQ => 32.0, -- Desired output frequency
|
187 |
|
|
SYS_CLK_RATE => SYS_CLK_RATE, -- underlying clock rate
|
188 |
|
|
ACC_BITS => 32 -- Bit width of DDS phase accumulator
|
189 |
|
|
)
|
190 |
|
|
port map(
|
191 |
|
|
|
192 |
|
|
sys_rst_n => sys_rst_n,
|
193 |
|
|
sys_clk => sys_clk,
|
194 |
|
|
sys_clk_en => sys_clk_en,
|
195 |
|
|
|
196 |
|
|
-- Output
|
197 |
|
|
pulse_o => larson_pulse_1,
|
198 |
|
|
squarewave_o => open
|
199 |
|
|
);
|
200 |
|
|
|
201 |
|
|
-------------------------
|
202 |
|
|
-- A clock enable pulse
|
203 |
|
|
c2_clkgen: entity work.dds_constant_squarewave
|
204 |
|
|
generic map(
|
205 |
|
|
OUTPUT_FREQ => 16.2, -- Desired output frequency
|
206 |
|
|
SYS_CLK_RATE => SYS_CLK_RATE, -- underlying clock rate
|
207 |
|
|
ACC_BITS => 32 -- Bit width of DDS phase accumulator
|
208 |
|
|
)
|
209 |
|
|
port map(
|
210 |
|
|
|
211 |
|
|
sys_rst_n => sys_rst_n,
|
212 |
|
|
sys_clk => sys_clk,
|
213 |
|
|
sys_clk_en => sys_clk_en,
|
214 |
|
|
|
215 |
|
|
-- Output
|
216 |
|
|
pulse_o => larson_pulse_2,
|
217 |
|
|
squarewave_o => open
|
218 |
|
|
);
|
219 |
|
|
-- Larson scanner #1
|
220 |
|
|
process (sys_clk,sys_rst_n)
|
221 |
|
|
begin
|
222 |
|
|
if (sys_rst_n='0') then
|
223 |
|
|
c1 <= (0=>'1', others=>'0');
|
224 |
|
|
c1_dir <= '0';
|
225 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
226 |
|
|
if (sys_clk_en='1') then
|
227 |
|
|
if (larson_pulse_1='1') then
|
228 |
|
|
if (c1_dir='0') then
|
229 |
|
|
c1 <= c1(c1'length-2 downto 0) & '0';
|
230 |
|
|
if (c1="01000000") then
|
231 |
|
|
c1_dir <= '1';
|
232 |
|
|
end if;
|
233 |
|
|
else
|
234 |
|
|
c1 <= '0' & c1(c1'length-1 downto 1);
|
235 |
|
|
if (c1="00000010") then
|
236 |
|
|
c1_dir <= '0';
|
237 |
|
|
end if;
|
238 |
|
|
end if;
|
239 |
|
|
end if;
|
240 |
|
|
end if;
|
241 |
|
|
end if;
|
242 |
|
|
end process;
|
243 |
|
|
-- Larson scanner #2
|
244 |
|
|
process (sys_clk,sys_rst_n)
|
245 |
|
|
begin
|
246 |
|
|
if (sys_rst_n='0') then
|
247 |
|
|
c2 <= (0=>'1', others=>'0');
|
248 |
|
|
c2_dir <= '0';
|
249 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
250 |
|
|
if (sys_clk_en='1') then
|
251 |
|
|
if (larson_pulse_2='1') then
|
252 |
|
|
if (c2_dir='0') then
|
253 |
|
|
c2 <= c2(c2'length-2 downto 0) & '0';
|
254 |
|
|
if (c2="01000000") then
|
255 |
|
|
c2_dir <= '1';
|
256 |
|
|
end if;
|
257 |
|
|
else
|
258 |
|
|
c2 <= '0' & c2(c2'length-1 downto 1);
|
259 |
|
|
if (c2="00000010") then
|
260 |
|
|
c2_dir <= '0';
|
261 |
|
|
end if;
|
262 |
|
|
end if;
|
263 |
|
|
end if;
|
264 |
|
|
end if;
|
265 |
|
|
end if;
|
266 |
|
|
end process;
|
267 |
|
|
|
268 |
|
|
------------------------------
|
269 |
|
|
-- This module generates a serial BAUD clock automatically.
|
270 |
|
|
-- The unit synchronizes on the carriage return character, so the user
|
271 |
|
|
-- only needs to press the "enter" key for serial communications to start
|
272 |
|
|
-- working, no matter what BAUD rate and clk_i frequency are used, within
|
273 |
|
|
-- reason, of course.
|
274 |
|
|
|
275 |
|
|
auto_baud1 : entity work.auto_baud_with_tracking
|
276 |
|
|
generic map(
|
277 |
|
|
CLOCK_FACTOR => 1, -- Output is this factor times the baud rate
|
278 |
|
|
FPGA_CLKRATE => SYS_CLK_RATE, -- FPGA system clock rate
|
279 |
|
|
MIN_BAUDRATE => 19200.0, -- Minimum expected incoming Baud rate
|
280 |
|
|
DELTA_THRESHOLD => 200 -- Measurement filter constraint. Smaller = tougher.
|
281 |
|
|
)
|
282 |
|
|
port map(
|
283 |
|
|
|
284 |
|
|
sys_rst_n => sys_rst_n,
|
285 |
|
|
sys_clk => sys_clk,
|
286 |
|
|
sys_clk_en => sys_clk_en,
|
287 |
|
|
|
288 |
|
|
-- rate and parity
|
289 |
|
|
rx_parity_i => "00", -- 0=none, 1=even, 2=odd
|
290 |
|
|
|
291 |
|
|
-- serial input
|
292 |
|
|
rx_stream_i => uart_0_rx_i,
|
293 |
|
|
|
294 |
|
|
-- Output
|
295 |
|
|
baud_lock_o => syscon_baud_lock,
|
296 |
|
|
baud_clk_o => syscon_baud_clk
|
297 |
|
|
);
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
-- ascii_syscon mounted with a UART interface
|
301 |
|
|
syscon_1 : entity work.async_syscon
|
302 |
|
|
generic map(
|
303 |
|
|
ECHO_COMMANDS => 1, -- set nonzero to echo back command characters
|
304 |
|
|
ADR_DIGITS => 8, -- # of hex digits for address
|
305 |
|
|
DAT_DIGITS => 8, -- # of hex digits for data
|
306 |
|
|
QTY_DIGITS => 4, -- # of hex digits for quantity
|
307 |
|
|
CMD_BUFFER_SIZE => 64, -- # of chars in the command buffer
|
308 |
|
|
WATCHDOG_VALUE => 20, -- # of sys_clks before ack is expected
|
309 |
|
|
DISPLAY_FIELDS => 4 -- # of fields/line
|
310 |
|
|
)
|
311 |
|
|
port map(
|
312 |
|
|
|
313 |
|
|
sys_rst_n => sys_rst_n,
|
314 |
|
|
sys_clk => sys_clk,
|
315 |
|
|
sys_clk_en => sys_clk_en,
|
316 |
|
|
|
317 |
|
|
-- rate and parity
|
318 |
|
|
parity_i => "00", -- 0=none, 1=even, 2=odd
|
319 |
|
|
baud_clk_i => syscon_baud_clk, -- At 1x the desired baud rate, can be squarewave or pulses.
|
320 |
|
|
baud_lock_i => syscon_baud_lock, -- '1' Indicates baud clock is stable and ready.
|
321 |
|
|
|
322 |
|
|
-- Serial IO
|
323 |
|
|
cmd_i => uart_0_rx_i,
|
324 |
|
|
resp_o => uart_0_tx_o,
|
325 |
|
|
cmd_done_o => open,
|
326 |
|
|
|
327 |
|
|
-- Master Bus IO
|
328 |
|
|
master_bg_i => '1',
|
329 |
|
|
master_ack_o => open,
|
330 |
|
|
master_adr_i => to_unsigned(0,32),
|
331 |
|
|
master_dat_i => to_unsigned(0,32),
|
332 |
|
|
master_dat_o => open,
|
333 |
|
|
master_stb_i => '0',
|
334 |
|
|
master_we_i => '0',
|
335 |
|
|
master_br_o => open,
|
336 |
|
|
|
337 |
|
|
-- System Bus IO
|
338 |
|
|
ack_i => syscon_ack,
|
339 |
|
|
err_i => syscon_err,
|
340 |
|
|
dat_i => syscon_dat_rd,
|
341 |
|
|
dat_o => syscon_dat_wr,
|
342 |
|
|
rst_o => syscon_rst,
|
343 |
|
|
stb_o => open,
|
344 |
|
|
cyc_o => syscon_cyc,
|
345 |
|
|
adr_o => syscon_adr,
|
346 |
|
|
we_o => syscon_we
|
347 |
|
|
);
|
348 |
|
|
|
349 |
|
|
--------------------------
|
350 |
|
|
-- syscon bus selection --
|
351 |
|
|
--------------------------
|
352 |
|
|
with to_integer(syscon_adr(31 downto 24)) select
|
353 |
|
|
syscon_dat_rd <=
|
354 |
|
|
bram_dat_rd when 2,
|
355 |
|
|
reg_dat_rd when 3,
|
356 |
|
|
str2u("01234567",32) when others;
|
357 |
|
|
|
358 |
|
|
with to_integer(syscon_adr(31 downto 24)) select
|
359 |
|
|
syscon_ack <=
|
360 |
|
|
bram_ack when 2,
|
361 |
|
|
reg_ack when 3,
|
362 |
|
|
'1' when others;
|
363 |
|
|
|
364 |
|
|
with to_integer(syscon_adr(31 downto 24)) select
|
365 |
|
|
syscon_err <=
|
366 |
|
|
bram_err when 2,
|
367 |
|
|
reg_err when 3,
|
368 |
|
|
syscon_cyc when others;
|
369 |
|
|
|
370 |
|
|
sel_bram <= '1' when syscon_cyc='1' and to_integer(syscon_adr(31 downto 24))=2 else '0';
|
371 |
|
|
sel_reg <= '1' when syscon_cyc='1' and to_integer(syscon_adr(31 downto 24))=3 else '0';
|
372 |
|
|
|
373 |
|
|
----------------------------
|
374 |
|
|
-- register bus selection --
|
375 |
|
|
----------------------------
|
376 |
|
|
with to_integer(syscon_adr(23 downto 8)) select
|
377 |
|
|
reg_dat_rd <=
|
378 |
|
|
sysregs_dat_rd when 16#00FF#,
|
379 |
|
|
str2u("11112222",32) when others;
|
380 |
|
|
|
381 |
|
|
with to_integer(syscon_adr(23 downto 8)) select
|
382 |
|
|
reg_ack <=
|
383 |
|
|
sysregs_ack when 16#00FF#,
|
384 |
|
|
'1' when others;
|
385 |
|
|
|
386 |
|
|
with to_integer(syscon_adr(23 downto 8)) select
|
387 |
|
|
reg_err <=
|
388 |
|
|
sysregs_err when 16#00FF#,
|
389 |
|
|
sel_reg when others;
|
390 |
|
|
|
391 |
|
|
sel_sysregs <= '1' when sel_reg='1' and to_integer(syscon_adr(23 downto 8))=16#00FF# else '0';
|
392 |
|
|
|
393 |
|
|
-----------------------------
|
394 |
|
|
-- System Registers --
|
395 |
|
|
-----------------------------
|
396 |
|
|
with to_integer(syscon_adr(7 downto 0)) select
|
397 |
|
|
sysregs_dat_rd <=
|
398 |
|
|
center_f1 when 0,
|
399 |
|
|
ber_center_f1 when 1,
|
400 |
|
|
center_f2 when 2,
|
401 |
|
|
ber_center_f2 when 3,
|
402 |
|
|
to_unsigned(0,27) & speed_bit &
|
403 |
|
|
"00" & ber_rnrzl_enable & rnrzl_enable when 4,
|
404 |
|
|
resize(rgb_1,32) when 240,
|
405 |
|
|
resize(rgb_2,32) when 241,
|
406 |
|
|
ber_errors when 250,
|
407 |
|
|
ber_bits when 251,
|
408 |
|
|
to_unsigned(0,30) & sync_0_lock & sync_0_idle when 252,
|
409 |
|
|
resize(switch_l,32) when 253,
|
410 |
|
|
FPGA_VERSION when 254,
|
411 |
|
|
resize(led_reg,32) when 255,
|
412 |
|
|
syscon_adr(7 downto 0) & syscon_adr(7 downto 0) & syscon_adr(7 downto 0) & syscon_adr(7 downto 0)
|
413 |
|
|
when others;
|
414 |
|
|
|
415 |
|
|
with to_integer(syscon_adr(7 downto 0)) select
|
416 |
|
|
sysregs_ack <=
|
417 |
|
|
sel_sysregs when others;
|
418 |
|
|
|
419 |
|
|
with to_integer(syscon_adr(7 downto 0)) select
|
420 |
|
|
sysregs_err <=
|
421 |
|
|
'0' when others;
|
422 |
|
|
|
423 |
|
|
--------------------------
|
424 |
|
|
-- Bit Error Rate Counts
|
425 |
|
|
proc_bert: Process(sys_rst_n,sys_clk)
|
426 |
|
|
begin
|
427 |
|
|
if (sys_rst_n = '0') then
|
428 |
|
|
elsif (sys_clk'event AND sys_clk='1') then
|
429 |
|
|
end if;
|
430 |
|
|
end process;
|
431 |
|
|
|
432 |
|
|
-- Handle writes to system registers
|
433 |
|
|
process (sys_clk,sys_rst_n)
|
434 |
|
|
begin
|
435 |
|
|
if (sys_rst_n='0') then
|
436 |
|
|
ber_errors <= (others=>'0');
|
437 |
|
|
ber_bits <= (others=>'0');
|
438 |
|
|
led_reg <= (others=>'0');
|
439 |
|
|
center_f1 <= to_unsigned(integer(128095.0*(2.0**10.0)/SYS_CLK_RATE*(2.0**23.0)),center_f1'length);
|
440 |
|
|
ber_center_f1 <= to_unsigned(integer(128095.0*(2.0**10.0)/SYS_CLK_RATE*(2.0**23.0)),ber_center_f1'length);
|
441 |
|
|
center_f2 <= to_unsigned(integer(2000000.0*(2.0**10.0)/SYS_CLK_RATE*(2.0**23.0)),center_f2'length);
|
442 |
|
|
ber_center_f2 <= to_unsigned(integer(2000000.0*(2.0**10.0)/SYS_CLK_RATE*(2.0**23.0)),ber_center_f2'length);
|
443 |
|
|
ber_rnrzl_enable <= '0';
|
444 |
|
|
rnrzl_enable <= '0';
|
445 |
|
|
rgb_1 <= str2u("802020",rgb_1'length);
|
446 |
|
|
rgb_2 <= str2u("200080",rgb_2'length);
|
447 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
448 |
|
|
if (sys_clk_en='1') then
|
449 |
|
|
if (sysregs_ack='1' and syscon_we='1') then
|
450 |
|
|
case to_integer(syscon_adr(7 downto 0)) is
|
451 |
|
|
when 0 =>
|
452 |
|
|
center_f1 <= syscon_dat_wr;
|
453 |
|
|
when 1 =>
|
454 |
|
|
ber_center_f1 <= syscon_dat_wr;
|
455 |
|
|
when 2 =>
|
456 |
|
|
center_f2 <= syscon_dat_wr;
|
457 |
|
|
when 3 =>
|
458 |
|
|
ber_center_f2 <= syscon_dat_wr;
|
459 |
|
|
when 4 =>
|
460 |
|
|
rnrzl_enable <= syscon_dat_wr(0);
|
461 |
|
|
ber_rnrzl_enable <= syscon_dat_wr(1);
|
462 |
|
|
when 240 =>
|
463 |
|
|
rgb_1 <= syscon_dat_wr(rgb_1'length-1 downto 0);
|
464 |
|
|
when 241 =>
|
465 |
|
|
rgb_2 <= syscon_dat_wr(rgb_2'length-1 downto 0);
|
466 |
|
|
when 250 =>
|
467 |
|
|
ber_errors <= (others=>'0');
|
468 |
|
|
when 251 =>
|
469 |
|
|
ber_bits <= (others=>'0');
|
470 |
|
|
when 255 =>
|
471 |
|
|
led_reg <= syscon_dat_wr(led_reg'length-1 downto 0);
|
472 |
|
|
when others =>
|
473 |
|
|
null;
|
474 |
|
|
end case;
|
475 |
|
|
end if;
|
476 |
|
|
-- Increment the counters if there are data mismatches
|
477 |
|
|
if (pn_clk_pulse='1') then
|
478 |
|
|
ber_bits <= ber_bits+1;
|
479 |
|
|
if (dat_out/=pn_seq) then
|
480 |
|
|
ber_errors <= ber_errors+1;
|
481 |
|
|
end if;
|
482 |
|
|
end if;
|
483 |
|
|
end if; -- sys_clk_en
|
484 |
|
|
end if; -- sys_clk
|
485 |
|
|
end process;
|
486 |
|
|
|
487 |
|
|
---------------------------------------------------------
|
488 |
|
|
-- Acknowledge Signal for BRAM
|
489 |
|
|
process (sys_clk,sys_rst_n)
|
490 |
|
|
begin
|
491 |
|
|
if (sys_rst_n='0') then
|
492 |
|
|
bram_wait <= (others=>'0');
|
493 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
494 |
|
|
if (sys_clk_en='1') then
|
495 |
|
|
if sel_bram='1' and bram_ack='0' then
|
496 |
|
|
bram_wait <= bram_wait+1;
|
497 |
|
|
else
|
498 |
|
|
bram_wait <= (others=>'0');
|
499 |
|
|
end if;
|
500 |
|
|
end if;
|
501 |
|
|
end if;
|
502 |
|
|
end process;
|
503 |
|
|
bram_ack <= '1' when (bram_wait=1 and sel_bram='1') else '0';
|
504 |
|
|
|
505 |
|
|
----------------------------
|
506 |
|
|
-- RAM block selection --
|
507 |
|
|
----------------------------
|
508 |
|
|
bram_dat_rd <= to_unsigned(16#1234#,bram_dat_rd'length);
|
509 |
|
|
bram_err <= syscon_cyc;
|
510 |
|
|
|
511 |
|
|
|
512 |
|
|
--------------------------------
|
513 |
|
|
-- Digital Bit synchronizers --
|
514 |
|
|
--------------------------------
|
515 |
|
|
alex_kp <= to_unsigned(16#00094F59#,alex_kp'length); -- Alex DPLL kp factor
|
516 |
|
|
alex_ki <= to_unsigned(16#00000793#,alex_ki'length); -- Alex DPLL ki factor
|
517 |
|
|
|
518 |
|
|
bit_sync_0 : entity work.bit_sync_digital
|
519 |
|
|
generic map(
|
520 |
|
|
ALEX_K_BITS => ALEX_K_BITS, -- Number of bits in Alexander DPLL coefficients
|
521 |
|
|
ALEX_K_FRAC => ALEX_K_FRAC, -- How many of the ALEX_K_BITS are used for fractional representation
|
522 |
|
|
ALEX_GAIN_ADJ => ALEX_GAIN_ADJ, -- How many bits to reduce KP_i and KI_i during lock
|
523 |
|
|
FSTEP_FINE => 1, -- Frequency increment during phase track
|
524 |
|
|
PHASE_WIDTH => 33, -- Bits in the phase accumulator
|
525 |
|
|
LOCK_VAL => 4, -- Period mismatch to obtain lock
|
526 |
|
|
DROP_LOCK_VAL => 12, -- Period mismatch to drop lock
|
527 |
|
|
PERIOD_I_WIDTH => 16, -- Integer width of period measurements
|
528 |
|
|
PERIOD_F_WIDTH => 2, -- Fractional width of period measurements
|
529 |
|
|
IDLE_CLOCKS => 2**16, -- sys_clk periods before signal is called idle
|
530 |
|
|
BAUD_READS => 127, -- Period baud interval read attempts
|
531 |
|
|
INTERVAL_READS => 64, -- Period interval read attempts
|
532 |
|
|
WINDOW_SIZE => 3 -- Period variation window, in sys_clks
|
533 |
|
|
)
|
534 |
|
|
port map(
|
535 |
|
|
-- System Clock and Clock Enable
|
536 |
|
|
sys_rst_n => sys_rst_n,
|
537 |
|
|
sys_clk => sys_clk,
|
538 |
|
|
sys_clk_en => sys_clk_en,
|
539 |
|
|
|
540 |
|
|
-- Frequency calibration clk enable
|
541 |
|
|
cal_clk_en => '1', -- Calibration in Hz removed. Units are now (Fsys_clk/2^33) Hz.
|
542 |
|
|
|
543 |
|
|
-- Settings
|
544 |
|
|
freq_i => center_f,
|
545 |
|
|
freq_seek_i => '0',
|
546 |
|
|
use_alex_i => '0',
|
547 |
|
|
alex_kp_i => alex_kp(ALEX_K_BITS-ALEX_K_FRAC-1 downto 0),
|
548 |
|
|
alex_ki_i => alex_ki(ALEX_K_BITS-ALEX_K_FRAC-1 downto 0),
|
549 |
|
|
|
550 |
|
|
-- Reference data input
|
551 |
|
|
dat_i => dat_in,
|
552 |
|
|
|
553 |
|
|
-- indicators and outputs
|
554 |
|
|
idle_o => sync_0_idle,
|
555 |
|
|
lock_o => sync_0_lock,
|
556 |
|
|
dat_o => sync_0_dat,
|
557 |
|
|
clk_o => sync_0_clk
|
558 |
|
|
);
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
--------------------------
|
562 |
|
|
-- Derandomizer shift register
|
563 |
|
|
pcm_dr_taps <= to_unsigned(16#6000#,pcm_dr_taps'length);
|
564 |
|
|
proc_derand_sr: Process(sys_rst_n,sys_clk)
|
565 |
|
|
begin
|
566 |
|
|
if (sys_rst_n = '0') then
|
567 |
|
|
derand_sr <= (others=>'0');
|
568 |
|
|
clk_in_r1 <= '0';
|
569 |
|
|
clk_in_r2 <= '0';
|
570 |
|
|
dat_rnrzl <= '0';
|
571 |
|
|
elsif (sys_clk'event AND sys_clk='1') then
|
572 |
|
|
clk_in_r1 <= sync_0_clk;
|
573 |
|
|
clk_in_r2 <= clk_in_r1;
|
574 |
|
|
if (clk_in_r1='0' and clk_in_r2='1') then -- falling edge
|
575 |
|
|
derand_sr <= derand_sr(derand_sr'length-2 downto 0) & sync_0_dat;
|
576 |
|
|
-- Latch outputs in synchronism with clock edge
|
577 |
|
|
dat_rnrzl <= sync_0_dat xor u_recursive_parity(derand_sr and pcm_dr_taps);
|
578 |
|
|
end if;
|
579 |
|
|
end if;
|
580 |
|
|
end process;
|
581 |
|
|
clk_out <= clk_in_r2;
|
582 |
|
|
|
583 |
|
|
-- Obtain data input from desired pins
|
584 |
|
|
dat_in <= exp_io(32);
|
585 |
|
|
|
586 |
|
|
-- Select which data goes out
|
587 |
|
|
dat_out <= dat_rnrzl when rnrzl_enable='1' else sync_0_dat;
|
588 |
|
|
|
589 |
|
|
-- Map outputs to desired pins
|
590 |
|
|
exp_io(35) <= dat_out;
|
591 |
|
|
exp_io(34) <= clk_out;
|
592 |
|
|
exp_io(36) <= dat_out;
|
593 |
|
|
exp_io(37) <= not dat_out;
|
594 |
|
|
exp_io(38) <= clk_out;
|
595 |
|
|
exp_io(39) <= not clk_out;
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
--------------------------
|
599 |
|
|
-- For test purposes, generate a PN sequence and randomize it.
|
600 |
|
|
-- Send it out on a pin, for use in testing the bit synchronizer.
|
601 |
|
|
-- Check the bit synchronized data against the generated data,
|
602 |
|
|
-- and count the total bits and the errors, if any.
|
603 |
|
|
-------------------------
|
604 |
|
|
-- A clock enable pulse for use with PN sequence and randomizer
|
605 |
|
|
pn_freq <= '0' & ber_center_f;
|
606 |
|
|
pn_clkgen : entity work.dds_squarewave
|
607 |
|
|
generic map(
|
608 |
|
|
ACC_BITS => 33 -- Bit width of DDS phase accumulator
|
609 |
|
|
)
|
610 |
|
|
port map(
|
611 |
|
|
|
612 |
|
|
sys_rst_n => sys_rst_n,
|
613 |
|
|
sys_clk => sys_clk,
|
614 |
|
|
sys_clk_en => '1',
|
615 |
|
|
|
616 |
|
|
-- Frequency setting
|
617 |
|
|
freq_i => pn_freq,
|
618 |
|
|
|
619 |
|
|
-- Output
|
620 |
|
|
pulse_o => pn_clk_pulse,
|
621 |
|
|
squarewave_o => open
|
622 |
|
|
);
|
623 |
|
|
|
624 |
|
|
------------------------------------------------------------------------
|
625 |
|
|
-- Instantiate a maximum-cycle linear feedback shift register
|
626 |
|
|
-- which generates a pseudo-noise sequence
|
627 |
|
|
pn_0 : entity work.mlfsr
|
628 |
|
|
generic map(
|
629 |
|
|
POLY_A => 32, -- Polynomial tap, also number of bits in shift register
|
630 |
|
|
POLY_B => 30, -- Polynomial tap, less than POLY_A
|
631 |
|
|
POLY_C => 26, -- Polynomial tap, less than POLY_B
|
632 |
|
|
POLY_D => 25 -- Polynomial tap, less than POLY_C
|
633 |
|
|
)
|
634 |
|
|
port map(
|
635 |
|
|
-- System Clock and Clock Enable
|
636 |
|
|
sys_rst_n => sys_rst_n,
|
637 |
|
|
sys_clk => sys_clk,
|
638 |
|
|
sys_clk_en => pn_clk_pulse,
|
639 |
|
|
|
640 |
|
|
-- Sequence Output
|
641 |
|
|
pn_seq_o => pn_seq
|
642 |
|
|
|
643 |
|
|
);
|
644 |
|
|
|
645 |
|
|
--------------------------
|
646 |
|
|
-- Randomizer shift register
|
647 |
|
|
proc_rand_sr: Process(sys_rst_n,sys_clk)
|
648 |
|
|
begin
|
649 |
|
|
if (sys_rst_n = '0') then
|
650 |
|
|
rand_sr <= (others=>'0');
|
651 |
|
|
elsif (sys_clk'event AND sys_clk='1') then
|
652 |
|
|
if (pn_clk_pulse='1') then
|
653 |
|
|
rand_sr <= rand_sr(rand_sr'length-2 downto 0) & rand_bit;
|
654 |
|
|
end if;
|
655 |
|
|
end if;
|
656 |
|
|
end process;
|
657 |
|
|
rand_bit <= pn_seq xor u_recursive_parity(rand_sr and to_unsigned(16#6000#,16));
|
658 |
|
|
ber_bit <= rand_bit when ber_rnrzl_enable='1' else pn_seq;
|
659 |
|
|
|
660 |
|
|
-- Provide outputs for testing
|
661 |
|
|
exp_io(1) <= ber_bit;
|
662 |
|
|
exp_io(2) <= not ber_bit;
|
663 |
|
|
|
664 |
|
|
|
665 |
|
|
-- Create a colorful LED indicator
|
666 |
|
|
-- Use it to indicate at what speed the bit synchronizer center frequency
|
667 |
|
|
-- is set. The speed is set by a rocker switch.
|
668 |
|
|
indicator : entity work.p9813_LED_chain_driver
|
669 |
|
|
generic map(
|
670 |
|
|
SCLK_FREQ => 2000000.0, -- Desired lpd8806 serial clock frequency
|
671 |
|
|
UPDATE_FREQ => 200.0, -- Desired LED chain update frequency
|
672 |
|
|
SYS_CLK_RATE => SYS_CLK_RATE, -- underlying clock rate
|
673 |
|
|
N_LEDS => 1 -- Number of LEDs in chain
|
674 |
|
|
)
|
675 |
|
|
port map(
|
676 |
|
|
|
677 |
|
|
-- System Clock, Reset and Clock Enable
|
678 |
|
|
sys_rst_n => sys_rst_n,
|
679 |
|
|
sys_clk => sys_clk,
|
680 |
|
|
sys_clk_en => '1',
|
681 |
|
|
|
682 |
|
|
-- Selection of color information
|
683 |
|
|
c_adr_o => open,
|
684 |
|
|
red_i => p9813_rgb(23 downto 16),
|
685 |
|
|
grn_i => p9813_rgb(15 downto 8),
|
686 |
|
|
blu_i => p9813_rgb(7 downto 0),
|
687 |
|
|
|
688 |
|
|
-- Output
|
689 |
|
|
sclk_o => exp_io(5),
|
690 |
|
|
sdat_o => exp_io(6)
|
691 |
|
|
);
|
692 |
|
|
-- Obtain switch position
|
693 |
|
|
speed_bit <= exp_io(11);
|
694 |
|
|
|
695 |
|
|
-- Select settings based on the switch position
|
696 |
|
|
p9813_rgb <= rgb_1 when speed_bit='0' else rgb_2;
|
697 |
|
|
center_f <= center_f1 when speed_bit='0' else center_f2;
|
698 |
|
|
ber_center_f <= ber_center_f1 when speed_bit='0' else ber_center_f2;
|
699 |
|
|
|
700 |
|
|
end beh;
|