Line 1... |
Line 1... |
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
--| Modular Oscilloscope
|
--| Modular Oscilloscope
|
--| UNSL - Argentina
|
--| UNSL - Argentina
|
--|
|
--|
|
--| File: daq.vhd
|
--| File: daq.vhd
|
--| Version: 0.1
|
--| Version: 0.40
|
--| Tested in: Actel A3PE1500
|
--| Tested in: Actel A3PE1500
|
|
--| Board: RVI Prototype Board + LP Data Conversion Daughter Board
|
--|-------------------------------------------------------------------------------------------------
|
--|-------------------------------------------------------------------------------------------------
|
--| Description:
|
--| Description:
|
--| Acquisition control module.
|
--| Acquisition control module.
|
--| It drives the ADC chip.
|
--| It drives the ADC chip.
|
--|-------------------------------------------------------------------------------------------------
|
--|-------------------------------------------------------------------------------------------------
|
--| File history:
|
--| File history:
|
--| 0.01 | apr-2008 | First testing
|
--| 0.01 | apr-2008 | First testing
|
--| 0.10 | apr-2009 | First release
|
--| 0.10 | apr-2009 | First release
|
|
--| 0.40 | jul-2009 | Added a read flag for each channel and adc_clk_I input
|
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
--| Copyright ® 2009, Facundo Aguilera.
|
--| Copyright ® 2009, Facundo Aguilera.
|
--|
|
--|
|
--| This VHDL design file is an open design; you can redistribute it and/or
|
--| This VHDL design file is an open design; you can redistribute it and/or
|
--| modify it and/or implement it after contacting the author.
|
--| modify it and/or implement it after contacting the author.
|
|
|
--| Wishbone Rev. B.3 compatible
|
--| Wishbone Rev. B.3 compatible
|
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
|
|
|
--==================================================================================================
|
|
-- TODO
|
|
-- · Access to both channels in consecutive reads
|
|
--==================================================================================================
|
|
|
--| TODO:
|
|
--| Access to both channels in consecutive reads
|
|
|
|
|
|
|
|
-- Esta primera versión está realizada específicamente para controlar el ADC AD9201. Otras
|
-- Esta primera versión está realizada específicamente para controlar el ADC AD9201. Otras
|
-- versiones podrán ser más genéricas.
|
-- versiones podrán ser más genéricas.
|
Line 47... |
Line 51... |
entity daq is
|
entity daq is
|
generic (
|
generic (
|
DEFALT_CONFIG : std_logic_vector := "0000100000000000"
|
DEFALT_CONFIG : std_logic_vector := "0000100000000000"
|
-- bits 8 a 0 clk_pre_scaler
|
-- bits 8 a 0 clk_pre_scaler
|
-- bits 9 clk_pre_scaler_ena
|
-- bits 9 clk_pre_scaler_ena
|
-- bit 10 adc_sleep
|
-- bit 10 adc sleep
|
-- bit 11 adc_chip_sel
|
-- bit 11 adc_chip_sel
|
-- bits 12 a 15 sin usar
|
-- bits 12 a 15 sin usar
|
|
|
-- si clk_pre_scaler_ena = 1
|
-- si clk_pre_scaler_ena = 1
|
-- frecuencia_adc = frecuencia_wbn / ((clk_pre_scaler+1)*2)
|
-- frecuencia_adc = frecuencia_wbn / ((clk_pre_scaler+1)*2)
|
-- sino frecuencia_adc = frecuencia_wbn
|
-- sino frecuencia_adc = frecuencia_wbn
|
);
|
);
|
port(
|
port(
|
-- Externo
|
-- Externo
|
adc_data: in std_logic_vector (9 downto 0);
|
adc_data_I: in std_logic_vector (9 downto 0);
|
adc_sel: out std_logic;
|
adc_sel_O: out std_logic;
|
adc_clk: out std_logic;
|
adc_clk_O: out std_logic;
|
adc_sleep: out std_logic;
|
adc_sleep_O: out std_logic;
|
adc_chip_sel: out std_logic;
|
adc_chip_sel_O: out std_logic;
|
|
|
|
|
-- Interno
|
-- Interno
|
RST_I: in std_logic;
|
RST_I: in std_logic;
|
CLK_I: in std_logic;
|
CLK_I: in std_logic;
|
Line 73... |
Line 77... |
ADR_I: in std_logic_vector (1 downto 0);
|
ADR_I: in std_logic_vector (1 downto 0);
|
CYC_I: in std_logic;
|
CYC_I: in std_logic;
|
STB_I: in std_logic;
|
STB_I: in std_logic;
|
WE_I: in std_logic;
|
WE_I: in std_logic;
|
DAT_O: out std_logic_vector (15 downto 0);
|
DAT_O: out std_logic_vector (15 downto 0);
|
ACK_O: out std_logic
|
ACK_O: out std_logic;
|
|
|
|
adc_clk_I: std_logic
|
);
|
);
|
end daq;
|
end daq;
|
|
|
|
|
architecture beh1 of daq is
|
architecture archdaq2 of daq is
|
-- Tipos
|
-- Tipos
|
type data_array is array(0 to 2) of std_logic_vector(15 downto 0);
|
type config_array is array(0 to 2) of std_logic_vector(15 downto 0);
|
|
|
|
|
-- type arr is array(0 to 3) of std_logic_vector(15 downto 0);
|
-- type arr is array(0 to 3) of std_logic_vector(15 downto 0);
|
--
|
--
|
-- signal arr_a : arr;
|
-- signal arr_a : arr;
|
Line 92... |
Line 98... |
-- ....
|
-- ....
|
-- arr_a(0) <= vec_0;
|
-- arr_a(0) <= vec_0;
|
-- arr_a(1) <= vec_1;
|
-- arr_a(1) <= vec_1;
|
-- ....
|
-- ....
|
|
|
-- Registros de configuración
|
type data_array is array(0 to 1) of std_logic_vector(adc_data_I'length - 1 downto 0);
|
|
|
|
|
|
|
|
-- Registers
|
signal config: std_logic_vector (15 downto 0);
|
signal config: std_logic_vector (15 downto 0);
|
signal selector: data_array;
|
signal count: std_logic_vector (8 downto 0);
|
|
signal channel_data: data_array;
|
|
signal read_flag_adc: std_logic_vector (1 downto 0);
|
|
signal read_flag_wb: std_logic_vector (1 downto 0);
|
|
-- The biggest limit must be the channels number (-1)
|
|
-- There are two clocks becouse there are two clocks
|
|
|
-- Registros
|
-- Signals
|
signal count: std_logic_vector (9 downto 0);
|
signal selector: config_array;
|
|
|
-- Señales
|
signal s_adc_clk, s_adc_sleep, s_adc_chip_sel: std_logic; -- previous to outputs
|
signal s_adc_clk, s_adc_sleep, s_adc_chip_sel: std_logic;
|
signal reduced_clk, same_clk: std_logic;
|
signal data_ack_ready: std_logic; -- habilita confirmación de datos
|
signal data_ack_ready: std_logic; -- habilita confirmación de datos
|
signal conf_ack_ready: std_logic; -- habilita confirmación de escritura de configuración
|
signal conf_ack_ready: std_logic; -- habilita confirmación de escritura de configuración
|
signal clk_pre_scaler: std_logic_vector (8 downto 0);
|
signal clk_pre_scaler: std_logic_vector (8 downto 0);
|
signal clk_pre_scaler_ena: std_logic;
|
signal clk_pre_scaler_ena: std_logic;
|
|
signal channel_sel: std_logic_vector(0 downto 0); -- max limit must be the number of channels
|
|
signal count_reset: std_logic;
|
|
signal count_max: std_logic;
|
--signal clk_enable: std_logic_vector (9 downto 0);
|
--signal clk_enable: std_logic_vector (9 downto 0);
|
|
|
begin
|
begin
|
--------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------
|
-- Asignaciones
|
-- Asignaciones
|
---- Comunicación interna (Wishbone)
|
---- Internal
|
selector(0) <= config;
|
selector(0) <= (config'length - 1 downto adc_data_I'length => '0' ) &
|
selector(1) <= (config'length - 1 downto adc_data'length => '0' ) & adc_data;
|
channel_data(conv_integer(channel_sel));
|
selector(2) <= (config'length - 1 downto adc_data'length => '0' ) & adc_data;
|
selector(1) <= (config'length - 1 downto adc_data_I'length => '0' ) &
|
--selector(3) <= (others => '0' ); -- Sin usar
|
channel_data(conv_integer(channel_sel));
|
|
selector(2) <= config;
|
|
--selector(3) <= (others => '0' ); -- Unassigned
|
|
|
|
|
|
|
---- Registro de configuración config
|
---- Config register
|
clk_pre_scaler <= config(8 downto 0);
|
clk_pre_scaler <= config(8 downto 0);
|
clk_pre_scaler_ena <= config(9);
|
clk_pre_scaler_ena <= config(9);
|
s_adc_sleep <= config(10);
|
s_adc_sleep <= config(10);
|
s_adc_chip_sel <= config(11);
|
s_adc_chip_sel <= config(11);
|
-- sin asignar <= config(13); para usar en otras implementaciones
|
-- Unassigned <= config(13);
|
-- sin asignar <= config(14);
|
-- Unassigned <= config(14);
|
-- sin asignar <= config(15);
|
-- Unassigned <= config(15);
|
|
|
---- Comunicación externa (AD)
|
---- External communication (AD)
|
adc_sleep <= s_adc_sleep;
|
adc_sleep_O <= s_adc_sleep;
|
adc_chip_sel <= s_adc_chip_sel;
|
adc_chip_sel_O <= s_adc_chip_sel;
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------
|
-- Generación de adc_clk
|
-- Generación de adc_clk_O
|
process (CLK_I, clk_pre_scaler,RST_I,count, clk_pre_scaler_ena)
|
count_max <= '1' when count >= clk_pre_scaler else '0';
|
|
count_reset <= RST_I or count_max or not(clk_pre_scaler_ena);
|
|
|
|
P_count: process (adc_clk_I, count, count_reset)
|
begin
|
begin
|
if RST_I = '1' then
|
if adc_clk_I'event and adc_clk_I = '1' then
|
|
if count_reset = '1' then
|
count <= (others => '0');
|
count <= (others => '0');
|
s_adc_clk <= '0';
|
else
|
elsif clk_pre_scaler_ena = '1' then
|
|
if CLK_I'event and CLK_I = '1' then
|
|
count <= count + 1;
|
count <= count + 1;
|
if count = clk_pre_scaler then
|
|
s_adc_clk <= not(s_adc_clk);
|
|
count <= (others => '0');
|
|
end if;
|
end if;
|
end if;
|
end if;
|
else
|
end process;
|
count <= (others => '0');
|
|
s_adc_clk <= CLK_I;
|
P_adcclk: process (adc_clk_I, RST_I, clk_pre_scaler_ena)
|
|
begin
|
|
if adc_clk_I'event and adc_clk_I = '1' then
|
|
if RST_I = '1' or clk_pre_scaler_ena = '0' then
|
|
reduced_clk <= '0';
|
|
elsif count_max = '1' then
|
|
reduced_clk <= not(reduced_clk);
|
|
end if;
|
end if;
|
end if;
|
|
-- OLD
|
|
-- if RST_I = '1' then
|
|
-- count <= (others => '0');
|
|
-- s_adc_clk <= '0';
|
|
-- elsif clk_pre_scaler_ena = '1' then
|
|
-- if CLK_I'event and CLK_I = '1' then
|
|
-- count <= count + 1;
|
|
-- if count = clk_pre_scaler then
|
|
-- s_adc_clk <= not(s_adc_clk);
|
|
-- count <= (others => '0');
|
|
-- end if;
|
|
-- end if;
|
|
-- else
|
|
-- count <= (others => '0');
|
|
-- s_adc_clk <= CLK_I;
|
|
-- end if;
|
end process;
|
end process;
|
adc_clk <= s_adc_clk;
|
same_clk <= adc_clk_I;
|
|
|
|
with clk_pre_scaler_ena select
|
|
s_adc_clk <= reduced_clk when '1',
|
|
same_clk when others;
|
|
|
|
adc_clk_O <= s_adc_clk;
|
|
|
--------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------
|
-- Generación ack
|
-- Generación ack
|
|
|
|
-- When ADR_I(1) = '1', master will be accessing to confing register.
|
|
|
ACK_O <= CYC_I and STB_I and (data_ack_ready or conf_ack_ready);
|
ACK_O <= CYC_I and STB_I and (data_ack_ready or conf_ack_ready);
|
data_ack_ready <= '1' when (unsigned(count) = 0 and WE_I = '0' and unsigned(ADR_I) /= 0 and s_adc_clk = '1')
|
|
or (clk_pre_scaler_ena /= '1')
|
|
else
|
|
'0';
|
|
-- count = 0 asegura que el dato actual ya fue leído
|
|
|
|
conf_ack_ready <= '1' when unsigned(ADR_I) = 0 else
|
data_ack_ready <= (read_flag_wb(conv_integer(channel_sel)) xnor read_flag_adc(conv_integer(channel_sel))) and not(WE_I);
|
'0';
|
|
|
conf_ack_ready <= ADR_I(1);
|
|
|
--------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------
|
-- Selección de canal
|
-- Channel selection
|
adc_sel <= '1' when unsigned(ADR_I) = 2 else -- selecciona canal Q
|
|
'0'; -- selecciona canal I
|
-- channel_data(0) --> Q channel
|
|
-- channel_data(1) --> I channel (of ADC AD9201)
|
|
|
|
channel_sel(0) <= ADR_I(0);
|
|
|
|
P_dataread: process (s_adc_clk, adc_data_I)
|
|
begin
|
|
if s_adc_clk'event and s_adc_clk = '1' then
|
|
channel_data(0) <= adc_data_I;
|
|
end if;
|
|
if s_adc_clk'event and s_adc_clk = '0' then
|
|
channel_data(1) <= adc_data_I;
|
|
end if;
|
|
end process;
|
|
|
|
P_flags: process (s_adc_clk, CLK_I, CYC_I, STB_I, ADR_I, read_flag_adc, read_flag_wb,channel_sel)
|
|
begin
|
|
|
|
if s_adc_clk'event and s_adc_clk = '1' then
|
|
read_flag_adc(0) <= read_flag_wb(0);
|
|
end if;
|
|
|
|
if s_adc_clk'event and s_adc_clk = '0' then
|
|
read_flag_adc(1) <= read_flag_wb(1);
|
|
end if;
|
|
|
|
if CLK_I'event and CLK_I = '1' then
|
|
if RST_I = '1' then
|
|
read_flag_wb <= (others => '0');
|
|
--read_flag_adc <= (others => '1');
|
|
elsif CYC_I = '1' and STB_I = '1' and ADR_I(1) = '0' then -- read_flag(conv_integer(channel_sel)) = '0' and
|
|
read_flag_wb(conv_integer(channel_sel)) <= not(read_flag_adc(conv_integer(channel_sel)));
|
|
end if;
|
|
end if;
|
|
|
|
|
|
|
|
end process;
|
|
|
|
adc_sel_O <= s_adc_clk;
|
|
|
--------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------
|
-- Lectura y escritura de datos
|
-- Lectura y escritura de datos
|
---- Generación de DAT_O
|
---- Generación de DAT_O
|
DAT_O <= selector(conv_integer(ADR_I));
|
DAT_O <= selector(conv_integer(ADR_I));
|
|
|
---- Almacenado de registro de configuración
|
---- Almacenado de registro de configuración
|
process (CLK_I, ADR_I, RST_I, DAT_I)
|
P_output: process (CLK_I, ADR_I, RST_I, DAT_I)
|
begin
|
begin
|
|
|
if CLK_I'event and CLK_I = '1' then
|
if CLK_I'event and CLK_I = '1' then
|
if RST_I = '1' then
|
if RST_I = '1' then
|
config <= DEFALT_CONFIG;
|
config <= DEFALT_CONFIG;
|
elsif WE_I = '1' and CYC_I = '1' and STB_I = '1' then
|
elsif WE_I = '1' and CYC_I = '1' and STB_I = '1' then
|
if unsigned(ADR_I) = 0 then
|
if unsigned(ADR_I) = 2 then
|
config <= DAT_I;
|
config <= DAT_I;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
end process;
|
end process;
|
|
|
|
|
end architecture beh1;
|
|
No newline at end of file
|
No newline at end of file
|
|
end architecture archdaq2;
|
No newline at end of file
|
No newline at end of file
|