?? ad0804.vhd
字號:
--下面給出一個用VHDL實現ADC0804控制器的完整設計過程
--4個狀態如下:
--
--idle: CS="0",WR=0,RD=1 啟動AD0804開始轉換
--convert:CS=1,WR=1,RD=1,AD0804進行數據轉換
--read1: CS="0",WR=1,RD=0,INTR,轉換結束,開始讀
--read2: CS="1",WR=1,RD=1,讀取數據。
--ADC0804的輸入時鐘沒有固定要求,一般為640KHZ、750KHZ
--------------------------------------------------------------------------------
-- Designer Name: bankqd
-- Module Name: ad0804 - Behave
-- 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 ad0804 is
port(
reset : in std_logic;
clk : in std_logic;
ad_int : 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;
architecture Behave of ad0804 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 = '1') then
current_state <= start;
elsif(clk'event and clk = '1') then
current_state <= next_state;
end if;
end process sync;
comb :process(current_state, ad_int)
begin
case current_state is
when start =>
next_state <= convert;
cs <= '0';
wr <= '0';
rd <= '1';
read_data <= '0';
when convert =>
if(ad_int = '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 = '1') 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;
data_o <= data_r;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -