|
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity count is
port(
clk:in std_logic;
freq_in:in std_logic;
en_in:in std_logic;
count_out:out std_logic_vector(3 downto 0));
end count;
architecture ari of count is
signal en_num:std_logic_vector(2 downto 0):="000";
signal count_temp:std_logic_vector(18 downto 0);
signal count_num:integer range 0 to 1000;
signal q1,reply_ok:std_logic:='0';
--signal q2:std_logic:=0;
begin
count:process(clk)
begin
if (clk='1' and clk'event )then
if(count_num =count_num'high)then
q1<='1';--count is up ,stop test
else
count_temp<=count_temp+1;
end if;
if(reply_ok ='1' and en_num ="000")then -- the data is carry out start testing again
q1 <='0';
count_temp<=(others=>'0');
end if;
end if;
end process;
process(freq_in)
begin
if(freq_in='1' and freq_in'event) then
if(count_num < count_num'high ) then
count_num<=count_num+1;
end if;
if(en_num = "000" and reply_ok ='1')then
count_num <=0;
end if;
if(en_num > "000" )then
reply_ok <= '1';
else
reply_ok <= '0';
end if;
end if;
end process;
process(en_in)
begin
if( en_in'event and en_in='1' )then
en_num<=en_num+1;
end if;
end process;
process(en_in)
begin
if (en_in='1' and en_in'event )then
case en_num is
when "001"=>count_out(3 downto 0)<=('0' &count_temp(18 downto 16));
when "010"=>count_out(3 downto 0)<=count_temp(15 downto 12);
when "011"=>count_out(3 downto 0)<=count_temp(11 downto 8);
when "100"=>count_out(3 downto 0)<=count_temp(7 downto 4);
when "101"=>count_out(3 downto 0)<=count_temp(3 downto 0);
when others=>
end case;
end if;
end process;
end ari;
count_out是送给单片机
count_num是要计频率的脉冲个数
count_temp是总的计1000次时的糸统脉冲
CPLD是用有限的10M晶振
设计思路:固定计1000(count_num)个freq_in求得系统脉冲(count_temp)的个数.1/10M
程序出来后结果乱跳
大家救急啊.再做不出来,就要走人了.!!!老板的脸色一天比一天难看了
程序怪得很.一开始是可以的.后来就不行了. |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|