需要我的vhdl代码的建议吗
我正在做我的大学项目——altera板上的数字时钟。我面临的问题是我的工作时间从24小时变为29小时!我使用整数类型表示我的小时数,右数字范围为0到9;我得到了if语句,当我的小时数左边的数字是2,小时数右边的数字是3,我想要我的第二个,分钟和小时00:00:00。。但它没有实现为什么?需要一些建议。。。谢谢需要我的vhdl代码的建议吗,vhdl,Vhdl,我正在做我的大学项目——altera板上的数字时钟。我面临的问题是我的工作时间从24小时变为29小时!我使用整数类型表示我的小时数,右数字范围为0到9;我得到了if语句,当我的小时数左边的数字是2,小时数右边的数字是3,我想要我的第二个,分钟和小时00:00:00。。但它没有实现为什么?需要一些建议。。。谢谢 这是我的密码: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_
这是我的密码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity master is
port(
clk : in std_logic;
hrs_lft : out std_logic_vector(1 downto 0 );
hrs_rght : out std_logic_vector(3 downto 0 );
min_lft : out std_logic_vector(2 downto 0 );
min_rght : out std_logic_vector(3 downto 0 );
second_lft: out std_logic_vector(2 downto 0);
second_rght : out std_logic_vector( 3 downto 0)
);
end master;
architecture bhv of master is
signal second_lft_int : integer range 0 to 5;
signal second_rght_int : integer range 0 to 9;
signal min_lft_int : integer range 0 to 5;
signal min_rght_int : integer range 0 to 9;
signal hrs_lft_int : integer range 0 to 2;
signal hrs_rght_int : integer range 0 to 9;
begin
process(clk)
begin
if (rising_edge(clk)) then
second_rght_int <= second_rght_int + 1;
if second_rght_int = 9 then
second_lft_int <= second_lft_int + 1;
second_rght_int <= 0;
if second_lft_int = 5 then
second_lft_int <= 0;
min_rght_int <= min_rght_int + 1;
if min_rght_int = 9 then
min_lft_int <= min_lft_int + 1;
min_rght_int <= 0;
if min_rght_int = 5 then
hrs_rght_int <= hrs_rght_int + 1;
min_rght_int <= 0;
if hrs_rght_int = 9 then
hrs_lft_int <= hrs_lft_int + 1;
if (hrs_rght_int = 3 and hrs_lft_int = 2) then
hrs_lft_int <= 0;
hrs_rght_int <= 0;
min_lft_int <= 0;
min_rght_int <= 0;
second_rght_int <= 0;
second_lft_int <= 0;
end if ;
end if;
end if;
end if;
end if;
end if;
end if;
end process;
second_rght<= std_logic_vector(to_unsigned(second_rght_int,second_rght'length));
second_lft<=std_logic_vector(to_unsigned(second_lft_int,second_lft'length));
min_rght<= std_logic_vector(to_unsigned(min_rght_int,min_rght 'length));
min_lft <= std_logic_vector(to_unsigned(min_lft_int,min_lft'length));
hrs_rght<= std_logic_vector(to_unsigned(hrs_rght_int,hrs_rght 'length));
hrs_lft <= std_logic_vector(to_unsigned(hrs_lft_int,hrs_lft'length));
end bhv;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.std_logic_arith.all;
使用ieee.std_logic_unsigned.all;
使用ieee.numeric_std.all;
实体主控是
港口(
clk:标准逻辑中;
hrs_lft:输出标准逻辑向量(1到0);
hrs\u rght:输出标准逻辑向量(3到0);
最小lft:输出标准逻辑向量(2到0);
最小值:输出标准逻辑向量(3到0);
第二个逻辑向量:输出标准逻辑向量(2到0);
第二个参数:输出标准逻辑向量(3到0)
);
终端主机;
master的架构bhv是
信号秒数:整数范围0到5;
信号秒:整数范围0到9;
信号最小值:整数范围0到5;
信号最小值:整数范围0到9;
信号hrs_lft_int:整数范围0到2;
信号时间:整数范围0至9;
开始
过程(clk)
开始
如果(上升沿(clk)),则
第二,您的流程看起来不正确,所以我重新编写了它:
process (clk)
begin
if rising_edge(clk) then
if second_rght_int = 9 then
second_rght_int <= 0;
if second_lft_int = 5 then
second_lft_int <= 0;
if min_rght_int = 9 then
min_rght_int <= 0;
if min_lft_int = 5 then
min_lft_int <= 0;
if (hrs_lft_int = 2 and hrs_rght_int = 4)
or hrs_rght_int = 9 then
hrs_rght_int <= 0;
if hrs_lft_int = 2 then
hrs_lft_int <= 0;
else
hrs_lft_int <= hrs_lft_int + 1;
end if;
else
hrs_rght_int <= hrs_rght_int + 1;
end if;
else
min_lft_int <= min_lft_int + 1;
end if;
else
min_rght_int <= min_rght_int + 1;
end if;
else
second_lft_int <= second_lft_int + 1;
end if;
else
second_rght_int <= second_rght_int + 1;
end if;
end if;
end process;
过程(clk)
开始
如果上升沿(clk),则
如果second_rght_int=9,则
第二个愚蠢的问题…但是如果你的hrs是0到4之间的整数…那么18:00应该怎么发生呢?编辑:我的意思是你的复制/粘贴代码是这样的,尽管你的描述是这样的。而且,你的代码没有重置,所以像“if second\u lft\u int=5”这样的语句大胆地假设值总是0..5。但实际上,3位向量的值很容易接近6。这是resets->在开始时有一个已知状态的第一个原因。@JarnoNurminen这段代码似乎有很多同步重置(零的赋值)。这也是我喜欢的。请正确缩进你的代码。正如目前编写的那样,if
语句的嵌套很难理解,很可能是错误。请出示您的测试台。@Martin,很抱歉,我在代码中没有看到任何重置?有些赋值为零,但它们不符合重置的定义。例如,如果second_rght_int不是9,则不会对其他信号进行赋值。但是缩进很可怕,因此代码无法读取。谢谢您,先生,@user1155120