|
楼主 |
发表于 2010-6-9 11:32:19
|
显示全部楼层
--计数器
--rst复位控制低电平有效;
--en使能控制高电平有效;
--up加/减控制,高电平加法,低电平减法。
--sum为计数输出;cout为进位输出。
--**************库定义、 包定义********************
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
--**************实体定义********************
Entity counter is
Port(clk,rst,en,up: in std_logic;
Sum: out std_logic_vector(2 downto 0);
Cout: out std_logic;
red : out std_logic
);
End counter;
--**************构造体定义********************
Architecture a of counter is
Signal count: std_logic_vector(2 downto 0);
signal clock : std_logic;
Begin
red<='1';
process(clk)--分频进程
variable cnt1 : integer range 0 to 5000;
variable cnt2 : integer range 0 to 2000;
begin
if clk'event and clk='1' then
if cnt1=5000 then
cnt1:=0;
if cnt2=2000 then
cnt2:=0;
clock<=not clock;
else
cnt2:=cnt2+1;
end if;
else
cnt1:=cnt1+1;
end if;
end if;
end process;
Process(clock,rst)--计数器进程
Begin
If rst='0' then
Count<=(others=>'0');
Elsif rising_edge(clock) then
If en='1' then
Case up is
When '1' => count<=count+1;
When others =>count<=count-1;
End case;
End if;
End if;
End process;
Sum<=not count;--数据输入反逻辑
Cout <='0' when en='1' and ((up='1' and count=7) or (up='0' and count=0)) else '1';--进位输出
End;
以上基于VHDL的计数器程序,想利用MODELSIM仿真,遇到点问题,请高手帮忙!
首先是分频功能步能实现
1、 给clk设为时钟驱动后,分频后CLOCK一直步变?怎么对CLOCK进行初始化?
2、 如何使用图像激励进行这个程序的仿真
3、 正在学TESTBENCH ,如可以请给出这个程序的测试激励
截图没发上来 |
|