--**********************分频进程*************************

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 = &#39;0&#39;) then

current_state <= start;

elsif(clock'event and clock=&#39;1&#39;) 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 <= &#39;0&#39;;

wr <= &#39;0&#39;;

rd <= &#39;1&#39;;

read_data <= &#39;0&#39;;

when convert =>--初始化

if(intr = &#39;0&#39;) then

next_state <= read1;

else

next_state <= convert;

end if;

cs <= &#39;1&#39;;

wr <= &#39;1&#39;;

rd <= &#39;1&#39;;

read_data <= &#39;0&#39;;

when read1 =>--读状态1

next_state <= read2;

cs <= &#39;0&#39;;

wr <= &#39;1&#39;;

rd <= &#39;0&#39;;

read_data <= &#39;1&#39;;

when read2 =>--读状态2

next_state <= start;

cs <= &#39;1&#39;;

wr <= &#39;1&#39;;

rd <= &#39;1&#39;;

read_data <= &#39;0&#39;;

when others =>--其他状态

next_state <= start;

end case;

end process comb;

--****************读取AD数据********************

get_data: process(clock,reset)

begin

if(reset = &#39;0&#39;) then

p<=0;

elsif(clock'event and clock=&#39;1&#39;) then

if(read_data = &#39;1&#39;) then

p<=conv_integer(data_i);

end if;

end if;

end process;