1 | ----------------------------------------------------------------------------------
|
---|
2 | -- Company:
|
---|
3 | -- Engineer:
|
---|
4 | --
|
---|
5 | -- Create Date: 10:44:52 01/07/2010
|
---|
6 | -- Design Name:
|
---|
7 | -- Module Name: adc_emulator - Behavioral
|
---|
8 | -- Project Name:
|
---|
9 | -- Target Devices:
|
---|
10 | -- Tool versions:
|
---|
11 | -- Description:
|
---|
12 | --
|
---|
13 | -- Dependencies:
|
---|
14 | --
|
---|
15 | -- Revision:
|
---|
16 | -- Revision 0.01 - File Created
|
---|
17 | -- Additional Comments:
|
---|
18 | --
|
---|
19 | ----------------------------------------------------------------------------------
|
---|
20 | -- hds interface_start
|
---|
21 | LIBRARY ieee;
|
---|
22 | USE ieee.std_logic_1164.all;
|
---|
23 | USE ieee.std_logic_unsigned.all;
|
---|
24 | USE ieee.std_logic_textio.all;
|
---|
25 | LIBRARY std;
|
---|
26 | USE std.textio.all;
|
---|
27 |
|
---|
28 | ENTITY adc_emulator IS
|
---|
29 | GENERIC(
|
---|
30 | INPUT_FILE : string := "filename"
|
---|
31 | );
|
---|
32 | PORT(
|
---|
33 | clk : IN std_logic;
|
---|
34 | data : OUT std_logic_vector (11 downto 0);
|
---|
35 | otr : OUT std_logic;
|
---|
36 | oeb : IN std_logic
|
---|
37 | );
|
---|
38 |
|
---|
39 | -- Declarations
|
---|
40 |
|
---|
41 | END adc_emulator ;
|
---|
42 |
|
---|
43 | architecture Behavioral of adc_emulator is
|
---|
44 |
|
---|
45 | -- type_rom_type has to be a multiple of 4 bit because HREAD is used
|
---|
46 | type type_shift_reg is array (0 to 7) of std_logic_vector(12 downto 0);
|
---|
47 | type type_rom_array is array (0 to 1024) of std_logic_vector(15 downto 0);
|
---|
48 |
|
---|
49 | -- 'InitRomFromFile' reads one column of 'rom_filename' and puts the returned value to 'rom(i)'
|
---|
50 | impure function InitRomFromFile (rom_filename : in string) return type_rom_array is
|
---|
51 | file rom_file : text open read_mode is rom_filename;
|
---|
52 | variable rom_file_line: line;
|
---|
53 | variable rom : type_rom_array;
|
---|
54 | begin
|
---|
55 | for i in 0 to 1023 loop
|
---|
56 | readline(rom_file, rom_file_line);
|
---|
57 | hread(rom_file_line, rom(i));
|
---|
58 | end loop;
|
---|
59 | return rom;
|
---|
60 | end function InitRomFromFile;
|
---|
61 |
|
---|
62 | signal rom : type_rom_array := InitRomFromFile(INPUT_FILE);
|
---|
63 | signal rom_reg : type_shift_reg;
|
---|
64 | signal rom_addr : std_logic_vector(9 downto 0) := (others => '0');
|
---|
65 | signal rom_data : std_logic_vector(12 downto 0);
|
---|
66 |
|
---|
67 | begin
|
---|
68 |
|
---|
69 | rom_data <= rom(conv_integer(rom_addr))(12 downto 0);
|
---|
70 | data <= rom_reg(7)(11 downto 0) when oeb = '0' else (others => 'Z');
|
---|
71 | otr <= rom_reg(7)(12);
|
---|
72 |
|
---|
73 | fetch_data_proc: process(clk)
|
---|
74 | begin
|
---|
75 | if rising_edge(clk) then
|
---|
76 | if (oeb = '0') then
|
---|
77 | rom_addr <= rom_addr + 1;
|
---|
78 | else
|
---|
79 | rom_addr <= (others => '0');
|
---|
80 | end if;
|
---|
81 | end if;
|
---|
82 | end process fetch_data_proc;
|
---|
83 |
|
---|
84 |
|
---|
85 | ad_conv_proc: process(clk)
|
---|
86 | begin
|
---|
87 | if rising_edge(clk) then
|
---|
88 | if (oeb = '0') then
|
---|
89 | if (conv_integer(rom_data) > 2**12-1) then
|
---|
90 | rom_reg(0) <= '1' & X"FFF"; -- set OTR flag when rom_data is too high and set adc value to max
|
---|
91 | else
|
---|
92 | rom_reg(0) <= rom_data; -- shifting input cause output is shifted 7 cycles
|
---|
93 | end if;
|
---|
94 | rom_reg(1) <= rom_reg(0);
|
---|
95 | rom_reg(2) <= rom_reg(1);
|
---|
96 | rom_reg(3) <= rom_reg(2);
|
---|
97 | rom_reg(4) <= rom_reg(3);
|
---|
98 | rom_reg(5) <= rom_reg(4);
|
---|
99 | rom_reg(6) <= rom_reg(5);
|
---|
100 | rom_reg(7) <= rom_reg(6);
|
---|
101 | end if;
|
---|
102 | end if;
|
---|
103 | end process ad_conv_proc;
|
---|
104 |
|
---|
105 | end Behavioral;
|
---|
106 |
|
---|