1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 | use ieee.std_logic_arith.all;
|
5 | library diamond;
|
6 | use diamond.chan_pkg.all;
|
7 |
|
8 | entity adc_read is
|
9 | port (
|
10 | -- @Diamond3L Begin@
|
11 | -- Do not alter the contents of the block between the begin and end tags.
|
12 | x_chan_in_0 : IN X_chan_t; --port not named
|
13 | y_chan_in_0 : OUT Y_chan_t; --port not named
|
14 | x_chan_out_0 : OUT X_chan_t; --ADC_OUT
|
15 | y_chan_out_0 : IN Y_chan_t; --ADC_OUT
|
16 | -- @Diamond3L End@
|
17 |
|
18 | ADCA_DATA_CLK : in std_logic; -- ADC Clock IN vom ADC
|
19 | ADCA_DATA : in std_logic_vector (13 downto 0); -- ADC CHA
|
20 | ADCB_DATA : in std_logic_vector (13 downto 0); -- ADC CHB
|
21 |
|
22 | LED : out std_logic;
|
23 |
|
24 | -- The following signals are always required for a task
|
25 | clk : IN std_logic;
|
26 | rst : IN std_logic;
|
27 | ce : IN std_logic;
|
28 | ce_clr : IN std_logic
|
29 | -- Do not add any ports after this point
|
30 | );
|
31 | end adc_read;
|
32 |
|
33 | architecture arch_adc_read of adc_read is
|
34 |
|
35 | -- @Diamond3L Alias Begin@
|
36 | -- Do not alter the contents of the block between the begin and end tags.
|
37 | alias ADC_OUT_x : X_chan_t is x_chan_out_0;
|
38 | alias ADC_OUT_y : Y_chan_t is y_chan_out_0;
|
39 | -- @Diamond3L Alias End@
|
40 |
|
41 | component BUFIO is
|
42 | port(
|
43 | I : in std_logic;
|
44 | O : out std_logic
|
45 | );
|
46 | end component;
|
47 |
|
48 | component BUFR
|
49 | port(
|
50 | I : in std_logic;
|
51 | CE : in std_logic;
|
52 | CLR : in std_logic;
|
53 | O : out std_logic
|
54 | );
|
55 | end component;
|
56 | signal temp_clk : std_logic; -- Zum Verbinden von BUFIO-->BUFR
|
57 |
|
58 | signal counter : integer range 0 to 7500000 := 0; -- Counter für LED
|
59 |
|
60 | signal sample_count : integer range 0 to 15 := 0; -- Counter für Samples
|
61 | signal sample_count_pre : integer range 0 to 15 := 0; -- Zum vergleich mit sample_count
|
62 | signal sample : std_logic_vector (31 downto 0); -- Zwischenspeicher für beide ADC Channels
|
63 | signal sample_rdy : std_logic; -- if (sample_count != sample_count_pre)
|
64 |
|
65 | signal write : std_logic; -- zur Kommunikation mit anderen Tasks (entity) Sundance 3L Diamond
|
66 |
|
67 | signal LED_OUT : std_logic;
|
68 |
|
69 | signal adc_clk : std_logic; -- internes Clock Signal nach BUFR
|
70 | begin
|
71 |
|
72 |
|
73 | -- erzeugen des interen adc_clk ----------------------------------
|
74 | BUFIO_CHA:BUFIO port map(I=>ADCA_DATA_CLK, O=>temp_clk);
|
75 | BUFR_CHA: BUFR port map(I=>temp_clk, CE=>'0', CLR=>'0', O=>adc_clk);
|
76 | ------------------------------------------------------------------
|
77 |
|
78 | ---- für Sundance bzw. 3L Diamond kommunikation ------------------
|
79 | y_chan_in_0.ready <= '1'; -- assume channel is ready
|
80 | ADC_OUT_x.validwords <= "01"; -- 32 Bit Word
|
81 | ADC_OUT_x.write <= write;
|
82 | -------------------------------------------------------------------
|
83 |
|
84 | LED <= LED_OUT;
|
85 |
|
86 | -- auslesen der ADC Channels mit adc_clk --------------------------
|
87 | -- Speichern in Signal sample -------------------------------------
|
88 | process(adc_clk)
|
89 | begin
|
90 | if rising_edge(adc_clk) then
|
91 | -- LED Blink ---------------------------------
|
92 | counter <= counter + 1;
|
93 | if counter = 7500000 then
|
94 | LED_OUT <= LED_OUT xor '1';
|
95 | end if;
|
96 | ----------------------------------------------
|
97 | -- Read both ADC Channels --------------------
|
98 | sample_count <= sample_count + 1;
|
99 | sample <= conv_std_logic_vector(sample_count,4) & ADCB_DATA & ADCA_DATA;
|
100 | ----------------------------------------------
|
101 | end if;
|
102 | end process;
|
103 | -------------------------------------------------------------------
|
104 |
|
105 | -- prüfen ob neues Sample angekommen ist --------------------------
|
106 | process(sample_count, sample_count_pre)
|
107 | begin
|
108 | if sample_count = sample_count_pre then
|
109 | sample_rdy <= '0';
|
110 | else
|
111 | sample_rdy <= '1';
|
112 | end if;
|
113 | end process;
|
114 | --------------------------------------------------------------------
|
115 |
|
116 | -- Auslesen des Registers (Signal) sample mit clk (Global CLK) -----
|
117 | -- Senden der Daten zum anderen Task mit Sundance bzw. 3L Diamond
|
118 | -- Kommunikations Channel
|
119 | process(clk)
|
120 | begin
|
121 | if rising_edge(clk) then
|
122 | if sample_rdy = '1' then
|
123 | sample_count_pre <= sample_count;
|
124 | if ADC_OUT_y.ready = '1' and write = '0' then
|
125 | ADC_OUT_x.data(31 downto 0) <= sample;
|
126 | ADC_OUT_x.data(63 downto 32) <= (others => '0');
|
127 | write <= '1';
|
128 | end if;
|
129 | if write = '1' then
|
130 | write <= '0';
|
131 | end if;
|
132 | end if;
|
133 | end if;
|
134 | end process;
|
135 | --------------------------------------------------------------------
|
136 |
|
137 | end arch_adc_read;
|