| 1 |
32 |
budinero |
-------------------------------------------------------------------------------------------------100
|
| 2 |
|
|
--| Modular Oscilloscope
|
| 3 |
|
|
--| UNSL - Argentine
|
| 4 |
|
|
--|
|
| 5 |
38 |
budinero |
--| File: ctrl_channel_selector.vhd
|
| 6 |
|
|
--| Version: 0.3
|
| 7 |
32 |
budinero |
--| 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 |
38 |
budinero |
--| 0.3 | jul-2009 | Added signal indicating when it's selecting the first channel
|
| 19 |
32 |
budinero |
----------------------------------------------------------------------------------------------------
|
| 20 |
33 |
budinero |
--| Copyright © 2009, Facundo Aguilera.
|
| 21 |
32 |
budinero |
--|
|
| 22 |
|
|
--| This VHDL design file is an open design; you can redistribute it and/or
|
| 23 |
|
|
--| modify it and/or implement it after contacting the author.
|
| 24 |
|
|
----------------------------------------------------------------------------------------------------
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
--==================================================================================================
|
| 28 |
|
|
-- TODO
|
| 29 |
38 |
budinero |
-- · Speed up...
|
| 30 |
|
|
-- · Generic width in channel_number_O
|
| 31 |
32 |
budinero |
--==================================================================================================
|
| 32 |
|
|
|
| 33 |
|
|
|
| 34 |
|
|
library ieee;
|
| 35 |
|
|
use ieee.std_logic_1164.all;
|
| 36 |
|
|
--use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
| 37 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
| 38 |
|
|
use ieee.math_real.all;
|
| 39 |
|
|
|
| 40 |
|
|
|
| 41 |
|
|
----------------------------------------------------------------------------------------------------
|
| 42 |
|
|
----------------------------------------------------------------------------------------------------
|
| 43 |
38 |
budinero |
entity ctrl_channel_selector is
|
| 44 |
32 |
budinero |
generic(
|
| 45 |
38 |
budinero |
CHANNEL_WIDTH: integer := 4 -- number of channels 2**CHANNEL_WIDTH, max. 4
|
| 46 |
32 |
budinero |
);
|
| 47 |
|
|
port(
|
| 48 |
38 |
budinero |
channels_I: in std_logic_vector(integer(2**real(CHANNEL_WIDTH))-1 downto 0);
|
| 49 |
32 |
budinero |
channel_number_O: out std_logic_vector(3 downto 0);
|
| 50 |
38 |
budinero |
first_channel_O: out std_logic;
|
| 51 |
32 |
budinero |
clk_I: in std_logic;
|
| 52 |
|
|
enable_I: in std_logic;
|
| 53 |
|
|
reset_I: in std_logic
|
| 54 |
|
|
);
|
| 55 |
|
|
end entity channel_selector;
|
| 56 |
|
|
|
| 57 |
|
|
|
| 58 |
|
|
----------------------------------------------------------------------------------------------------
|
| 59 |
|
|
----------------------------------------------------------------------------------------------------
|
| 60 |
38 |
budinero |
architecture ARCH01 of ctrl_channel_selector is
|
| 61 |
|
|
constant N_CHANNELS: integer := integer(2**real(CHANNEL_WIDTH));
|
| 62 |
|
|
-- signal channel: unsigned(CHANNEL_WIDTH-1 downto 0);
|
| 63 |
|
|
-- signal next_channel: unsigned(CHANNEL_WIDTH-1 downto 0);
|
| 64 |
|
|
-- signal next_is_first_channel: std_logic;
|
| 65 |
|
|
signal channel: unsigned(CHANNEL_WIDTH-1 downto 0);
|
| 66 |
|
|
signal next_channel: unsigned(CHANNEL_WIDTH downto 0);
|
| 67 |
|
|
signal next_is_first_channel: std_logic;
|
| 68 |
|
|
signal rotated: unsigned(N_CHANNELS-1 downto 0);
|
| 69 |
|
|
signal plus: unsigned(CHANNEL_WIDTH downto 0);
|
| 70 |
32 |
budinero |
begin
|
| 71 |
|
|
|
| 72 |
|
|
--------------------------------------------------------------------------------------------------
|
| 73 |
|
|
-- Output
|
| 74 |
|
|
channel_number_O <= (3 downto CHANNEL_WIDTH => '0') & std_logic_vector(channel);
|
| 75 |
|
|
--channel_number_O <= std_logic_vector(channel);
|
| 76 |
|
|
--------------------------------------------------------------------------------------------------
|
| 77 |
38 |
budinero |
-- Combinational selection of next channel
|
| 78 |
32 |
budinero |
|
| 79 |
38 |
budinero |
-- P_comb: process(channel,channels_I)
|
| 80 |
|
|
-- variable j : integer range 0 to N_CHANNELS-1;
|
| 81 |
|
|
-- variable index: integer range 0 to N_CHANNELS-1;
|
| 82 |
|
|
-- begin
|
| 83 |
32 |
budinero |
|
| 84 |
38 |
budinero |
-- for j in 0 to N_CHANNELS-1 loop
|
| 85 |
32 |
budinero |
|
| 86 |
38 |
budinero |
-- if (j + to_integer(channel) + 1) > (N_CHANNELS - 1) then
|
| 87 |
|
|
-- index := j + to_integer(channel) + 1 - N_CHANNELS;
|
| 88 |
|
|
-- next_is_first_channel <= '1';
|
| 89 |
|
|
-- else
|
| 90 |
|
|
-- index := j + to_integer(channel) + 1;
|
| 91 |
|
|
-- next_is_first_channel <= '0';
|
| 92 |
|
|
-- end if;
|
| 93 |
32 |
budinero |
|
| 94 |
38 |
budinero |
-- if channels_I(index) = '1' then
|
| 95 |
|
|
-- next_channel <= to_unsigned(index, CHANNEL_WIDTH);
|
| 96 |
|
|
-- exit;
|
| 97 |
|
|
-- else
|
| 98 |
|
|
-- next_channel <= channel;
|
| 99 |
|
|
-- end if;
|
| 100 |
|
|
-- end loop;
|
| 101 |
|
|
-- end process;
|
| 102 |
|
|
|
| 103 |
|
|
--100.0 MHz 67.1 MHz (N_CHANNELS = 16)
|
| 104 |
|
|
-- 271 of 38400 (1%)
|
| 105 |
32 |
budinero |
|
| 106 |
|
|
|
| 107 |
|
|
|
| 108 |
|
|
|
| 109 |
38 |
budinero |
rotated <= unsigned(channels_I) ror (to_integer(channel));
|
| 110 |
|
|
next_channel <= ('0' & channel) + plus;
|
| 111 |
|
|
--next_channel <= channel + plus;
|
| 112 |
|
|
next_is_first_channel <= next_channel (CHANNEL_WIDTH);
|
| 113 |
|
|
P_coder: process(rotated)
|
| 114 |
|
|
variable i: integer range 1 to N_CHANNELS-1;
|
| 115 |
|
|
begin
|
| 116 |
|
|
for i in 1 to N_CHANNELS-1 loop
|
| 117 |
|
|
if rotated(i) = '1' then
|
| 118 |
|
|
plus <= to_unsigned(i, CHANNEL_WIDTH+1);
|
| 119 |
|
|
exit;
|
| 120 |
|
|
else
|
| 121 |
|
|
plus <= (CHANNEL_WIDTH =>'1') & (CHANNEL_WIDTH - 1 downto 0 => '0');
|
| 122 |
|
|
end if;
|
| 123 |
|
|
end loop;
|
| 124 |
|
|
end process;
|
| 125 |
32 |
budinero |
|
| 126 |
38 |
budinero |
--100.0 MHz 70.6 MHz (N_CHANNELS = 16)
|
| 127 |
|
|
-- 137 of 38400 (0%)
|
| 128 |
32 |
budinero |
|
| 129 |
|
|
--------------------------------------------------------------------------------------------------
|
| 130 |
38 |
budinero |
-- Clocked selection of actual channel
|
| 131 |
32 |
budinero |
|
| 132 |
38 |
budinero |
-- P_clock: process(enable_I, reset_I, next_channel, clk_I)
|
| 133 |
|
|
-- begin
|
| 134 |
|
|
-- if clk_I'event and clk_I = '1' then
|
| 135 |
|
|
-- if reset_I = '1' then
|
| 136 |
|
|
-- channel <= (others => '0');
|
| 137 |
|
|
-- first_channel_O <= '1';
|
| 138 |
|
|
-- elsif enable_I = '1' then
|
| 139 |
|
|
-- channel <= next_channel;
|
| 140 |
|
|
-- first_channel_O <= next_is_first_channel;
|
| 141 |
|
|
-- end if;
|
| 142 |
|
|
-- end if;
|
| 143 |
|
|
-- end process;
|
| 144 |
|
|
|
| 145 |
|
|
P_clock: process(enable_I, reset_I, next_channel, clk_I)
|
| 146 |
32 |
budinero |
begin
|
| 147 |
|
|
if clk_I'event and clk_I = '1' then
|
| 148 |
|
|
if reset_I = '1' then
|
| 149 |
|
|
channel <= (others => '0');
|
| 150 |
38 |
budinero |
first_channel_O <= '1';
|
| 151 |
32 |
budinero |
elsif enable_I = '1' then
|
| 152 |
38 |
budinero |
channel <= next_channel(CHANNEL_WIDTH-1 downto 0);
|
| 153 |
|
|
first_channel_O <= next_is_first_channel;
|
| 154 |
32 |
budinero |
end if;
|
| 155 |
|
|
end if;
|
| 156 |
|
|
end process;
|
| 157 |
|
|
|
| 158 |
|
|
|
| 159 |
|
|
end architecture;
|