实在不懂

2019-03-25 10:09发布

这是一个关于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; 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
16条回答
阿飞
2019-03-27 00:41
--******因为FPGA的时钟频率为50MHz,则256分频后,即ADC0809输入时钟为195KHz******
--******对ADC0809进行简单的采样控制,得到的数据进FPGA送到8个并排的数码管显示*****
--***后面的注释是我自己加的,因该是这样理解的吧***
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); --ADC0809输出的采样数据输入FPGA
       clk,eoc: in std_logic; --clk为系统时钟,eoc为ADC0809转换结束信号输入FPGA
       lock1,start, ale,en: out std_logic;  --ADC0809控制信号FPGA输出信号
      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));送至8个并排数码管信号FPGA输出数字信号
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;--定义总体两个状态现态和次态并且初值为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) –此进程主要是驱动ADC0809工作即数据转换过程
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;--打开输出数据锁存器,将数据送入寄存器regl
  when others=> next_state<=st0;ale<='0';start<='0';en<='0';
  end case;
end process;
clock:process(clk) --对系统时钟进行分频,得到驱动ADC0809的时钟信号
begin
if clk'event and clk='1' then qq<=qq+1;
if QQ="01111111" THEN lock<='1';--实现分频
current_state <=next_state;--在lock上升沿,转换至下一状态   
    elsif qq<="01111111" then lock<='0';       
    end if;  
end if;
end process;
q<=regl;--寄存器数据输出即FPGA输出
lock1<=lock;
abc_out<=abc_in;--模拟选通信号送往ADC0809
end behav;

一周热门 更多>