⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ads7846a.vhd.bak

📁 四线电阻式触摸屏
💻 BAK
字号:
--采用延迟测量法来解决,即在接受到触摸屏笔中断时延时一段时间(30ms)后再测量,可消除抖动
--测量完后再次延迟一段时间(连击延时300ms)后打开笔中断,可避免连击现象的出现
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY ADS7846a IS
PORT(
     penirq,dout,busy,clk2mhz,clk1khz:IN STD_LOGIC;
     din,dclk:OUT STD_LOGIC;
     cs:buffer STD_LOGIC;
     xdout,ydout:OUT STD_LOGIC_VECTOR(11 DOWNTO 0));
END ADS7846a;

architecture behavioral of ads7846a is
type states is(reset,control,write_bit,read_bit,wait_300ms);--注:写控制字占一个时钟周期(control)
signal state:states:=reset;
signal flag,wait_flag:std_logic:='0';
signal pen:std_logic:='1';
signal write_cnt:integer range 0 to 7:=0;
signal read_cnt:integer range 0 to 15:=0;
signal cnt1:integer range 0 to 30:=0;
signal cnt2:integer range 0 to 300:=0;
signal dataoutx,dataouty:std_logic_vector(11 downto 0):=(others=>'0');
signal write_control:std_logic_vector(7 downto 0):=(others=>'0');
begin

process(clk1khz,penirq,state)
begin
if rising_edge(clk1khz)then
 if state=reset then  
  if penirq/='0'then cnt1<=0;
    elsif cnt1/=30 then cnt1<=cnt1+1;
      else cnt1<=0;
  end if;
 end if;
  if cnt2/=300 then cnt2<=cnt2+1;
  else cnt2<=0;
  end if;
end if;
end process;

process(state)
begin 
 case state is
  when reset=>if cnt1=30 then pen<='0';
              else pen<='1';
              end if;
  when wait_300ms=>if cnt2=300 then wait_flag<='0';
                   else wait_flag<='1';
                   end if;             
  when others=>pen<='1';wait_flag<='1';
 end case;
end process;

process(cs)
begin
if cs='0'then dclk<=clk2mhz;
else dclk<='0';
end if;
end process;

process(clk2mhz,state)
begin 
   if rising_edge(clk2mhz)then 
    case state is
      when reset=>if pen/='0'then cs<='1';state<=reset;
                   else state<=control;
                   end if;                  
      when control=>if flag='0'then write_control<="10010000";--ox90(flag='0')
                    else write_control<="11010000";--oxd0(flag='1')##
                    end if;
                    cs<='0';state<=write_bit;
      when write_bit=>case write_cnt is
                       when 0 to 3=>if write_control(7-write_cnt)='1'then din<='1';
                                    else din<='0';
                                    end if;
                                    write_cnt<=write_cnt+1;
                       when 4 to 6=>din<='0';write_cnt<=write_cnt+1;
					   when 7=>din<='0';write_cnt<=0;state<=read_bit;
					   end case;
	  when read_bit=>case read_cnt is
                       when 0 =>read_cnt<=read_cnt+1;
                       when 1 to 12=>if flag='0'then dataoutx(12-read_cnt)<=dout;read_cnt<=read_cnt+1;
                                     else dataouty(12-read_cnt)<=dout;read_cnt<=read_cnt+1;
                                     end if;
                       when 13 to 14=>read_cnt<=read_cnt+1;
                       when 15=>if flag='0'then state<=control;flag<='1';
                                else state<=wait_300ms;flag<='0';
                                end if;
                                read_cnt<=0;                    
                     end case;
      when wait_300ms=>if wait_flag='1'then state<=wait_300ms;cs<='1';
                       else state<=reset;
                       end if;
end case;
end if;
end process;

xdout<=dataoutx;
end;

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -