library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity count is
port(
cs : in std_logic;
dclk : in std_logic;
datain : in std_logic;
dataout: out std_logic;
widthin: in std_logic
);
end ;
architecture one of count is
signal tempin: std_logic_vector(15 downto 0);
signal tempdout: std_logic;
--signal notdin: std_logic;
begin
control:process(tempin,cs,datain)
variable ct1,ct2,cnt : integer range 0 to 65535;
begin
if cs='0' then
if dclk'event and dclk='1' then
tempin(15)<=widthin;
tempin(14 downto 0)<=tempin(15 downto 1);
end if;
-- tempin<="0000000000000110";
tempdout<='0';
end if;
if cs='1'then
cnt:=(conv_integer(tempin));
if (ct1+ct2)=cnt then
tempdout<=not tempdout;
ct1:=0;
ct2:=0;
else
if datain'event and datain='1' then
ct1:=ct1+1;
end if;
if datain'event and datain='0' then
ct2:=ct2+1;
end if;
end if;
end if;
end process;
dataout<=tempdout;
--notdin<=not datain;
end;
这个程运行不稳定怎么回事。用单片机传一数过来,CPLD根据这个数对一个外部的编码器脉冲计数。计到传的这个数就翻转一个脚的输出。 |