下面是我的源程序,可是在硬件验证的时候,秒表进位会有错误。当2秒是进位一次,59秒时同样进位一次。正常情况下在2s是不应该进位的,希望高手指点一下。感激不已!
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clock is
port(clk,reset,busy:in std_logic;
--时钟信号和复位信号
setmin,sethour:in std_logic;
a1,a0:in std_logic_vector(3 downto 0);
y:out std_logic_vector(7 downto 0);
req:out std_logic;
alert:out std_logic
);
end clock;
architecture a of clock is
signal Q5,Q4,Q3,Q2,Q1,Q0:std_logic_vector(3 downto 0);
signal enmin,enhour :std_logic; --触发信号
signal q:std_logic_vector(22 downto 0); --分频信号
signal clks,clkscan: std_logic;
--1s时钟,扫描时钟
type state is (s0,s1,s2,s3,s4,s5);
signal p_state,n_state:state;
signal xx,yy,as:std_logic_vector(7 downto 0);
signal asout:std_logic_vector(3 downto 0);
signal n:std_logic_vector(1 downto 0);
signal w,r:std_logic;
begin
分频进程省略
second:process (clks) is --秒
begin
if reset='1' then
Q1<="0000";Q0<="0000";
elsif clks'event and clks='1' then
if Q0 = "1001" then
Q0<="0000";
if Q1 = "0101" then
Q1<="0000";
else
Q1<=Q1+1;
end if;
else
Q0<=Q0+'1';
end if;
end if;
end process;
enmin<='1' when Q1="0000" and Q0="0000";
minute:process (enmin) is--分
begin
if reset='1' then
Q3<="0000";Q2<="0000";
elsif setmin='1' then
Q3<=a1;Q2<=a0;
elsif enmin'event and enmin='1' then
if Q2 = "1001" then
Q2<="0000";
if Q3 = "0101" then
Q3<="0000";
else
Q3<=Q3+1;
end if;
else
Q2<=Q2+'1';
end if;
end if;
end process;
enhour<='1' when Q3="0000" and Q2="0000";
alert<='1' when Q3="0000" and Q2="0000" and Q1="0000" and Q0="0000"; --整点报时
hour:process (enhour) is--时
begin
if reset='1' then
Q5<="0000";Q4<="0000";
elsif sethour='1' then
Q5<=a1;Q4<=a0;
elsif enhour'event and enhour='1' then
if Q5="0010" and Q4="0011" then
Q5<="0000";Q4<="0000";
else
if Q4="1001" then
Q4<="0000";Q5<=Q5+'1';
else
Q4<=Q4+'1';
end if;
end if;
end if;
end process;
液晶扫描程序省略
end a;
|