1.
signal cnt : integer range 0 to 8;
elsif clk'event and clk = '1' then
if cnt = 8 then
cnt <= 0;
led <= '1';
else
cnt <= cnt + 1;
led <= '0';
end if;
end if;
2.
signal cnt : integer range 0 to 7;
elsif clk'event and clk = '1' then
if cnt = 7 then
cnt <= cnt + 1;
led <= '1';
else
cnt <= cnt + 1;
led <= '0';
end if;
end if;
表面上你用的是integer,其实在芯片内部还是将其转换为二进制来实现。
建议你的程序这么改:
signal cnt : integer range 0 to 7;
elsif clk'event and clk = '1' then
if cnt = 7 then
cnt <= 0;
led <= '1';
else
cnt <= cnt + 1;
led <= '0';
end if;
end if;
好的。
1。
entity test is
port(
clk : in std_logic;
nrst : in std_logic;
led : out std_logic
);
end test;
architecture RTL of test is
signal cnt : integer range 0 to 7;
begin
process(clk,nrst)
begin
if nrst = '0' then
cnt <= 0;
led <= '0';
elsif clk'event and clk = '1' then
if cnt = 7 then
led <= '1';
cnt <= cnt + 1;
else
cnt <= cnt + 1;
led <= '0';
end if;
end if;
end process;
end RTL;
2.
entity test is
port(
clk : in std_logic;
nrst : in std_logic;
led : out std_logic
);
end test;
architecture RTL of test is
signal cnt : integer range 0 to 8;
begin
process(clk,nrst)
begin
if nrst = '0' then
cnt <= 0;
led <= '0';
elsif clk'event and clk = '1' then
if cnt = 8 then
led <= '1';
cnt <= 0;
else
cnt <= cnt + 1;
led <= '0';
end if;
end if;
end process;
signal cnt : integer range 0 to 7;
elsif clk'event and clk = '1' then
if cnt = 7 then
cnt <= 0;
led <= '1';
else
cnt <= cnt + 1;
led <= '0';
end if;
end if;
原来应该是这样,呵呵,仿真结果和
if cnt = 7 then
cnt <= cnt + 1;
led <= '1';
是一样的,但是肯定是上面一种写法好,但是我还是想知道如果采用下面一种写法,FPGA内部逻辑实现是不是有可能出错呢?
呵呵,一点疑惑,万分感谢!