-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathref_freq.vhd
62 lines (49 loc) · 1.67 KB
/
ref_freq.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.funct.all;
entity ref_freq is
generic (
ADC_DATA_WIDTH : natural := 14;
AXIS_TDATA_WIDTH: natural := 32
);
port(
clk_i : in std_logic;
ref_sync_wave: in std_logic; -- reference signal after zero crossing
SPARTAN_clk : in std_logic;
DDS_feedback_out: out std_logic_vector (23 downto 0);
ref_period_cnt_out: out std_logic_vector (25 downto 0)
);
end ref_freq;
architecture rtl of ref_freq is
constant freq_const: unsigned (25 downto 0):="10111110101111000010000000"; --50 000 000
signal ref_period_counter: unsigned (25 downto 0):= ((0)=>'1', others=>'0');
signal ref_period_int: unsigned (25 downto 0):= ((0)=>'1', others=>'0');
signal ref_frequency: std_logic_vector (23 downto 0):=(others=>'0');
signal previous_ref_state: std_logic:='0';
begin
DDS_feedback_out <= ref_frequency;
process(SPARTAN_clk)
begin
if rising_edge(SPARTAN_clk) then
previous_ref_state <= ref_sync_wave;
if ((ref_sync_wave = '1') and (previous_ref_state = '0')) then --if reference pulse goes high, begin count
ref_period_int<=ref_period_counter;
ref_period_counter <= ((0)=>'1', others=>'0');
else -- it counts for both positive and negative periods, but period is taken for one
ref_period_counter <= ref_period_counter + 1;
end if;
end if;
end process;
process (clk_i)
begin
if rising_edge(clk_i) then
--ref_frequency<=std_logic_vector(resize(ref_period_int, 24));
if (ref_period_int>1) then
ref_frequency <= std_logic_vector(resize(divide(freq_const, ref_period_int), 24));
else
ref_frequency <= (others=>'0');
end if;
end if;
end process;
end rtl;