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

Subversion Repositories modular_oscilloscope

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

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

Line No. Rev Author Line
1 38 budinero
-------------------------------------------------------------------------------------------------100
2
--| Modular Oscilloscope
3
--| UNSL - Argentine
4
--|
5
--| File: ctrl.vhd
6
--| Version: 0.1
7
--| Tested in: Actel A3PE1500
8
--|   Board: RVI Prototype Board + LP Data Conversion Daughter Board
9
--|-------------------------------------------------------------------------------------------------
10
--| Description:
11
--|   CONTROL - Control system
12
--|   This is the tom modules in the folder.
13
--|   
14
--|-------------------------------------------------------------------------------------------------
15
--| File history:
16
--|   0.1   | aug-2009 | First testing
17
----------------------------------------------------------------------------------------------------
18 48 budinero
--| Copyright © 2009, Facundo Aguilera (budinero at gmail.com).
19 38 budinero
--|
20
--| This VHDL design file is an open design; you can redistribute it and/or
21
--| modify it and/or implement it after contacting the author.
22
----------------------------------------------------------------------------------------------------
23
 
24
 
25
--==================================================================================================
26
-- TO DO
27 57 budinero
-- · 
28 38 budinero
--==================================================================================================
29
library IEEE;
30
use IEEE.STD_LOGIC_1164.ALL;
31 48 budinero
use IEEE.STD_LOGIC_UNSIGNED.ALL;
32 38 budinero
use ieee.math_real.all;
33
 
34
use work.ctrl_pkg.all;
35
 
36
entity ctrl is
37
  port(
38
    ------------------------------------------------------------------------------------------------
39
    -- From port
40
    DAT_I_port: in  std_logic_vector (15 downto 0);
41
    DAT_O_port: out std_logic_vector (15 downto 0);
42
    ADR_I_port: in  std_logic_vector (3 downto 0);
43
    CYC_I_port: in  std_logic;
44
    STB_I_port: in  std_logic;
45
    ACK_O_port: out std_logic ;
46
    WE_I_port:  in  std_logic;
47
    CLK_I_port: in std_logic;
48
    RST_I_port: in std_logic;
49
 
50
    ------------------------------------------------------------------------------------------------
51
    -- To ADC
52
    DAT_I_daq: in  std_logic_vector (15 downto 0);
53
    DAT_O_daq: out std_logic_vector (15 downto 0);
54 48 budinero
    ADR_O_daq: out std_logic_vector (1 downto 0);
55 38 budinero
    CYC_O_daq: out std_logic;
56
    STB_O_daq: out std_logic;
57
    ACK_I_daq: in  std_logic ;
58
    WE_O_daq:  out std_logic;
59
 
60
    CLK_I_daq: in std_logic;
61
    RST_I_daq: in std_logic;
62
 
63
    ------------------------------------------------------------------------------------------------
64
    -- To memory, A (writing) interface (Higer prioriry)
65
    --DAT_I_memw: in  std_logic_vector (15 downto 0);
66
    DAT_O_memw: out std_logic_vector (15 downto 0);
67
    ADR_O_memw: out  std_logic_vector (13 downto 0);
68
    CYC_O_memw: out  std_logic;
69
    STB_O_memw: out  std_logic;
70
    ACK_I_memw: in std_logic ;
71
    WE_O_memw:  out  std_logic;
72
 
73
    ------------------------------------------------------------------------------------------------
74
    -- To memory, B (reading) interface
75
    DAT_I_memr: in  std_logic_vector (15 downto 0);
76
    --DAT_O_memr: out std_logic_vector (15 downto 0);
77
    ADR_O_memr: out  std_logic_vector (13 downto 0);
78
    CYC_O_memr: out  std_logic;
79
    STB_O_memr: out  std_logic;
80
    ACK_I_memr: in std_logic ;
81
    WE_O_memr:  out  std_logic
82
 
83
  );
84
end entity ctrl;
85
 
86
 
87
 
88
architecture WSM of ctrl is
89 48 budinero
  -- machine
90 38 budinero
  type StateType is (
91
          ST_IDLE,
92
          ST_INIT,
93 48 budinero
          ST_RUNNING,
94
          ST_ADCWRITE_INIT,
95
          ST_ADCWRITE
96 38 budinero
          );
97
  signal next_state, present_state: StateType;
98
 
99
 
100
  -- trigger
101
  signal trigger_reset:           std_logic;
102
  signal trigger_en:              std_logic;
103 48 budinero
  signal trigger_out_adr:         std_logic_vector(13 downto 0);
104
  signal trigger_act:              std_logic;
105 38 budinero
  signal reg_trigger_en:          std_logic;
106
  signal reg_trigger_edge:        std_logic;
107
  signal reg_trigger_level:       std_logic_vector(9 downto 0);
108
  signal reg_trigger_offset:      std_logic_vector(14 downto 0);
109 48 budinero
  signal reg_trigger_channel:     std_logic_vector(0 downto 0);
110 38 budinero
 
111
  -- channels
112
  signal reg_channels_selection:  std_logic_vector(1 downto 0);
113
  signal chsel_first_channel:     std_logic;
114 48 budinero
  signal chsel_channel:           std_logic_vector(0 downto 0);
115 38 budinero
  signal chsel_reset:             std_logic;
116 48 budinero
  --signal chsel_en:                std_logic;
117 38 budinero
 
118
  -- address
119 48 budinero
  signal reg_buffer_size:         std_logic_vector(13 downto 0);
120 38 budinero
 
121
  -- skipper
122 48 budinero
  --signal dskip_en:         std_logic;
123
  signal dskip_reset:        std_logic;
124 38 budinero
  signal dskip_out_ack:      std_logic;
125 48 budinero
  signal reg_time_scale:     std_logic_vector(4 downto 0);
126
  signal reg_time_scale_en:  std_logic;
127 38 budinero
 
128
  -- Memory writer
129
  signal memwr_en:          std_logic;
130
  signal memwr_reset:       std_logic;
131 48 budinero
  --signal memwr_ack:         std_logic;
132
  --signal memwr_continuous:  std_logic;
133
  signal memwr_out_stb_daq: std_logic;
134
  signal memwr_in_ack_mem:  std_logic;
135 55 budinero
  signal memwr_out_cyc_daq: std_logic;
136 48 budinero
  signal memwr_out_adr:     std_logic_vector (13 downto 0);
137 38 budinero
  signal memwr_in_dat:      std_logic_vector (15 downto 0);
138 55 budinero
  signal memwr_out_dat:     std_logic_vector (15 downto 0);
139 38 budinero
 
140 48 budinero
  -- Outmgr
141
  --signal outmgr_reset:       std_logic;
142
  signal outmgr_en:          std_logic;
143
  signal outmgr_load:        std_logic;
144
  signal outmgr_initial_adr: std_logic_vector(13 downto 0);
145 38 budinero
  --signal outmgr_pause_adr:    std_logic; -- ??
146 48 budinero
  signal outmgr_finish:      std_logic;
147
  signal outmgr_in_cyc:      std_logic;
148
  signal outmgr_in_stb:      std_logic;
149
  signal outmgr_out_akc:     std_logic;
150
  signal outmgr_out_dat:     std_logic_vector(15 downto 0);
151 38 budinero
 
152 48 budinero
  --------------------------------------------------------------------------------------------------
153
  -- DAQ config
154
  signal dat_to_adc: std_logic_vector(15 downto 0);
155
  signal strobe_adc: std_logic;
156
  signal write_in_adc: std_logic;
157 38 budinero
 
158
 
159
  --------------------------------------------------------------------------------------------------
160
  -- Flags
161 56 budinero
  signal status: std_logic_vector(1 downto 0);
162
  signal next_status1: std_logic;
163 38 budinero
  signal stop: std_logic;
164
  signal start: std_logic;
165
  signal continuous: std_logic;
166 48 budinero
 
167
 
168 38 budinero
 
169
 
170
 
171
 
172
begin
173
  --------------------------------------------------------------------------------------------------
174
  -- Instances
175
 
176 57 budinero
  U_CTRL_OUTMGR0: ctrl_output_manager
177 38 budinero
  generic map(
178
      MEM_ADD_WIDTH => 14 --: integer :=  14
179
    )
180
    port map(
181
      -- MASTER (to memory) 
182
      DAT_I_mem => DAT_I_memr, -- direct
183
      ADR_O_mem => ADR_O_memr, -- direct
184
      CYC_O_mem => CYC_O_memr, -- direct
185
      STB_O_mem => STB_O_memr, -- direct
186
      ACK_I_mem => ACK_I_memr, -- direct
187
      WE_O_mem  => WE_O_memr, -- direct
188
      -- SLAVE (to I/O ports) 
189 48 budinero
      DAT_O_port => outmgr_out_dat,
190
      CYC_I_port => outmgr_in_cyc,
191
      STB_I_port => outmgr_in_stb,
192
      ACK_O_port => outmgr_out_akc,
193 38 budinero
      WE_I_port  => '0',
194
      -- Common signals 
195
      RST_I      => RST_I_port, -- direct
196
      CLK_I      => CLK_I_port, -- direct
197
      -- Internal
198
      load_I            => outmgr_load,
199
      enable_I          => outmgr_en,
200
      initial_address_I => outmgr_initial_adr,
201 48 budinero
      biggest_address_I => reg_buffer_size,
202
      pause_address_I   => memwr_out_adr,
203 38 budinero
      finish_O          => outmgr_finish
204
    );
205
 
206
  U_CTRL_MEMWR0: ctrl_memory_writer
207
    generic map(
208
      MEM_ADD_WIDTH => 14--: integer :=  14
209
    )
210
    port map(
211
      -- to memory
212 55 budinero
      DAT_O_mem => memwr_out_dat,  -- direct
213 48 budinero
      ADR_O_mem => memwr_out_adr,
214
      CYC_O_mem => CYC_O_memw,  -- direct
215
      STB_O_mem => STB_O_memw,  -- direct
216
      ACK_I_mem => memwr_in_ack_mem,  -- direct
217
      WE_O_mem  => WE_O_memw,   -- direct
218 38 budinero
      -- to acquistion module
219 48 budinero
      DAT_I_adc => memwr_in_dat,
220
      CYC_O_adc => memwr_out_cyc_daq,   -- direct
221
      STB_O_adc => memwr_out_stb_daq,   -- direct
222
      ACK_I_adc => dskip_out_ack,
223 38 budinero
      -- Common signals 
224 48 budinero
      RST_I => RST_I_daq,       -- direct
225
      CLK_I => CLK_I_daq,       -- direct
226 38 budinero
      -- Internal
227
      reset_I         => memwr_reset,
228
      enable_I        => memwr_en,
229 48 budinero
      final_address_I => reg_buffer_size,
230
      finished_O      => open,            -- !
231
      continuous_I    => reg_trigger_en
232 38 budinero
    );
233
 
234
 
235
  U_CTRL_DSKIP0: ctrl_data_skipper
236
    generic map(
237 48 budinero
      SELECTOR_WIDTH    => 5--: integer := 5 
238 38 budinero
    )
239
    port map(
240
      ack_O             => dskip_out_ack,
241 48 budinero
      ack_I             => ACK_I_daq, -- direct
242
      stb_I             => memwr_out_stb_daq,
243 38 budinero
      selector_I        => reg_time_scale,
244
      enable_skipper_I  => reg_time_scale_en,
245 48 budinero
      reset_I           => dskip_reset,
246
      clk_I             => CLK_I_daq, -- direct
247 38 budinero
      first_channel_I   => chsel_first_channel
248
    );
249
 
250
 
251
  U_CTRL_CHSEL0: ctrl_channel_selector
252
    generic map(
253 48 budinero
      CHANNEL_WIDTH     => 1 -- number of channels 2**CHANNEL_WIDTH, max. 4 
254 38 budinero
    )
255
    port map(
256
      channels_I        => reg_channels_selection,
257
      channel_number_O  => chsel_channel,
258
      first_channel_O   => chsel_first_channel,
259
      clk_I             => CLK_I_daq,
260 48 budinero
      enable_I          => '1',
261 38 budinero
      reset_I           => chsel_reset
262
    );
263
 
264
 
265
  U_CTRL_TRIGGER0: ctrl_trigger_manager
266
    generic map(
267
      MEM_ADD_WIDTH   => 14,--:  integer := 14;
268 48 budinero
      DATA_WIDTH      => 10,--:  integer := 10;
269
      CHANNELS_WIDTH  => 1 --:   integer := 4
270 38 budinero
    )
271
    port map(
272 55 budinero
      data_I          => memwr_out_dat(9 downto 0),  -- values beign writed in memory
273
      channel_I       => memwr_out_dat(10 downto 10),
274 38 budinero
      trig_channel_I  => reg_trigger_channel,
275
      address_I       => memwr_out_adr,
276
      final_address_I => reg_buffer_size,
277
      offset_I        => reg_trigger_offset,
278
      level_I         => reg_trigger_level,
279
      falling_I       => reg_trigger_edge,
280
      clk_I           => CLK_I_daq,
281
      reset_I         => trigger_reset,
282
      enable_I        => trigger_en,
283
      trigger_O       => trigger_act,
284
      address_O       => trigger_out_adr
285
    );
286
 
287
  -- reg_: signals from conf registers
288 48 budinero
  U_CTRL_ADDALLOC0: ctrl_address_allocation
289 38 budinero
    port map(
290
      -- From port
291
      DAT_I_port        => DAT_I_port,
292
      DAT_O_port        => DAT_O_port,
293
      ADR_I_port        => ADR_I_port,
294
      CYC_I_port        => CYC_I_port,
295
      STB_I_port        => STB_I_port,
296
      ACK_O_port        => ACK_O_port,
297
      WE_I_port         => WE_I_port,
298
      RST_I             => RST_I_port,
299
      CLK_I             => CLK_I_port,
300
      -- To internal 
301 48 budinero
      CYC_O_int         => outmgr_in_cyc,
302
      STB_O_int         => outmgr_in_stb,
303
      ACK_I_int         => outmgr_out_akc,
304
      DAT_I_int         => outmgr_out_dat,
305
      -- Internal
306 38 budinero
      time_scale_O      => reg_time_scale,
307
      time_scale_en_O   => reg_time_scale_en,
308
      channels_sel_O    => reg_channels_selection,
309
      buffer_size_O     => reg_buffer_size,
310
 
311
      trigger_en_O      => reg_trigger_en,
312
      trigger_edge_O    => reg_trigger_edge,
313
      trigger_level_O   => reg_trigger_level,
314
      trigger_offset_O  => reg_trigger_offset,
315
      trigger_channel_O => reg_trigger_channel,
316
 
317 48 budinero
      error_number_I    => "000", -- not implemented yet
318 38 budinero
 
319 48 budinero
      adc_conf_O        => dat_to_adc,
320
 
321 38 budinero
      start_O           => start,
322
      continuous_O      => continuous,
323 56 budinero
      status_I         =>  status,
324 48 budinero
      write_in_adc_O    => write_in_adc,
325 38 budinero
      stop_O            => stop
326
    );
327
 
328
  ------------------------------------------------------------------------------------------------
329 48 budinero
  -- Assignments
330
  ADR_O_memw <= memwr_out_adr;
331 55 budinero
  DAT_O_memw <= memwr_out_dat;
332
 
333 48 budinero
  ADR_O_daq <= '0' & chsel_channel(0) when strobe_adc = '0'
334 55 budinero
          else "10";
335 48 budinero
  DAT_O_daq <= dat_to_adc;
336
  CYC_O_daq <= strobe_adc or memwr_out_cyc_daq;
337
  STB_O_daq <= strobe_adc or memwr_out_stb_daq;
338
  WE_O_daq <= strobe_adc ;
339
 
340
 
341
  memwr_in_dat <= (15 downto 11 => '0') &  chsel_channel & DAT_I_daq(9 downto 0);
342
  memwr_in_ack_mem <= ACK_I_memw;
343
 
344
  ------------------------------------------------------------------------------------------------
345 38 budinero
  -- Machine
346 54 budinero
  P_sm_comb: process (present_state, reg_trigger_en, trigger_out_adr, memwr_out_adr,
347 57 budinero
  memwr_in_ack_mem, outmgr_finish, continuous, ack_i_daq,next_status1,trigger_act)
348 38 budinero
  begin
349 48 budinero
    -- signals from output manager are described in next process
350 38 budinero
    case present_state is
351
      when ST_INIT =>
352
 
353
        memwr_reset       <= '1';
354 48 budinero
        memwr_en          <= '-';
355 38 budinero
 
356
        dskip_reset   <= '1';
357
 
358 48 budinero
        chsel_reset   <= '0';
359 38 budinero
 
360
        trigger_reset <= '1';
361 48 budinero
        trigger_en    <= '-';
362 38 budinero
 
363 56 budinero
        status(0) <= '1';
364 57 budinero
        --  next_status1: above
365 38 budinero
 
366 48 budinero
        strobe_adc <= '0';
367 38 budinero
 
368 48 budinero
        -- -- -- --
369 57 budinero
        if outmgr_finish = '0' then
370
          next_state <= ST_RUNNING;
371
          next_status1 <= not(status(1)); -- will be changed every buffer full read 
372
        else
373
          next_state <= ST_INIT;
374
          next_status1 <= status(1);
375
        end if;
376
        -- if there is an error manager, include "if" for errors in parameters
377
 
378 38 budinero
 
379
 
380 48 budinero
      when ST_RUNNING =>
381
 
382 38 budinero
        memwr_reset       <= '0';
383 55 budinero
        if reg_trigger_en = '1' and trigger_out_adr = memwr_out_adr and trigger_act = '1' then
384 48 budinero
          memwr_en        <= '0';
385
        else
386
          memwr_en        <= '1';
387
        end if;
388 38 budinero
 
389
        dskip_reset   <= '0';
390
 
391
        chsel_reset   <= '0';
392
 
393
        trigger_reset <= '0';
394 48 budinero
        trigger_en    <= reg_trigger_en and memwr_in_ack_mem;
395 38 budinero
 
396 56 budinero
        status(0) <= '1';
397
        next_status1 <= status(1);
398 38 budinero
 
399 48 budinero
        strobe_adc <= '0';
400 38 budinero
 
401 48 budinero
        -- -- -- --
402 56 budinero
        -- if there is an error manager, influde an if for errors in running, etc...
403 48 budinero
        if outmgr_finish = '1' then
404
          if continuous = '1' then
405
            next_state <= ST_INIT;
406
          else
407
            next_state <= ST_IDLE;
408
          end if;
409
        else
410
          next_state <= ST_RUNNING;
411
        end if;
412
 
413
      when ST_ADCWRITE_INIT =>
414
        memwr_reset       <= '1';
415
        memwr_en          <= '-';
416
 
417
        dskip_reset   <= '1';
418
 
419
        chsel_reset   <= '1';
420
 
421
        trigger_reset <= '1';
422
        trigger_en    <= '-';
423
 
424 56 budinero
        status(0) <= '1'; -- aviod an ack if there is a read/write from port
425
        next_status1 <= status(1);
426 48 budinero
 
427
        strobe_adc <= '0';
428
 
429
        -- -- -- --
430
        next_state <= ST_ADCWRITE;
431 38 budinero
 
432
 
433 48 budinero
      when ST_ADCWRITE =>
434
        memwr_reset       <= '1';
435
        memwr_en          <= '-';
436
 
437
        dskip_reset   <= '1';
438
 
439
        chsel_reset   <= '1';
440
 
441
        trigger_reset <= '1';
442
        trigger_en    <= '-';
443
 
444 56 budinero
        status(0) <= '1'; -- aviod an ack if there is a read/write from port
445
        next_status1 <= status(1);
446 48 budinero
 
447
        strobe_adc <= '1';
448
 
449
        -- -- -- --
450
        if ACK_I_daq = '1' then
451
          next_state <= ST_IDLE;
452
        else
453
          next_state <= ST_ADCWRITE;
454
        end if;
455 38 budinero
 
456
      when others =>  --ST_IDLE
457 48 budinero
 
458
        memwr_reset       <= '1';
459
        memwr_en          <= '-';
460
 
461
        dskip_reset   <= '1';
462
 
463
        chsel_reset   <= '1';
464
 
465
        trigger_reset <= '1';
466
        trigger_en    <= '-';
467
 
468 56 budinero
        status(0) <= '0';
469
        next_status1 <= '0'; -- or error when there is an error manager
470 48 budinero
 
471
        strobe_adc <= '0';
472
 
473
        -- -- -- --
474
        next_state    <= ST_IDLE;
475 38 budinero
    end case;
476
 
477
  end process;
478
 
479
 
480
 
481 57 budinero
  P_sm_clkd: process (RST_I_daq, stop, start, CLK_I_daq, next_state, write_in_adc,next_status1)
482 38 budinero
  begin
483
 
484 56 budinero
    if RST_I_daq = '1' then
485 38 budinero
      present_state <= ST_IDLE;
486 56 budinero
      status(1) <= '0';
487
    elsif stop = '1' then
488
      present_state <= ST_IDLE;
489 57 budinero
      status(1) <= '0';
490 48 budinero
    elsif write_in_adc = '1' then
491
      present_state <= ST_ADCWRITE_INIT;
492 57 budinero
      status(1) <= next_status1;
493 48 budinero
    elsif start = '1' and present_state /= ST_ADCWRITE and present_state /= ST_ADCWRITE_INIT then
494 38 budinero
      present_state <= ST_INIT;
495 57 budinero
      status(1) <= next_status1;
496 48 budinero
    elsif CLK_I_daq'event and CLK_I_daq = '1' then
497 38 budinero
      present_state <= next_state;
498 56 budinero
      status(1) <= next_status1;
499 38 budinero
    end if;
500
 
501
 
502
  end process;
503
 
504
 
505
 
506
  ------------------------------------------------------------------------------------------------
507
  -- Output
508
 
509 54 budinero
  P_OUTMGR: process (RST_I_port, stop, CLK_I_port, present_state, trigger_act,
510 38 budinero
  reg_trigger_en, memwr_out_adr, outmgr_en)
511 48 budinero
  begin
512 54 budinero
    -- load must be '1' only for one cycle, enable must be set until the end
513
    if RST_I_port = '1' or present_state /= ST_RUNNING then
514 38 budinero
      outmgr_load <= '0';
515
      outmgr_en   <=  '0';
516
    elsif CLK_I_port'event and CLK_I_port = '1' then
517 48 budinero
      if stop = '1' then
518
        outmgr_load <=  '0';
519
        outmgr_en   <=  '0';
520 54 budinero
      elsif outmgr_en = '1' then
521
        outmgr_load <= '0';
522 48 budinero
      elsif present_state = ST_RUNNING and ( trigger_act = '1' or (reg_trigger_en = '0' and
523
      memwr_out_adr /= 0 ) ) then
524 38 budinero
        outmgr_load <=  '1';
525
        outmgr_en   <=  '1';
526
        -- load must be set only one cycle
527
      end if;
528
    end if;
529
  end process;
530
 
531
  outmgr_initial_adr <= trigger_out_adr     when reg_trigger_en = '1' else
532
                        (others => '0');
533
 
534
end architecture;
535
 

powered by: WebSVN 2.1.0

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