|
发表于 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; |
|