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 23

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 budinero
----------------------------------------------------------------------------------------------------
2
--| Modular Oscilloscope
3
--| UNSL - Argentina
4
--|
5
--| File: adq.vhd
6
--| Version: 0.1
7
--| Tested in: Actel A3PE1500
8
--|-------------------------------------------------------------------------------------------------
9
--| Description:
10
--|   Adquisition control module. 
11
--|   It drives the ADC chips.
12
--|-------------------------------------------------------------------------------------------------
13
--| File history:
14
--|   0.01   | apr-2008 | First testing
15
--|   0.10   | apr-2009 | First release
16
----------------------------------------------------------------------------------------------------
17
--| Copyright ® 2009, Facundo Aguilera.
18
--|
19
--| This VHDL design file is an open design; you can redistribute it and/or
20
--| modify it and/or implement it after contacting the author.
21
 
22
--| Wishbone Rev. B.3 compatible
23
----------------------------------------------------------------------------------------------------
24
 
25
 
26
--| TODO:
27
--|  Access to both channels in consecutive reads  
28
 
29
 
30
 
31
-- Esta primera versión está realizada específicamente para controlar el ADC AD9201. Otras
32
-- versiones podrán ser más genéricas.
33
 
34
 
35
-- ADR    configuración (señal config)
36
-- ADR+1  datos canal 1
37
-- ADR+2  datos canal 2
38
-- ADR+3  sin usar
39
 
40
library IEEE;
41
use IEEE.STD_LOGIC_1164.all;
42
use IEEE.STD_LOGIC_UNSIGNED.ALL;
43
--use IEEE.STD_LOGIC_ARITH.all;
44
use IEEE.NUMERIC_STD.ALL;
45
--use work.adq_pgk.all;
46
 
47
entity adq is
48
  generic (
49
    DEFALT_CONFIG : std_logic_vector := "0000100000000000"
50
                                      -- bits 8 a 0       clk_pre_scaler
51
                                      -- bits 9           clk_pre_scaler_ena
52
                                      -- bit 10           adc_sleep
53
                                      -- bit 11           adc_chip_sel
54
                                      -- bits 12 a 15     sin usar
55
 
56
                                      -- si clk_pre_scaler_ena = 1
57
                                      -- frecuencia_adc = frecuencia_wbn / ((clk_pre_scaler+1)*2)
58
                                      -- sino frecuencia_adc = frecuencia_wbn
59
  );
60
  port(
61
    -- Externo
62
    adc_data:     in    std_logic_vector (9 downto 0);
63
    adc_sel:      out   std_logic;
64
    adc_clk:      out   std_logic;
65
    adc_sleep:    out   std_logic;
66
    adc_chip_sel: out   std_logic;
67
 
68
 
69
    --  Interno
70
    RST_I:  in  std_logic;
71
    CLK_I:  in  std_logic;
72
    DAT_I:  in  std_logic_vector (15 downto 0);
73
    ADR_I:  in  std_logic_vector (1 downto 0);
74
    CYC_I:  in  std_logic;
75
    STB_I:  in  std_logic;
76
    WE_I:   in  std_logic;
77
    DAT_O:  out std_logic_vector (15 downto 0);
78
    ACK_O:  out std_logic
79
  );
80
end adq;
81
 
82
 
83
architecture beh1 of adq is
84
  -- Tipos
85
  type data_array is array(0 to 2) of std_logic_vector(15 downto 0);
86
 
87
 
88
                --   type arr is array(0 to 3) of std_logic_vector(15 downto 0);
89
                -- 
90
                -- signal arr_a : arr;
91
                -- signal vec_0, vec_1, vec_2, vec_3 : std_logic vector(15 downto 0);
92
                -- ....
93
                -- arr_a(0) <= vec_0;
94
                -- arr_a(1) <= vec_1;
95
                -- ....
96
 
97
  -- Registros de configuración
98
  signal config:   std_logic_vector (15 downto 0);
99
  signal selector: data_array;
100
 
101
  -- Registros
102
  signal count: std_logic_vector (9 downto 0);
103
 
104
  -- Señales 
105
  signal s_adc_clk, s_adc_sleep, s_adc_chip_sel: std_logic;
106
  signal data_ack_ready:      std_logic; -- habilita confirmación de datos
107
  signal conf_ack_ready:      std_logic; -- habilita confirmación de escritura de configuración
108
  signal clk_pre_scaler:      std_logic_vector (8 downto 0);
109
  signal clk_pre_scaler_ena:  std_logic;
110
  --signal clk_enable: std_logic_vector (9 downto 0);
111
 
112
begin
113
  --------------------------------------------------------------------------------------------------
114
  -- Asignaciones
115
  ---- Comunicación interna (Wishbone)
116
  selector(0) <= config;
117
  selector(1) <= (config'length - 1 downto adc_data'length => '0' ) & adc_data;
118
  selector(2) <= (config'length - 1 downto adc_data'length => '0' ) & adc_data;
119
  --selector(3) <= (others => '0' ); -- Sin usar
120
 
121
  ---- Registro de configuración config
122
  clk_pre_scaler <= config(8 downto 0);
123
  clk_pre_scaler_ena <= config(9);
124
  s_adc_sleep <= config(10);
125
  s_adc_chip_sel <= config(11);
126
  -- sin asignar <= config(13); para usar en otras implementaciones
127
  -- sin asignar <= config(14);
128
  -- sin asignar <= config(15);
129
 
130
  ---- Comunicación externa (AD)
131
  adc_sleep <= s_adc_sleep;
132
  adc_chip_sel <= s_adc_chip_sel;
133
 
134
 
135
 
136
  --------------------------------------------------------------------------------------------------
137
  -- Generación de adc_clk
138
  process (CLK_I, clk_pre_scaler,RST_I,count, clk_pre_scaler_ena)
139
  begin
140
    if RST_I = '1' then
141
      count <= (others => '0');
142
      s_adc_clk <= '0';
143
    elsif clk_pre_scaler_ena = '1' then
144
      if CLK_I'event and CLK_I = '1' then
145
        count <= count + 1;
146
        if count = clk_pre_scaler  then
147
          s_adc_clk <= not(s_adc_clk);
148
          count <= (others => '0');
149
        end if;
150
      end if;
151
    else
152
      count <= (others => '0');
153
      s_adc_clk <= CLK_I;
154
    end if;
155
  end process;
156
  adc_clk <= s_adc_clk;
157
 
158
  --------------------------------------------------------------------------------------------------
159
  -- Generación ack
160
  ACK_O <= CYC_I and STB_I and (data_ack_ready or conf_ack_ready);
161
  data_ack_ready  <=  '1' when (unsigned(count) = 0 and WE_I = '0' and unsigned(ADR_I) /= 0 and s_adc_clk = '1')
162
                      or (clk_pre_scaler_ena /= '1')
163
                  else
164
                      '0';
165
    -- count = 0 asegura que el dato actual ya fue leído
166
 
167
  conf_ack_ready  <=  '1' when unsigned(ADR_I) = 0  else
168
                      '0';
169
 
170
  --------------------------------------------------------------------------------------------------
171
  -- Selección de canal
172
  adc_sel <=  '1' when unsigned(ADR_I) = 2 else   -- selecciona canal Q
173
              '0';                                -- selecciona canal I
174
 
175
 
176
  --------------------------------------------------------------------------------------------------
177
  -- Lectura y escritura de datos
178
  ---- Generación de DAT_O
179
  DAT_O   <=  selector(conv_integer(ADR_I));
180
 
181
  ---- Almacenado de registro de configuración
182
  process (CLK_I, ADR_I, RST_I, DAT_I)
183
  begin
184
 
185
    if CLK_I'event and CLK_I = '1' then
186
      if RST_I = '1' then
187
        config <= DEFALT_CONFIG;
188
      elsif WE_I = '1' and  CYC_I = '1' and STB_I = '1' then
189
        if unsigned(ADR_I) = 0 then
190
          config <= DAT_I;
191
        end if;
192
      end if;
193
    end if;
194
 
195
  end process;
196
 
197
 
198
end architecture beh1;

powered by: WebSVN 2.1.0

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