OpenCores
URL https://opencores.org/ocsvn/modular_oscilloscope/modular_oscilloscope/trunk

Subversion Repositories modular_oscilloscope

[/] [modular_oscilloscope/] [trunk/] [hdl/] [daq/] [daq.vhd] - Blame information for rev 57

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 budinero
----------------------------------------------------------------------------------------------------
2
--| Modular Oscilloscope
3
--| UNSL - Argentina
4
--|
5 30 budinero
--| File: daq.vhd
6 31 budinero
--| Version: 0.40
7 23 budinero
--| Tested in: Actel A3PE1500
8 31 budinero
--|   Board: RVI Prototype Board + LP Data Conversion Daughter Board
9 23 budinero
--|-------------------------------------------------------------------------------------------------
10
--| Description:
11 30 budinero
--|   Acquisition control module. 
12
--|   It drives the ADC chip.
13 23 budinero
--|-------------------------------------------------------------------------------------------------
14
--| File history:
15
--|   0.01   | apr-2008 | First testing
16
--|   0.10   | apr-2009 | First release
17 31 budinero
--|   0.40   | jul-2009 | Added a read flag for each channel and adc_clk_I input
18 23 budinero
----------------------------------------------------------------------------------------------------
19 39 budinero
--| Copyright Š 2009, Facundo Aguilera.
20 23 budinero
--|
21
--| This VHDL design file is an open design; you can redistribute it and/or
22
--| modify it and/or implement it after contacting the author.
23
 
24
--| Wishbone Rev. B.3 compatible
25
----------------------------------------------------------------------------------------------------
26
 
27 31 budinero
--==================================================================================================
28
-- TODO
29
-- ˇ Access to both channels in consecutive reads  
30
--==================================================================================================
31 23 budinero
 
32
 
33
 
34
 
35
-- Esta primera versión está realizada específicamente para controlar el ADC AD9201. Otras
36 31 budinero
-- versiones podrán ser más genéricas. 
37 23 budinero
 
38
 
39
-- ADR    configuración (seńal config)
40
-- ADR+1  datos canal 1
41
-- ADR+2  datos canal 2
42
-- ADR+3  sin usar
43
 
44
library IEEE;
45
use IEEE.STD_LOGIC_1164.all;
46
use IEEE.STD_LOGIC_UNSIGNED.ALL;
47
--use IEEE.STD_LOGIC_ARITH.all;
48
use IEEE.NUMERIC_STD.ALL;
49
--use work.adq_pgk.all;
50
 
51 30 budinero
entity daq is
52 23 budinero
  generic (
53 57 budinero
    DEFALT_CONFIG : std_logic_vector := "0000001000000000"
54
                                      -- 5432109876543210
55 23 budinero
                                      -- bits 8 a 0       clk_pre_scaler
56
                                      -- bits 9           clk_pre_scaler_ena
57 31 budinero
                                      -- bit 10           adc sleep
58 23 budinero
                                      -- bit 11           adc_chip_sel
59
                                      -- bits 12 a 15     sin usar
60
 
61
                                      -- si clk_pre_scaler_ena = 1
62
                                      -- frecuencia_adc = frecuencia_wbn / ((clk_pre_scaler+1)*2)
63
                                      -- sino frecuencia_adc = frecuencia_wbn
64
  );
65
  port(
66
    -- Externo
67 31 budinero
    adc_data_I:     in    std_logic_vector (9 downto 0);
68
    adc_sel_O:      out   std_logic;
69
    adc_clk_O:      out   std_logic;
70
    adc_sleep_O:    out   std_logic;
71 57 budinero
    adc_chip_sel_O: out   std_logic;  -- '1' disable, '0' select
72 23 budinero
 
73
 
74
    --  Interno
75
    RST_I:  in  std_logic;
76
    CLK_I:  in  std_logic;
77
    DAT_I:  in  std_logic_vector (15 downto 0);
78
    ADR_I:  in  std_logic_vector (1 downto 0);
79
    CYC_I:  in  std_logic;
80
    STB_I:  in  std_logic;
81
    WE_I:   in  std_logic;
82
    DAT_O:  out std_logic_vector (15 downto 0);
83 31 budinero
    ACK_O:  out std_logic;
84
 
85
    adc_clk_I: std_logic
86 23 budinero
  );
87 30 budinero
end daq;
88 23 budinero
 
89
 
90 31 budinero
architecture archdaq2 of daq is
91 23 budinero
  -- Tipos
92 31 budinero
  type config_array is array(0 to 2) of std_logic_vector(15 downto 0);
93 23 budinero
 
94
 
95
                --   type arr is array(0 to 3) of std_logic_vector(15 downto 0);
96
                -- 
97
                -- signal arr_a : arr;
98
                -- signal vec_0, vec_1, vec_2, vec_3 : std_logic vector(15 downto 0);
99
                -- ....
100
                -- arr_a(0) <= vec_0;
101
                -- arr_a(1) <= vec_1;
102
                -- ....
103 31 budinero
 
104
  type data_array is array(0 to 1) of std_logic_vector(adc_data_I'length - 1 downto 0);
105
 
106 23 budinero
 
107 31 budinero
 
108
  -- Registers
109 23 budinero
  signal config:   std_logic_vector (15 downto 0);
110 31 budinero
  signal count: std_logic_vector (8 downto 0);
111
  signal channel_data: data_array;
112
  signal read_flag_adc: std_logic_vector (1 downto 0);
113
  signal read_flag_wb: std_logic_vector (1 downto 0);
114
  -- The biggest limit must be the channels number (-1)
115
  -- There are two clocks becouse there are two clocks
116
 
117
  -- Signals
118
  signal selector: config_array;
119 23 budinero
 
120 31 budinero
  signal s_adc_clk, s_adc_sleep, s_adc_chip_sel: std_logic; -- previous to outputs
121
  signal reduced_clk, same_clk: std_logic;
122 23 budinero
  signal data_ack_ready:      std_logic; -- habilita confirmación de datos
123
  signal conf_ack_ready:      std_logic; -- habilita confirmación de escritura de configuración
124
  signal clk_pre_scaler:      std_logic_vector (8 downto 0);
125
  signal clk_pre_scaler_ena:  std_logic;
126 31 budinero
  signal channel_sel:         std_logic_vector(0 downto 0); -- max limit must be the number of channels
127
  signal count_reset:          std_logic;
128
  signal count_max:           std_logic;
129 23 budinero
  --signal clk_enable: std_logic_vector (9 downto 0);
130
 
131
begin
132
  --------------------------------------------------------------------------------------------------
133
  -- Asignaciones
134 31 budinero
  ---- Internal 
135
  selector(0) <= (config'length - 1 downto adc_data_I'length => '0' ) &
136
                 channel_data(conv_integer(channel_sel));
137
  selector(1) <= (config'length - 1 downto adc_data_I'length => '0' ) &
138
                 channel_data(conv_integer(channel_sel));
139
  selector(2) <= config;
140
  --selector(3) <= (others => '0' ); -- Unassigned
141
 
142
 
143 23 budinero
 
144 31 budinero
  ---- Config register
145 23 budinero
  clk_pre_scaler <= config(8 downto 0);
146
  clk_pre_scaler_ena <= config(9);
147
  s_adc_sleep <= config(10);
148
  s_adc_chip_sel <= config(11);
149 31 budinero
  -- Unassigned <= config(13); 
150
  -- Unassigned <= config(14);
151
  -- Unassigned <= config(15);
152 23 budinero
 
153 31 budinero
  ---- External communication (AD)
154
  adc_sleep_O <= s_adc_sleep;
155
  adc_chip_sel_O <= s_adc_chip_sel;
156
 
157 23 budinero
 
158
 
159
 
160
  --------------------------------------------------------------------------------------------------
161 31 budinero
  -- Generación de adc_clk_O
162
  count_max <= '1' when count >= clk_pre_scaler else '0';
163
  count_reset <=  RST_I or count_max or not(clk_pre_scaler_ena);
164
 
165
  P_count: process (adc_clk_I, count, count_reset)
166 23 budinero
  begin
167 31 budinero
    if adc_clk_I'event and adc_clk_I = '1'  then
168
      if count_reset = '1' then
169
        count <= (others => '0');
170
      else
171 23 budinero
        count <= count + 1;
172
      end if;
173
    end if;
174
  end process;
175
 
176 31 budinero
  P_adcclk: process (adc_clk_I, RST_I, clk_pre_scaler_ena)
177
  begin
178
    if adc_clk_I'event and adc_clk_I = '1'  then
179
      if RST_I = '1' or clk_pre_scaler_ena = '0' then
180
        reduced_clk <= '0';
181
      elsif count_max = '1' then
182
        reduced_clk <= not(reduced_clk);
183
      end if;
184
    end if;
185
    -- OLD     
186
    --     if RST_I = '1' then
187
    --       count <= (others => '0');
188
    --       s_adc_clk <= '0';
189
    --     elsif clk_pre_scaler_ena = '1' then
190
    --       if CLK_I'event and CLK_I = '1' then
191
    --         count <= count + 1;
192
    --         if count = clk_pre_scaler  then
193
    --           s_adc_clk <= not(s_adc_clk);
194
    --           count <= (others => '0');
195
    --         end if;        
196
    --       end if;
197
    --     else  
198
    --       count <= (others => '0');
199
    --       s_adc_clk <= CLK_I;
200
    --     end if;
201
  end process;
202
  same_clk <= adc_clk_I;
203
 
204
  with clk_pre_scaler_ena select
205
    s_adc_clk <= reduced_clk  when '1',
206
                 same_clk      when others;
207
 
208
  adc_clk_O <= s_adc_clk;
209
 
210 23 budinero
  --------------------------------------------------------------------------------------------------
211
  -- Generación ack
212 31 budinero
 
213
  -- When ADR_I(1) = '1', master will be accessing to confing register.
214
 
215 23 budinero
  ACK_O <= CYC_I and STB_I and (data_ack_ready or conf_ack_ready);
216
 
217 31 budinero
  data_ack_ready  <=  (read_flag_wb(conv_integer(channel_sel)) xnor read_flag_adc(conv_integer(channel_sel))) and not(WE_I);
218 23 budinero
 
219 31 budinero
  conf_ack_ready  <=  ADR_I(1);
220
 
221 23 budinero
  --------------------------------------------------------------------------------------------------
222 31 budinero
  -- Channel selection
223 23 budinero
 
224 31 budinero
  -- channel_data(0) --> Q channel
225
  -- channel_data(1) --> I channel (of ADC AD9201)
226 23 budinero
 
227 31 budinero
  channel_sel(0) <= ADR_I(0);
228
 
229
  P_dataread: process (s_adc_clk, adc_data_I)
230
  begin
231
    if s_adc_clk'event and s_adc_clk = '1' then
232
      channel_data(0) <= adc_data_I;
233
    end if;
234
    if s_adc_clk'event and s_adc_clk = '0' then
235
      channel_data(1) <= adc_data_I;
236
    end if;
237
  end process;
238
 
239
  P_flags: process (s_adc_clk, CLK_I, CYC_I, STB_I, ADR_I, read_flag_adc, read_flag_wb,channel_sel)
240
  begin
241
 
242
    if s_adc_clk'event and s_adc_clk = '1' then
243
      read_flag_adc(0) <= read_flag_wb(0);
244
    end if;
245
 
246
    if s_adc_clk'event and s_adc_clk = '0' then
247
      read_flag_adc(1) <= read_flag_wb(1);
248
    end if;
249
 
250
    if CLK_I'event and CLK_I = '1' then
251
      if RST_I = '1' then
252
        read_flag_wb <= (others => '0');
253
        --read_flag_adc <= (others => '1');
254
      elsif CYC_I = '1' and STB_I = '1' and ADR_I(1) = '0' then  -- read_flag(conv_integer(channel_sel)) = '0' and  
255
        read_flag_wb(conv_integer(channel_sel)) <= not(read_flag_adc(conv_integer(channel_sel)));
256
      end if;
257
    end if;
258
 
259
 
260
 
261
  end process;
262
 
263
  adc_sel_O <= s_adc_clk;
264
 
265 23 budinero
  --------------------------------------------------------------------------------------------------
266
  -- Lectura y escritura de datos
267
  ---- Generación de DAT_O
268
  DAT_O   <=  selector(conv_integer(ADR_I));
269
 
270
  ---- Almacenado de registro de configuración
271 31 budinero
  P_output: process (CLK_I, ADR_I, RST_I, DAT_I)
272 23 budinero
  begin
273
 
274
    if CLK_I'event and CLK_I = '1' then
275
      if RST_I = '1' then
276
        config <= DEFALT_CONFIG;
277
      elsif WE_I = '1' and  CYC_I = '1' and STB_I = '1' then
278 31 budinero
        if unsigned(ADR_I) = 2 then
279 23 budinero
          config <= DAT_I;
280
        end if;
281
      end if;
282
    end if;
283
 
284
  end process;
285
 
286
 
287 31 budinero
end architecture archdaq2;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.