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

Subversion Repositories modular_oscilloscope

[/] [modular_oscilloscope/] [trunk/] [hdl/] [ctrl/] [memory_writer.vhd] - Blame information for rev 48

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

Line No. Rev Author Line
1 32 budinero
-------------------------------------------------------------------------------------------------100
2
--| Modular Oscilloscope
3
--| UNSL - Argentine
4
--|
5 37 budinero
--| File: ctrl_memory_writer.vhd
6 32 budinero
--| Version: 0.1
7
--| Tested in: Actel A3PE1500
8
--|-------------------------------------------------------------------------------------------------
9
--| Description:
10
--|   CONTROL - Memory writer
11
--|   Read data and write it in a memory (it's a simple wishbone bridge)
12
--|   
13
--|-------------------------------------------------------------------------------------------------
14
--| File history:
15
--|   0.1   | jul-2009 | First release
16 48 budinero
--|   0.12  | aug-2009 | Disable strobe output when enable = '0'
17
--|   0.13  | aug-2009 | End in 0 when continuous (better integration)
18 32 budinero
----------------------------------------------------------------------------------------------------
19 33 budinero
--| Copyright © 2009, Facundo Aguilera.
20 32 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
 
25
 
26
--==================================================================================================
27
-- TODO
28 48 budinero
-- · Test new enable function (for stb and cyc)
29
-- · Clean!
30 32 budinero
--==================================================================================================
31
 
32
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
use IEEE.STD_LOGIC_UNSIGNED.ALL;
36
use IEEE.NUMERIC_STD.ALL;
37
 
38 48 budinero
use work.ctrl_pkg.all;
39 32 budinero
 
40
----------------------------------------------------------------------------------------------------
41
----------------------------------------------------------------------------------------------------
42 37 budinero
entity ctrl_memory_writer is
43 32 budinero
  generic(
44
    MEM_ADD_WIDTH: integer :=  14
45
  );
46
  port(
47
    ------------------------------------------------------------------------------------------------
48
    -- to memory
49
    DAT_O_mem: out std_logic_vector (15 downto 0);
50
    ADR_O_mem: out std_logic_vector (MEM_ADD_WIDTH - 1  downto 0);
51
    CYC_O_mem: out std_logic;
52
    STB_O_mem: out std_logic;
53
    ACK_I_mem: in std_logic ;
54
    WE_O_mem:  out std_logic;
55
 
56
    ------------------------------------------------------------------------------------------------
57
    -- to acquistion module
58
    DAT_I_adc: in std_logic_vector (15 downto 0);
59
    -- Using an address generator, commented
60
    -- ADR_O_adc: out std_logic_vector (ADC_ADD_WIDTH - 1  downto 0); 
61
    CYC_O_adc: out std_logic;
62
    STB_O_adc: out std_logic;
63
    ACK_I_adc: in std_logic ;
64 48 budinero
    --WE_O_adc:  out std_logic;
65 32 budinero
 
66
    ------------------------------------------------------------------------------------------------
67
    -- Common signals 
68
    RST_I: in std_logic;
69
    CLK_I: in std_logic;
70
 
71
    ------------------------------------------------------------------------------------------------
72
    -- Internal
73 37 budinero
    -- reset memory address to 0
74 32 budinero
    reset_I:            in std_logic;
75
    -- read in clk edge from the actual address ('0' means pause, '1' means continue)
76
    enable_I:           in std_logic;
77
    final_address_I:    in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
78
    -- it is set when communication ends and remains until next restart or actual address change
79
    finished_O:         out std_logic;
80 37 budinero
    -- when counter finishes, restart
81 48 budinero
    continuous_I:       in  std_logic
82 32 budinero
  );
83 37 budinero
end entity ctrl_memory_writer;
84 32 budinero
 
85
 
86
----------------------------------------------------------------------------------------------------
87
----------------------------------------------------------------------------------------------------
88 48 budinero
architecture ARCH12 of ctrl_memory_writer is
89 32 budinero
 
90
  type DataStatusType is (
91 48 budinero
          FINISHED,
92 32 budinero
          INIT,
93
          WORKING
94
          );
95
 
96 48 budinero
  signal data_status: DataStatusType;
97 32 budinero
 
98
  signal count: std_logic_vector(MEM_ADD_WIDTH-1  downto 0);
99
  signal enable_count:std_logic;
100
  signal reset_count: std_logic;
101
  signal data: std_logic_vector(15 downto 0);
102
 
103
  signal s_finished, s_STB_adc, s_STB_mem: std_logic; -- previous to outputs
104
 
105
begin
106
  --------------------------------------------------------------------------------------------------
107 37 budinero
  -- Instances
108 32 budinero
  U_COUNTER0: generic_counter
109
  generic map(
110
    OUTPUT_WIDTH => MEM_ADD_WIDTH -- Output width for counter.
111
  )
112
  port map(
113
    clk_I => CLK_I,
114
    count_O => count,
115
    reset_I => reset_count,
116
    enable_I => enable_count
117
  );
118
 
119
 
120
  --------------------------------------------------------------------------------------------------
121
  -- Combinational
122
 
123
  -- counter
124 48 budinero
  s_finished <= '1' when count >= final_address_I else '0';
125 32 budinero
  enable_count <= '1' when enable_I = '1' and
126
                           data_status = WORKING  and
127
                           s_STB_mem = '1' and
128 48 budinero
                           ACK_I_mem = '1'
129 32 budinero
                      else
130
                  '0';
131 48 budinero
  reset_count <= '1' when reset_I = '1' or s_finished = '1'  else
132 32 budinero
                 '0';
133
 
134
  -- outputs
135
  finished_O <= s_finished;
136 48 budinero
  STB_O_adc <= s_STB_adc and enable_I;  -- !
137
  STB_O_mem <= s_STB_mem and enable_I;  -- !
138 32 budinero
  DAT_O_mem <= data;
139
  ADR_O_mem <= count;
140 48 budinero
  --WE_O_adc <= '0';
141
  WE_O_mem <= '1';
142 32 budinero
 
143
  --------------------------------------------------------------------------------------------------
144
  -- Clocked
145
 
146
 
147
  -- Lock interface when working
148 48 budinero
  P_cyc_signals: process (CLK_I, enable_I, reset_I)
149 32 budinero
  begin
150
    if CLK_I'event and CLK_I = '1' then
151 37 budinero
      if enable_I = '0' or reset_I = '1' then
152 32 budinero
        CYC_O_adc <= '0';   CYC_O_mem <= '0';
153
      else
154
        CYC_O_adc <= '1';  CYC_O_mem <= '1';
155
      end if;
156
    end if;
157
  end process;
158
 
159
 
160
  P_stb_signals: process (CLK_I, reset_I, data_status, s_STB_adc, s_STB_mem, ACK_I_adc, ACK_I_mem)
161
  begin
162
 
163
    if CLK_I'event and CLK_I = '1' then
164 48 budinero
      if reset_I = '1' or RST_I = '1' then
165 32 budinero
        data_status <= INIT;
166
        s_STB_adc <= '0';
167
        s_STB_mem <= '0';
168
        data <= (others => '0');
169
      elsif enable_I = '1' then
170 48 budinero
        case data_status is
171
          when INIT =>
172
            -- this state is only necessary when there are adc convertions in every clock
173
            -- (for the first convertion)
174
            s_STB_adc <= '1';
175
            s_STB_mem <= '1';
176
            data_status <= WORKING;
177 32 budinero
 
178 48 budinero
          when WORKING =>
179
            if s_STB_adc = '1' and ACK_I_adc = '1' then
180
              s_STB_mem <= '1'; -- strobe when adc ack
181
              data <= DAT_I_adc; -- save data
182
            elsif s_STB_mem = '1' and ACK_I_mem = '1' then
183
              s_STB_mem <= '0';
184
            end if;
185
 
186
            if s_STB_mem = '1' and ACK_I_mem = '1' then
187
              s_STB_adc <= '1'; -- strobe when mem ack
188
            elsif s_STB_adc = '1' and ACK_I_adc = '1' then
189
              s_STB_adc <= '0';
190
            end if;
191 32 budinero
 
192 48 budinero
            if continuous_I = '0' and s_finished = '1' then
193
              data_status <= FINISHED;
194
            end if;
195
 
196
          when others => -- FINISHED
197 32 budinero
            s_STB_adc <= '0';
198 48 budinero
            s_STB_mem <= '0';
199 32 budinero
 
200 48 budinero
        end case;
201 32 budinero
      end if;
202 48 budinero
    end if;
203 32 budinero
 
204
  end process;
205
 
206
 
207 48 budinero
 
208
 
209
 
210 32 budinero
end architecture;

powered by: WebSVN 2.1.0

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