4631|2

2

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

关于走马灯语言的一些小细节(VHDL语言) [复制链接]

小弟FPGA初学者,最近研究走马灯程序时候发现有些VHDL语言的细节有些问题,希望同窗们,高手们给予解答。

首先附上程序的详细信息(此程序正确,在21eda所产fpga进行过测试)

先说说说这个程序的原理:这个跑马灯是6个led灯的(因为测试版的限制)。用一个control信号控制跑马灯的4种工作方式,1全亮2轮流亮3从中间向两边亮,也就是幕布式的4全灭。然后用一个模6计数器控制2工作方式,用一个模3计数器控制3工作方式

具体程序如下:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

entity led is

port(

clk,clear:in std_logic;           --系统的时钟信号,由于板子上的信号频率太高,下面还有分频的步骤。

control:in std_logic_vector(1 downto 0);  --控制信号

q:out std_logic_vector(5 downto 0);  --led灯的控制信号

);

end entity;

architecture exp of led is

signal count_temp1:std_logic_vector(3 downto 0);   --模6计数器的信号

signal count_temp2:std_logic_vector(1 downto 0);   --模4计数器的信号

signal q_temp:std_logic_vector(5 downto 0);   --led灯的中间信号

signal flag1:std_logic;

signal flag2:std_logic;

signal clk1:std_logic;--分频之后的脉冲信号

begin

process(clk)                  --分频的进程

variable count :integer range 0 to  9999999;

begin

if clk'event and clk='1' then

if count<=4999999 then

clk1<='0;'

elsif count>4999999 and clk<9999999 then

clk1<='1';

count:=count+1;

else clk1<='0';

end if;

end if;

end process;     --分频的进程

process(clk1,clear,q_temp)
begin
if clk1'event and clk1='1' then
if count_temp1="000"then
flag1<='0';
elsif count_temp1="101" then
flag1<='1';
end if;
if flag1='0' then
count_temp1<=count_temp1+1;
else
count_temp1<=count_temp1-1;
end if;
if count_temp2="00"then
flag2<='0';
elsif count_temp2="10" then
flag2<='1';
end if;
if flag2='0' then
count_temp2<=count_temp2+1;
else count_temp2<=count_temp2-1;
end if;
end if;
case control is
when "00"=>q_temp<="111111";
when "11"=>q_temp<="000000";
when "01"=>
case count_temp1 is
when "000"=>q_temp<="111110";
when "001"=>q_temp<="111101";
when "010"=>q_temp<="111011";
when "011"=>q_temp<="110111";
when "100"=>q_temp<="101111";
when "101"=>q_temp<="011111";
when others=>q_temp<="111111";
end case;
when "10"=>
case count_temp2 is
when "00"=>q_temp<="110011";
when "01"=>q_temp<="101101";
when "10"=>q_temp<="011110";
when others=>q_temp<="111111";
end case;
when others=>q_temp<="111111";
end case;
if clear='0' then
q_temp<="111111";
end if ;
end process;
q<=q_temp;
end architecture;

这个就是完整的程序,在看程序的时候,突发奇想想把蓝色的那个部分化简一下成为

if count_temp1="000"then
count_temp1<=count_temp1+1;
elsif count_temp1="101" then
count_temp1<=count_temp1-1;
end if;

这样可以省去红字部分的 flag1.2信号但验证结果是不行的,想不出原因来,希望得到大家的帮助

 

 

 

此帖出自FPGA/CPLD论坛

最新回复

process(clk1,clear,q_temp)beginif clk1'event and clk1='1' thenif count_temp1="000"thenflag1<='0';elsif count_temp1="101" thenflag1<='1';end if;if flag1='0' thencount_temp1<=count_temp1+1;else count_temp1<=count_temp1-1;end if;---- end if; end process;   上面这个部分蓝色的部分表达意思,通过电路可以产生的效果: 当count_temp1="000" 时,flag1='0'一直有效,持续5个时钟周期,使count_temp1计数到“101”; 同理 当count_temp1="101"时,flag1='1'一直有效,持续5个时钟周期,使count_temp计数到“000”;   如果修改为   if count_temp1="000"thencount_temp1<=count_temp1+1;elsif count_temp1="101" thencount_temp1<=count_temp1-1;end if;   这个代码,上电开始后 ,count_temp1初始化为“000”,此时条件count_temp1="000"成立,则执行一次count_temp1<=count_temp+1; 使count_temp1="001", 以后count_temp1被锁死,永远不执行。   不知到,楼主看了上面的解释,你明白了吗?  详情 回复 发表于 2011-8-18 09:34
点赞 关注
 

回复
举报

6892

帖子

0

TA的资源

五彩晶圆(高级)

沙发
 

process(clk1,clear,q_temp)
begin
if clk1'event and clk1='1' then
if count_temp1="000"then
flag1<='0';
elsif count_temp1="101" then
flag1<='1';
end if;
if flag1='0' then
count_temp1<=count_temp1+1;
else
count_temp1<=count_temp1-1;
end if;
----

end if;

end process;

 

上面这个部分蓝色的部分表达意思,通过电路可以产生的效果:

count_temp1="000" 时,flag1='0'一直有效,持续5个时钟周期,使count_temp1计数到“101”;

同理 当count_temp1="101"时,flag1='1'一直有效,持续5个时钟周期,使count_temp计数到“000”;

 

如果修改为

 

if count_temp1="000"then
count_temp1<=count_temp1+1;
elsif count_temp1="101" then
count_temp1<=count_temp1-1;
end if;

 

这个代码,上电开始后 ,count_temp1初始化为“000”,此时条件count_temp1="000"成立,则执行一次count_temp1<=count_temp+1; 使count_temp1="001", 以后count_temp1被锁死,永远不执行。

 

不知到,楼主看了上面的解释,你明白了吗?

此帖出自FPGA/CPLD论坛

赞赏

1

查看全部赞赏

个人签名一个为理想不懈前进的人,一个永不言败人!
http://shop57496282.taobao.com/
欢迎光临网上店铺!
 
 

回复

2

帖子

0

TA的资源

一粒金砂(初级)

板凳
 

恩,明白了。谢谢指教,嘻嘻

 

此帖出自FPGA/CPLD论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表