[求助]大家帮忙看看,流水灯程序为什么下载后所有的灯全亮了?
大家好,我刚刚学习VHDL,今天写了一个小程序,开始程序里有reset信号的时候程序运行正常,可是当我去掉reset信号的时候所有的LED灯全亮了,到底是程序哪里出现问题了?程序如下:
--库函数声明及调用
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--实体定义
entity led is
port(clk,reset:in std_logic; --,reset
led8: out std_logic_vector(7 downto 0));
end led;
--结构体
architecture one of led is
signal num : std_logic_vector(7 downto 0):="11111110";
signal clock:std_logic;
begin
--分频进程
--分频后的值:50000000/5000/2000=5HZ
process(clk)
variable cnt1 : integer range 0 to 5000;
variable cnt2 : integer range 0 to 1000;
begin
if clk'event and clk='1' then
if cnt1=5000 then
cnt1:=0;
if cnt2=1000 then
cnt2:=0;
clock<=not clock;
else
cnt2:=cnt2+1;
end if;
else
cnt1:=cnt1+1;
end if;
end if;
end process;
--移位操作
--process(clock) --reset,
process(clock)
begin
-- if reset='0' then
-- num<="11111110";
if clock'event and clock='1' then
num(7 downto 1) <= num(6 downto 0);
num(0) <= num(7);
end if;
end process;
led8<=num;
end one; num 复位后是多少?如果是0,那复位完后当然是全亮。 回复【1楼】usingavr
num 复位后是多少?如果是0,那复位完后当然是全亮。
-----------------------------------------------------------------------
怎么查看num复位后是多少啊 ?补充一下,如果我把第二个进程去掉,那LED显示的就是正常的(一个亮) 主要原因是去掉reset后num初始为0,00000000移位还是0000000 所以全亮 一般基于SRAM的FPGA上电后触发器输出为0
还是应该把复位的语句加上
PROCESS(clock, reset)
BEGIN
IF reset='0' THEN
num <= '11111110';
ELSIF clock'EVENT AND clock='1' THEN
.......................... 回复【楼主位】kai102910202
-----------------------------------------------------------------------
应该加上复位语句 随便写个当然不一定这样
--库函数声明及调用
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--实体定义
entity led is
port(clk:in std_logic; --,reset
led8: out std_logic_vector(7 downto 0));
end led;
--结构体
architecture one of led is
signal num : std_logic_vector(7 downto 0);
signal clock:std_logic;
begin
--分频进程
--分频后的值:50000000/5000/2000=5HZ
process(clk)
variable cnt1 : integer range 0 to 5000;
variable cnt2 : integer range 0 to 1000;
begin
if clk'event and clk='1' then
if cnt1=5000 then
cnt1:=0;
if cnt2=1000 then
cnt2:=0;
clock<=not clock;
else
cnt2:=cnt2+1;
end if;
else
cnt1:=cnt1+1;
end if;
end if;
end process;
--移位操作
process(clock)
variable cnt3 : integer range 0 to 8;
begin
if clock'event and clock='1' then
if(cnt3=8)then
cnt3:=0;
else
cnt3:=cnt3+1;
end if;
case cnt3 is
when 0 =>num<="00000000";
when 1 =>num<="11111110";
when 2 =>num<="11111101";
when 3 =>num<="11111011";
when 4 =>num<="11110111";
when 5 =>num<="11101111";
when 6 =>num<="11011111";
when 7 =>num<="10111111";
when 8 =>num<="11111111";
end CASE;
end if;
end process;
led8<=num;
end one; 回复【3楼】40130064
主要原因是去掉reset后num初始为0,00000000移位还是0000000 所以全亮
-----------------------------------------------------------------------
确实是这样,但是为什么不加reset,num初始就是0呢?这个不懂,还有就是当把两个if调换位置也不行,不可思议啊! signal num : std_logic_vector(7 downto 0):="11111110";
:="11111110"; 这个只对仿真有用,综合时是无法设置目标硬件加电时的初始值的,心里明白就行了。
也就是说:="11111110";这种语句能不用就不用,麻烦。
页:
[1]