Как я могу увеличить асинхронный счетчик с помощью кнопок? - PullRequest
0 голосов
/ 03 мая 2019

Мне нужно создать счетчик с частотой 1 Гц, который имеет 3 асинхронных элемента: incrementMinutes, incrementSeconds и Reset (получается из anding Minutes and Seconds. Мой код выглядит так:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Counter is
    Port ( Clock : in STD_LOGIC; --Clock 1Hz
           ECU : in STD_LOGIC;--Enable Count Up
           ECD : in STD_LOGIC;--Enable Count Down
           Num : out STD_LOGIC_VECTOR (15 downto 0);--Output displayed on BCD7Seg
           incS : in STD_LOGIC;--increment seconds
           incM : in STD_LOGIC;--increment minutes
           Reset : in STD_LOGIC);--reset( and betweeen seconds and minutes)
end Counter;

architecture Behavioral of Counter is
signal count : STD_LOGIC_VECTOR(15 downto 0):= x"0000";
signal lastb_S: STD_LOGIC;--previous state of pushbutton S used for edge detection
signal lastb_M: STD_LOGIC;--previous state of pushbutton M used for edge detection
begin
Num <= count;

process(Clock,Reset,incS,incM)
begin
     lastb_S <= incS;
     lastb_M <= incM;
    if(Reset = '1') then
        count <= x"0000";
    else
        if(incS = '1' and lastb_S = '0') then
            if(count(3 downto 0) = 9) then
                count(3 downto 0) <= x"0";
                count(7 downto 4) <= count(7 downto 4) + 1;
                if(count(7 downto 4) = 5) then
                count(7 downto 0) <= x"00";
                end if;
            else
                count(3 downto 0) <= count(3 downto 0) + 1;
            end if;
        elsif(incM = '1' and lastb_M = '0') then
            if(count(11 downto 8) = 9) then
                count(11 downto 8) <= x"0";
                count(15 downto 12) <= count(15 downto 12) + 1;
                if(count(15 downto 12) = 9) then
                count(15 downto 8) <= x"00";
                end if;
            else
                count(11 downto 8) <= count(11 downto 8) + 1;
            end if;
        elsif(rising_edge(Clock)) then
            if(ECU = '1') then
                if(count(3 downto 0) = 9) then
                    count(3 downto 0) <= X"0";
                    count(7 downto 4) <= count(7 downto 4) + 1;
                    if(count(7 downto 4) = 5) then
                        count(7 downto 4) <= x"0";
                        count(11 downto 8) <= count(11 downto 8) + 1;
                        if(count(11 downto 8) = 9) then
                            count(11 downto 8) <= x"0";
                            count(15 downto 12) <= count(15 downto 12) + 1;
                            if(count(15 downto 12) = 9) then
                                count(15 downto 12) <= x"0";
                            end if;
                        end if;
                    end if;
                else
                    count(3 downto 0) <= count(3 downto 0) + 1;
                end if;
            elsif(ECD = '1') then
                if(count(3 downto 0) = 0) then
                    if(count(15 downto 4) /= 0) then
                        count(3 downto 0) <= x"9";
                        count(7 downto 4) <= count(7 downto 4) - 1;
                        if(count(7 downto 4) = 0) then
                            if(count(15 downto 8) /= 0) then
                                count(7 downto 4) <= x"5";
                                count(11 downto 8) <= count(11 downto 8) - 1;
                                if(count(11 downto 8) = 0) then
                                    if(count(15 downto 12) /= 0) then
                                    count(11 downto 8) <= x"9";
                                    count(15 downto 12) <= count(15 downto 12) - 1;
                                    end if;
                                end if;
                            end if;
                        end if;
                    end if;
                else
                    count(3 downto 0) <= count(3 downto 0) - 1;
                end if;
            end if;
        end if;
    end if;
end process; 

end Behavioral;

Я попробовал код на Basys 3, и кнопки увеличения не действуют. Считается нормально и Сброс работает.

...