--------------------------------------------------------------------------------
-- Design Name: skycanny
-- Module Name: ad_controller - Behavioral
-- Description: This VHDL design is created to implement a state machine
-- to control AD0804
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ad_controller is
port(
reset : in std_logic;
clk : in std_logic;
intr : in std_logic;
data_i : in std_logic_vector(7 downto 0);
data_o : out std_logic_vector(7 downto 0);
cs : out std_logic;
wr : out std_logic;
rd : out std_logic
);
end ad_controller;
architecture Behavioral of ad_controller is
type state is (start, convert, read1, read2);
signal current_state, next_state : state;
signal data_r : std_logic_vector(7 downto 0);
signal read_data : std_logic;
begin
sync :process(reset,clk)
begin
if(reset = '0') then
current_state <= start;
elsif(clk'event and clk = '1') then
current_state <= next_state;
end if;
end process sync;
comb :process(current_state, intr)
begin
case current_state is
when start =>
next_state <= convert;
cs <= '0';
wr <= '0';
rd <= '1';
read_data <= '0';
when convert =>
if(intr = '0') then
next_state <= read1;
else
next_state <= convert;
end if;
cs <= '1';
wr <= '1';
rd <= '1';
read_data <= '0';
when read1 =>
next_state <= read2;
cs <= '0';
wr <= '1';
rd <= '0';
read_data <= '1';
when read2 =>
next_state <= start;
cs <= '1';
wr <= '1';
rd <= '1';
read_data <= '0';
when others =>
next_state <= start;
end case;
end process comb;
get_data: process(reset,clk)
begin
if(reset = '0') then
data_r <= X"00";
elsif(clk'event and clk = '1') then
if(read_data = '1') then
data_r <= data_i;
end if;
end if;
end process;