|
发表于 2010-5-19 17:29:43
|
显示全部楼层
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity counter is
port(clk,reset,slt :in std_logic;
output :out std_logic_vector(19 downto 0));
end counter;
architecture behav of counter is
begin
process(clk,reset,slt)
variable d :integer range -1 to 1;
variable CNT :integer range -524287 to 524287 ;
begin
if(slt = '1') then
d := 1;
else
d := -1;
end if;
if(reset ='1') then
CNT := 0;
else
if(clk'event and clk = '1') then
CNT := CNT + d;
else
CNT:=CNT;
end if;
end if;
output <= conv_std_logic_vector(CNT,20);
end process;
end behav; |
|