集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 4007|回复: 6

单进程状态机的设计

[复制链接]
encounter 发表于 2010-6-26 00:08:51 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-11-19 06:36 编辑

library ieee;
use ieee.std_logic_1164.all;
entity adcint is
port(d:in std_logic_vector(7 downto 0);
  clk,eoc:in std_logic;
  ale,start,oe,adda,lock0 : out std_logic;
  q : out std_logic_vector(7 downto 0));
end adcint;
architecture be of adcint is
type states is (st0,st1,st2,st3,st4);
signal p_state:states:=st0;

signal lock :std_logic;
begin
adda<='1';

lock0<=lock;
com:process(p_state,eoc,clk,lock)
begin
if clk'event and clk='1' then
case p_state is
  when st0=>ale<='0';start<='0';lock<='0';oe<='0';
    p_state<=st1;
  when st1=>ale<='1';start<='1';lock<='0';oe<='0';
     p_state<=st2;
  when st2=>ale<='0';start<='0';lock<='0';oe<='0';
    if(eoc='1') then p_state<=st3;
    else p_state<=st2;
    end if;
  when st3=>ale<='0';start<='0';lock<='0';oe<='1';
    p_state<=st4;
  when st4=>ale<='0';start<='0';lock<='1';oe<='1';
    p_state<=st0;
   
  when others=>p_state<=st0;
  end case;
  end if;
if lock='1' and lock'event then q<=d;
end if;
  end process;
end be;
usb 发表于 2010-6-26 00:41:35 | 显示全部楼层
状态机的 DO 文件怎么写哟,&nbsp;&nbsp;帮我写一下这个程序,做个例子library ieee;<br>
use ieee.std_logic_1164.all;<br>
<br>
ENTITY StateMachine IS<br>
<br>
&nbsp; &nbsp; PORT(clock,x : IN BIT; z : OUT BIT);<br>
END StateMachine;<br>
-------------------------------------------------<br>
ARCHITECTURE using_wait OF StateMachine IS<br>
<br>
TYPE state_type IS (s0,s1,s2,s3);<br>
<br>
BEGIN<br>
&nbsp; &nbspROCESS<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp;VARIABLE state : state_type := s0;<br>
<br>
&nbsp; &nbsp;BEGIN<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp;WAIT UNTIL (clock'EVENT AND clock = '1');<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;CASE state IS<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;WHEN s0 =&gt; IF x = '0' THEN <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;WHEN s2 =&gt; IF x = '0' THEN <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;WHEN s3 =&gt; IF x = '0' THEN <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s3;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '1';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;WHEN s1 =&gt; IF x = '0' THEN <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ELSE<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state := s2;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;z &lt;= '0';<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;END IF;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;END CASE;<br>
&nbsp; &nbsp;END PROCESS;<br>
END using_wait;
usd 发表于 2010-6-26 02:15:58 | 显示全部楼层
什么是状态机的 DO 文件?我没有听说过啊, 我是刚学状态机的。
ANG 发表于 2010-6-26 02:46:22 | 显示全部楼层
你这些代码是VHDL写的吧,没研究过VHDL
VVIC 发表于 2010-6-26 03:09:34 | 显示全部楼层
学习中&hellip;&hellip;<br>
学习中&hellip;&hellip;
longt 发表于 2010-6-26 03:17:50 | 显示全部楼层
怎么有两个时钟信号啊???
usb 发表于 2010-6-26 03:46:02 | 显示全部楼层
if lock='1' and lock'event then q&lt;=d;和状态转移逻辑放在同一个进程中是错误的,你前面先用clk inputs等去生成 lock,随后你又想立刻捕捉其沿边,在VHDL里面对一个信号的赋值只有当进程结束时才会有效,因此如果你想利用lock的沿边的话肯定要那到外面来处理,但是我觉得这样的代码很危险,时序也许很可怕
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-15 17:09 , Processed in 0.073807 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表