搜索
bottom↓
回复: 1

新手 找大侠救命

[复制链接]

出0入0汤圆

发表于 2009-11-1 22:36:22 | 显示全部楼层 |阅读模式
下面是我写的状态机   就是编译成功后  
   没那个状态机的效果  希望个位大侠帮帮我这个新手。。
library ieee;
use ieee.std_logic_1164.all;
--use ieee.std_logic_arith.all;
--use ieee.std_logic_unsigned.all;
--use ieee.std_logic_signed.all;

entity jia1 is
port( clk,res,up,dow: in   std_logic;
          -- uu :          in std_logic_vector(1 downto 0);
           d            : out  bit_vector(1 downto 0);
           res1,up1,down1: out std_logic
     );
end;

architecture a of jia1 is
type state_type is (s0,s1,s2,s3);
signal old_state,new_state : state_type :=s0;
begin

   process(clk,res)
    begin
          if res='1' then
                -- new_state <= s0;
                 res1 <= '1';
          elsif clk'event and clk='1'  then
                 new_state<=old_state;
          end if;
        end process;
       
    process(new_state, up ,dow)
    begin
          case new_state is
                 when s0=>   
                      if up='0' then
                                  old_state<=s1;
                                  up1 <= '1';
                                  down1 <= '0';
                          elsif dow='0' then
                              up1 <= '0';
                              old_state <=s3;
                              down1 <= '1';
                          end if;
                        d <="00";
                 when s1=>   
                      if up='0' then
                                  old_state<=s2;
                                 up1 <= '1';
                                down1 <= '0';
                          elsif dow='0' then
                        up1 <= '0';
                              old_state <=s0;
                         down1 <= '1';
                          end if;
                        d <="01";
                 when s2=>   
                      if up='0' then
                                  old_state<=s3;
                                 up1 <= '1';
                                down1 <= '0';
                          elsif dow='0' then
                        up1 <= '0';
                              old_state <=s1;
                        down1 <= '1';
                          end if;
                        d <="10";
                 when s3=>   
                      if up='0' then
                                  old_state<=s0;
                                 up1 <= '1';
                                down1 <= '0';
                          elsif dow='0' then
                        up1 <= '0';
                         down1 <= '1';
                              old_state <=s2;
                         
                          end if;
                        d <="11";
                end case;
   end process;
               
end;

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2009-11-3 09:38:42 | 显示全部楼层
看了你写的程序,你的输出up1,down1: out std_logic 只与输入up,dow: in std_logic;有关与状态无关。不应写在状态机里的
      if--elseif--end if 里面。
   还有输出res1: out std_logic 的值不明确。
   我猜你的思路应该要用一个米里型状态机来完成。
   参考如下:不知道是不是和你的思路一样。
   library ieee;
use ieee.std_logic_1164.all;
--use ieee.std_logic_arith.all;
--use ieee.std_logic_unsigned.all;
--use ieee.std_logic_signed.all;
entity skd020 is
  port( clk,res,up,dow: in   std_logic;
                     d: out  bit_vector(1 downto 0);
        res1,up1,down1: out std_logic);
end skd020;

architecture a of skd020 is
  type state_type is (s0,s1,s2,s3);
  signal old_state : state_type :=s0;
begin

  process(clk)
  begin
    if res='1' then
       old_state<=s0;
       res1<='1';
    elsif clk'event and clk='1'  then
       res1<='0';
    case old_state is
      when s0=>   
        if up='0' then
           old_state<=s1;
        elsif dow='0' then
           old_state <=s3;
        end if;
      when s1=>   
        if up='0' then
           old_state<=s2;
        elsif dow='0' then
           old_state <=s0;
        end if;
      when s2=>   
        if up='0' then
           old_state<=s3;
        elsif dow='0' then
           old_state <=s1;  
        end if;
      when s3=>   
        if up='0' then
           old_state<=s0;
        elsif dow='0' then
           old_state <=s2;
        end if;
    end case;
  end if;
end process;

process(up,dow,old_state,clk)
   begin
     if clk'event and clk='1' then
       case old_state is
         when s0=>
           d <="00";
           if up='0' then
              up1<='1';
              down1<='0';
           elsif dow='0' then
              up1<='0';
              down1<='1';
           end if;
         when s1=>
           d <="01";
           if up='0' then
              up1<='1';
              down1<='0';
           elsif dow='0' then
              up1<='0';
              down1<='1';
           end if;
         when s2=>
           d <="10";
           if up='0' then
              up1<='1';
              down1<='0';
           elsif dow='0' then
              up1<='0';
              down1<='1';
           end if;
         when s3=>
           d <="11";
           if up='0' then
              up1<='1';
              down1<='0';
           elsif dow='0' then
              up1<='0';
              down1<='1';
           end if;
       end case;
     end if;
  end process;
end;
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 19:28

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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