VHDL-无法添加数字?

时间:2019-03-17 14:50:44

标签: vhdl

您好,我想在ALTERA DE2上建立一个时钟,我可以通过按键来调整时钟的长度。 现在的问题是,当我从STD_LOGIC_VECTOR转换为UNSIGNED时,代码不起作用:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
--use ieee.std_logic_unsigned.all; Do not use with numeric_std

entity Adjust_Clock_4_buttens is

port(
    clk,clk1 : in STD_LOGIC;
    minutes_plus, minutes_minus,houres_plus,houres_minus : in STD_LOGIC;

    minutes : IN STD_LOGIC_VECTOR(5 downto 0);
    houres   : IN  STD_LOGIC_VECTOR(4 downto 0);

    output_minutes : out STD_LOGIC_VECTOR(5 downto 0);
    output_houres : out STD_LOGIC_VECTOR(4 downto 0);

    LED_0 : OUT STD_LOGIC;
    LED_1 : OUT STD_LOGIC;
    LED_2 : OUT STD_LOGIC;
    LED_3 : OUT STD_LOGIC

);
end entity Adjust_Clock_4_buttens ;

architecture behavioral of Adjust_Clock_4_buttens  is

    signal button1_r : std_logic_vector(2 downto 0);
    signal button2_r : std_logic_vector(2 downto 0);
     signal button3_r : std_logic_vector(2 downto 0);
     signal button4_r : std_logic_vector(2 downto 0);

--    signal minutes_total  : unsigned(5 downto 0) := (others => '0');
--   signal houres_total  : unsigned(4 downto 0) := (others => '0');

     signal minutes_total  : unsigned(5 downto 0);
     signal houres_total  : unsigned(4 downto 0);

begin

    process(clk)
    begin

        if (rising_edge(clk) )then

                minutes_total<=unsigned(minutes);
                houres_total<=unsigned(houres);   

                 -- Shift the value of button in button_r
            -- The LSB is unused and is there solely for metastability
            button1_r <= button1_r(button1_r'left-1 downto 0) & minutes_plus;
            button2_r <= button2_r(button2_r'left-1 downto 0) & minutes_minus;
                button3_r <= button3_r(button3_r'left-1 downto 0) & houres_plus;                
                button4_r <= button4_r(button4_r'left-1 downto 0) & houres_minus;   


            if button1_r(button1_r'left downto button1_r'left-1) = "01" then -- Button1 rising --button1_r[2:1]
                minutes_total <= (minutes_total + 1);
                     LED_0<='1';LED_1<='0';LED_2<='0';LED_3<='0';

            elsif button2_r(button2_r'left downto button2_r'left-1) = "01" then -- Button2 rising --button1_r[2:1]
               minutes_total <= (minutes_total-1 );
                    LED_0<='0';LED_1<='1';LED_2<='0';LED_3<='0';
            end if;


            if button3_r(button3_r'left downto button3_r'left-1) = "01" then -- Button1 rising --button1_r[2:1]
                houres_total <= (houres_total + 1);
                     LED_0<='0';LED_1<='0';LED_2<='1';LED_3<='0';

            elsif button4_r(button4_r'left downto button4_r'left-1) = "01" then -- Button2 rising --button1_r[2:1]
                houres_total<= (houres_total-1 );
                     LED_0<='0';LED_1<='0';LED_2<='0';LED_3<='1';
            end if;

        end if;

    end process;

     output_minutes <= std_logic_vector(minutes_total);
     output_houres <= std_logic_vector(houres_total);

end architecture behavioral ;

因此在这段代码中,我从另一个块中获得时间,当我尝试增加分钟和小时数时,问题就开始了,并且由于某种原因,它对按下按键没有反应。谁能解释为什么?

2 个答案:

答案 0 :(得分:0)

minutes_total <= unsigned(minutes);
在过程的内部和外部位于两行上,会生成多个行驱动程序,并且永远无法工作!
(没有阅读其余的代码,可能还有其他问题,例如数小时未读e)

现在它已经在流程中了,您需要将minutes_total重命名为minute_source,否则您将仅在有按钮边缘的一个时钟周期内递增该值!

答案 1 :(得分:0)

问题可能是您的进程的敏感度列表中仅包含时钟。尝试在灵敏度列表中添加按钮,因为它们会驱动您的if条件。 (不确定这是否是问题,但我认为值得尝试)