LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
ENTITY liushuideng is
PORT(
clk:in STD_LOGIC;
led1:out STD_LOGIC_VECTOR(7 DOWNTO 0));
END liushuideng;
ARCHITECTURE light OF liushuideng IS
SIGNAL clk1,CLK2:std_logic;
BEGIN
P1:PROCESS (clk)
VARIABLE count:INTEGER RANGE 0 TO 999999;
BEGIN
IF clk'EVENT AND clk='1' THEN --当时钟脉冲上升沿到来时执行下面语句
IF count<=499999 THEN
clk1<='0'; --当count<=499999时divls=0并且count加1
count:=count+1;
ELSIF count>=499999 AND count<=999999 THEN --当ount>=499999 并且 count<=999998时
clk1<='1'; --
count:=count+1; --clk1=1并且count加1
ELSE count:=0; --当count>=499999时清零count1
END IF;
END IF;
END PROCESS ;
P3:PROCESS(CLK1)
begin
IF clk1'event AND clk1='1'THEN
clk2<=not clk2;
END IF;
END PROCESS P3;
---------------------------------------------------------
P2:PROCESS(clk2)
variable count1:INTEGER RANGE 0 TO 16; --定义的整型变量用做计数器
BEGIN --
IF clk2'event AND clk2='1'THEN --当时钟脉冲上升沿到来时执行下面语句
if count1<=16 then --当COUNT1<=9时执行下面语句
if count1=15 then --当COUNT1=8时,COUNT1清零
count1:=0; --
end if; --
CASE count1 IS --CASE语句给输出LED1赋值
WHEN 0=>led1<="11111110"; --依次点亮发光二极管
WHEN 1=>led1<="11111100"; --
WHEN 2=>led1<="11111000"; --
WHEN 3=>led1<="11110000"; --
WHEN 4=>led1<="11100000"; --
WHEN 5=>led1<="11000000"; --
WHEN 6=>led1<="10000000"; --
WHEN 7=>led1<="00000000";
WHEN 8=>led1<= "01111111"; --依次点亮发光二极管
WHEN 9=>led1<= "00111111"; --
WHEN 10=>led1<="00011111"; --
WHEN 11=>led1<="00001111"; --
WHEN 12=>led1<="00000111"; --
WHEN 13=>led1<="00000011"; --
WHEN 14=>led1<="00000001"; --
WHEN 15=>led1<="00000000"; -- --
WHEN OTHERS=>led1<="11111111"; --
END CASE;
count1:=count1+1;
end if;
end if;
end process;
END light;
初学VHDL,有个疑惑。如上面举的例子,clk这个信号时谁给的呢?这三个进程并发执行,只有当clk变化时才能导致clk1和clk2的变化。没有想明白这个clk是哪儿来的?
引用: 引用 2 楼 great_bug 的回复:
从外边来的信号.......
我现在似懂非懂的,我理解的是clk是始终信号,10ns为一个时钟周期.不知道对不对?
它是时钟没错,至于是什么频率,取决于你从外部给它送什么样的信号.
clk是接口,也就是外部的输入。看你的程序clk1好像是clk的一个分频
我也分频一般这么写
在architecture里声明一个signal
signal count:integer;
然后写一个process
process(clk)
begin
if(clk'event and clk= '1')then
if(counter > 50)then
clk1<=~clk1;
counter <= 0;
else
counter <= counter + 1;
end if;
end if;
end process;
代码没测试过,请你验证一下