小弟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;
这个就是完整的程序,在看程序的时候,突发奇想想把
蓝 {MOD}的那个部分化简一下成为
if count_temp1="000"then
count_temp1<=count_temp1+1;
elsif count_temp1="101" then
count_temp1<=count_temp1-1;
end if;
这样可以省去红字部分的 flag1.2信号,但验证结果是不行的,想不出原因来,希望得到大家的帮助
此帖出自
小平头技术问答
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;
上面这个部分蓝 {MOD}的部分表达意思,通过电路可以产生的效果:
当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被锁死,永远不执行。
不知到,楼主看了上面的解释,你明白了吗?
恩,明白了。谢谢指教,嘻嘻
一周热门 更多>