--******因为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; |