| 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.NUMERIC_STD.ALL;
|
|---|
| 24 |
|
|---|
| 25 | ENTITY adc_emulator IS
|
|---|
| 26 | PORT(
|
|---|
| 27 | clk : IN STD_LOGIC;
|
|---|
| 28 | reset : IN STD_LOGIC;
|
|---|
| 29 | d : OUT STD_LOGIC_VECTOR (11 DOWNTO 0);
|
|---|
| 30 | otr : OUT STD_LOGIC;
|
|---|
| 31 | oeb : IN STD_LOGIC;
|
|---|
| 32 | rom_data : IN STD_LOGIC_VECTOR (12 DOWNTO 0);
|
|---|
| 33 | rom_addr : OUT STD_LOGIC_VECTOR (9 DOWNTO 0)
|
|---|
| 34 | );
|
|---|
| 35 |
|
|---|
| 36 | -- Declarations
|
|---|
| 37 |
|
|---|
| 38 | END adc_emulator ;
|
|---|
| 39 | -- hds interface_end
|
|---|
| 40 |
|
|---|
| 41 | architecture Behavioral of adc_emulator is
|
|---|
| 42 |
|
|---|
| 43 | type shift_reg is array (0 to 7) of STD_LOGIC_VECTOR(12 DOWNTO 0);
|
|---|
| 44 |
|
|---|
| 45 | signal rom_reg : shift_reg;
|
|---|
| 46 | signal temp_addr : STD_LOGIC_VECTOR(9 downto 0) := (others => '0') ;
|
|---|
| 47 |
|
|---|
| 48 | begin
|
|---|
| 49 |
|
|---|
| 50 | rom_addr <= temp_addr;
|
|---|
| 51 | d <= rom_reg(7)(11 downto 0) when oeb = '0' else (others => 'Z');
|
|---|
| 52 | otr <= rom_reg(7)(12);
|
|---|
| 53 |
|
|---|
| 54 | fetch_data_proc: process(clk, reset)
|
|---|
| 55 | begin
|
|---|
| 56 | if (reset = '1') then
|
|---|
| 57 | temp_addr <= (others => '0');
|
|---|
| 58 | elsif rising_edge(clk) then
|
|---|
| 59 | if (oeb = '0') then
|
|---|
| 60 | temp_addr <= STD_LOGIC_VECTOR(UNSIGNED(temp_addr) + TO_UNSIGNED(1,10));
|
|---|
| 61 | else
|
|---|
| 62 | temp_addr <= (others => '0');
|
|---|
| 63 | end if;
|
|---|
| 64 | end if;
|
|---|
| 65 | end process fetch_data_proc;
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | ad_conv_proc: process(clk, reset)
|
|---|
| 69 | begin
|
|---|
| 70 | if (reset = '1') then
|
|---|
| 71 | for i in 0 to 7 loop
|
|---|
| 72 | rom_reg(i) <= (others => '0');
|
|---|
| 73 | end loop;
|
|---|
| 74 | elsif rising_edge(clk) then
|
|---|
| 75 | if (oeb = '0') then
|
|---|
| 76 | if (unsigned(rom_data) > 2**12-1) then
|
|---|
| 77 | rom_reg(0) <= '1' & X"FFF"; -- set OTR flag when rom_data is too high and set adc value to max
|
|---|
| 78 | else
|
|---|
| 79 | rom_reg(0) <= rom_data; -- shifting input cause output is shifted 7 cycles
|
|---|
| 80 | end if;
|
|---|
| 81 | rom_reg(1) <= rom_reg(0);
|
|---|
| 82 | rom_reg(2) <= rom_reg(1);
|
|---|
| 83 | rom_reg(3) <= rom_reg(2);
|
|---|
| 84 | rom_reg(4) <= rom_reg(3);
|
|---|
| 85 | rom_reg(5) <= rom_reg(4);
|
|---|
| 86 | rom_reg(6) <= rom_reg(5);
|
|---|
| 87 | rom_reg(7) <= rom_reg(6);
|
|---|
| 88 | end if;
|
|---|
| 89 | end if;
|
|---|
| 90 | end process ad_conv_proc;
|
|---|
| 91 |
|
|---|
| 92 | end Behavioral;
|
|---|
| 93 |
|
|---|