--**********************分频进程*************************
process(clk)
variable cnt1 : integer range 0 to 100;
variable cnt2 : integer range 0 to 20;
begin
if clk'event and clk='1' then
if cnt1=100 then
cnt1:=0;
if cnt2=20 then
cnt2:=0;
clock<=not clock;
if(cnt=3)then
cnt<=0;
else
cnt<=cnt+1;
end if;
else
cnt2:=cnt2+1;
end if;
else
cnt1:=cnt1+1;
end if;
end if;
end process;
--**************状态驱动进程**********************
sync :process(clock,reset)
begin
if(reset = '0') then
current_state <= start;
elsif(clock'event and clock='1') then
current_state <= next_state;
end if;
end process sync;
--***************adc驱动进程*******************
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 =>--读状态1
next_state <= read2;
cs <= '0';
wr <= '1';
rd <= '0';
read_data <= '1';
when read2 =>--读状态2
next_state <= start;
cs <= '1';
wr <= '1';
rd <= '1';
read_data <= '0';
when others =>--其他状态
next_state <= start;
end case;
end process comb;
--****************读取AD数据********************
get_data: process(clock,reset)
begin
if(reset = '0') then
p<=0;
elsif(clock'event and clock='1') then
if(read_data = '1') then
p<=conv_integer(data_i);
end if;
end if;
end process;