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

Subversion Repositories modular_oscilloscope

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

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
--| File: channel_selector.vhd
6
--| Version: 0.2
7
--| Tested in: Actel A3PE1500
8
--|   Board: RVI Prototype Board + LP Data Conversion Daughter Board
9
--|-------------------------------------------------------------------------------------------------
10
--| Description:
11
--|   CONTROL - Channel Selector
12
--|   This controls the comunication with the daq module. 
13
--|   
14
--|-------------------------------------------------------------------------------------------------
15
--| File history:
16
--|   0.1   | jul-2009 | First testing
17
--|   0.2   | jul-2009 | Added generic number of channel
18
----------------------------------------------------------------------------------------------------
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
-- · Speed up the design
29
--==================================================================================================
30
 
31
 
32
library ieee;
33
use ieee.std_logic_1164.all;
34
--use IEEE.STD_LOGIC_UNSIGNED.ALL;
35
use IEEE.NUMERIC_STD.ALL;
36
use ieee.math_real.all;
37
 
38
 
39
 
40
----------------------------------------------------------------------------------------------------
41
----------------------------------------------------------------------------------------------------
42
entity channel_selector is
43
  generic(
44
    N_CHANNELS: integer := 16 -- number of channels 
45
  );
46
  port(
47
    channels_I:         in  std_logic_vector(N_CHANNELS-1 downto 0);
48
    channel_number_O:   out std_logic_vector(3 downto 0);
49
    clk_I:              in  std_logic;
50
    enable_I:           in  std_logic;
51
    reset_I:            in  std_logic
52
  );
53
end entity channel_selector;
54
 
55
 
56
----------------------------------------------------------------------------------------------------
57
----------------------------------------------------------------------------------------------------
58
architecture ARCH01 of channel_selector is
59
  constant CHANNEL_WIDTH: integer := integer(ceil(log2(real(N_CHANNELS))));
60
 
61
  signal channel:       unsigned(CHANNEL_WIDTH-1 downto 0);
62
  signal next_channel:  unsigned(CHANNEL_WIDTH-1 downto 0);
63
 
64
 
65
begin
66
 
67
  --------------------------------------------------------------------------------------------------
68
  -- Output
69
  channel_number_O <= (3 downto CHANNEL_WIDTH => '0') & std_logic_vector(channel);
70
  --channel_number_O <=  std_logic_vector(channel);
71
  --------------------------------------------------------------------------------------------------
72
  -- Combinational selection
73
 
74
  P_comb: process(channel,channels_I)
75
    variable j :    integer range 0 to N_CHANNELS-1;
76
    variable index: integer range 0 to N_CHANNELS-1;
77
  begin
78
 
79
 
80
  --    -- for i in 0 to N_CHANNELS loop
81
  --       if i = to_integer(channel) then
82
  --         exit;
83
  --       end if;
84
  --      end loop;
85
 
86
  --  for i in 0 to N_CHANNELS loop
87
      --i := to_natural(channel);
88
      for j in 0 to N_CHANNELS-1 loop
89
 
90
        if (j + to_integer(channel) + 1) > (N_CHANNELS - 1) then
91
          index := j + to_integer(channel) + 1 - N_CHANNELS;
92
        else
93
          index := j + to_integer(channel) + 1;
94
        end if;
95
 
96
        if channels_I(index) = '1' then
97
          next_channel <= to_unsigned(index, CHANNEL_WIDTH);
98
          exit;
99
        else
100
          next_channel <= channel;
101
        end if;
102
 
103
      end loop;
104
 
105
 
106
 
107
 
108
 
109
 
110
 
111
--     for i in 0 to N_CHANNELS loop
112
--       if channel = to_unsigned(i, 4) then           
113
--         for j in i+1 to (2*N_CHANNELS)-1 loop
114
--           if j > N_CHANNELS-1 then
115
--             index := j - N_CHANNELS;
116
--           else
117
--             index := j;
118
--           end if;
119
--         
120
--           if channels_I(index) = '1' then
121
--             next_channel <= to_unsigned(index, CHANNEL_WIDTH);
122
--             exit;
123
--           else
124
--             next_channel <= channel;
125
--           end if;
126
--         end loop;
127
--         exit;
128
--       else
129
--         next_channel <= channel;
130
--       end if;
131
--     end loop;  
132
 
133
  end process;
134
 
135
 
136
  --------------------------------------------------------------------------------------------------
137
  -- Clocked
138
 
139
  P_clock: process(enable_I, reset_I, next_channel, clk_I)
140
  begin
141
    if clk_I'event and clk_I = '1' then
142
      if reset_I = '1' then
143
        channel <= (others => '0');
144
      elsif enable_I = '1' then
145
        channel <= next_channel;
146
      end if;
147
    end if;
148
  end process;
149
 
150
 
151
 
152
 
153
end architecture;

powered by: WebSVN 2.1.0

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