搜索
bottom↓
回复: 8

[求助]大家帮忙看看,流水灯程序为什么下载后所有的灯全亮了?

[复制链接]

出0入0汤圆

发表于 2011-9-2 09:43:51 | 显示全部楼层 |阅读模式
大家好,我刚刚学习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;

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2011-9-2 10:24:03 | 显示全部楼层
num 复位后是多少?如果是0,那复位完后当然是全亮。

出0入0汤圆

 楼主| 发表于 2011-9-2 10:34:04 | 显示全部楼层
回复【1楼】usingavr
num 复位后是多少?如果是0,那复位完后当然是全亮。
-----------------------------------------------------------------------

怎么查看num复位后是多少啊 ?补充一下,如果我把第二个进程去掉,那LED显示的就是正常的(一个亮)

出0入0汤圆

发表于 2011-9-2 10:44:10 | 显示全部楼层
主要原因是去掉reset后num初始为0,00000000移位还是0000000 所以全亮

出0入0汤圆

发表于 2011-9-2 10:44:20 | 显示全部楼层
一般基于SRAM的FPGA上电后触发器输出为0

还是应该把复位的语句加上
PROCESS(clock, reset)
BEGIN
    IF reset='0' THEN
        num <= '11111110';
    ELSIF clock'EVENT AND clock='1' THEN
..........................

出0入0汤圆

发表于 2011-9-2 11:05:15 | 显示全部楼层
回复【楼主位】kai102910202  
-----------------------------------------------------------------------

应该加上复位语句

出0入0汤圆

发表于 2011-9-2 11:23:06 | 显示全部楼层
随便写个当然不一定这样


--库函数声明及调用
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;

出0入0汤圆

 楼主| 发表于 2011-9-2 22:30:43 | 显示全部楼层
回复【3楼】40130064
主要原因是去掉reset后num初始为0,00000000移位还是0000000 所以全亮
-----------------------------------------------------------------------
确实是这样,但是为什么不加reset,num初始就是0呢?这个不懂,还有就是当把两个if调换位置也不行,不可思议啊!

出0入0汤圆

发表于 2011-9-3 08:42:03 | 显示全部楼层
signal num : std_logic_vector(7 downto 0):="11111110";

:="11111110"; 这个只对仿真有用,综合时是无法设置目标硬件加电时的初始值的,心里明白就行了。

也就是说:="11111110";这种语句能不用就不用,麻烦。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 13:24

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表