这是一个关于ADC0809采样控制程序,由于才学vhdl所以看了半天没懂。特别是com:process(current_state,eoc) 此进程后面的语句。为什么要定义六个状态。哪位高手能帮帮我,谢谢。最好能详细讲解一下。谢谢谢谢额。。。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity PL_AD is
port ( d : in std_logic_vector(7 downto 0);
clk,eoc : in std_logic;
lock1,start, ale,en: out std_logic;
abc_in :in std_logic_vector(2 downto 0);
abc_out :std_logic_vector(2 downto 0);--ADC0809
q : out std_logic_vector(7 downto 0));
end pl_AD;
architecture behav of PL_AD is
type states is ( st0,st1, st2, st3, st4,st5,st6);
signal current_state, next_state:states:=st0;
signal regl :std_logic_vector(7 downto 0);
signal lock : std_logic;
signal qq:std_logic_vector(7 downto 0);
begin
com:process(current_state,eoc)
begin
case current_state is
when st0=>next_state<=st1;ale<='0';start<='0';en<='0';
when st1=>next_state<=st2;ale<='1';start<='0';en<='0';
when st2=>next_state<=st3;ale<='0';start<='1';en<='0';
when st3=> ale<='0';start<='0';en<='0';
if eoc='1' then next_state<=st3;
else next_state<=st4;
end if;
when st4=> ale<='0';start<='0';en<='0';
if eoc='0' then next_state<=st4;
else next_state<=st5;
end if;
when st5=>next_state<=st6;ale<='0';start<='0';en<='1';
when st6=>next_state<=st0;ale<='0';start<='0';en<='1';regl<=d;
when others=> next_state<=st0;ale<='0';start<='0';en<='0';
end case;
end process;
clock:process(clk)
begin
if clk'event and clk='1' then qq<=qq+1;
if QQ="01111111" THEN lock<='1'; current_state <=next_state;
elsif qq<="01111111" then lock<='0';
end if;
end if;
end process;
q<=regl; lock1<=lock; abc_out<=abc_in;
end behav;
此帖出自
小平头技术问答
when st3=> ale<='0';start<='0';en<='0';--检测数据是否转换完
if eoc='1' then next_state<=st3;
else next_state<=st4;
end if;
when st4=> ale<='0';start<='0';en<='0';--再次检测数据是否转换完
if eoc='0' then next_state<=st4;
else next_state<=st5;
end if;
不过我这里的注释好像错了,这两个when合起来才是检测数据是否转换完的。
正确的注释是:
when st3=> ale<='0';start<='0';en<='0';--检测EOC的下降沿
if eoc='1' then next_state<=st3;--如果eoc=1则保持在st3
else next_state<=st4;--否则进入下一状态
end if;
when st4=> ale<='0';start<='0';en<='0';--检测eoc的上升沿
if eoc='0' then next_state<=st4;--如果eoc=0则保持在st4
else next_state<=st5;--否则进入下一状态
end if;
看了ADC0809的工作时序图就知道了:
start是转换启动信号,一个正脉冲后A/D开始转换;ale是3位通道选择地址信号锁存信号。当模拟量送至某一输入端时,有3位地址信号选择,而地址信号由ALE锁存。
EOC是转换情况状态信号,一开始为高电平,当启动装换约100us后,eoc将产生一个负脉冲,以示转换完成,在eoc的上升沿后,且输出使能信号enanle为高电时,则打开三态缓冲器,把转换好的8位数据送入数据总线,这样便完成了一次转换。
一周热门 更多>