-------------------------------------------------------------------------------- -- Copyright (c) 1995-2011 Xilinx, Inc. All rights reserved. -------------------------------------------------------------------------------- -- ____ ____ -- / /\/ / -- /___/ \ / Vendor: Xilinx -- \ \ \/ Version : 13.4 -- \ \ Application : -- / / Filename : xil_5680_39 -- /___/ /\ Timestamp : 11/25/2013 08:21:00 -- \ \ / \ -- \___\/\___\ -- --Command: --Design Name: -- library ieee; use ieee.std_logic_1164.ALL; use ieee.numeric_std.ALL; library UNISIM; use UNISIM.Vcomponents.ALL; entity Touchcontroll is port ( clk : in std_logic; Data_in_tp : in std_logic; PENIRQ : in std_logic; Reset : in std_logic; Busy : in std_logic; Dclk : out std_logic; CS : out std_logic; Data_out_tp : out std_logic; go_ZSK : out std_logic; hour_glass_button : out std_logic; LED : out std_logic_vector(5 downto 0); Start_button : out std_logic); end Touchcontroll; architecture BEHAVIORAL of Touchcontroll is type state is (idle,learnx,convx,hold); signal current_state, next_state : state; ---------------------------------------------------- -- --constants used for Data to Touch -- ---------------------------------------------------- constant S : std_logic := '1'; constant MulX:std_logic_vector(2 downto 0):="101";--A0|A1|A2 constant MulY:std_logic_vector(2 downto 0):="100";--A0|A1|A2 constant Mode: std_logic:= '1';--1=8bit constant SER_DFR: std_logic:= '0'; constant PD : std_logic_vector(1 downto 0):= "00";--PD0,PD1 signal dinx2 : unsigned (15 downto 0); -- for the samples in X signal diny : unsigned (15 downto 0); -- for the samplea in Y signal doutx : unsigned (7 downto 0); -- for Data x signal douty : unsigned (7 downto 0); -- for Data y signal doclk : std_logic; signal qdclk : unsigned (4 downto 0); signal qdin : natural range 0 to 8; -- counter (used like "pointer" in C) points at the doutx/douty position of count status signal qdout: natural range 0 to 15; -- same for dinx/diny signal qdelay : unsigned (15 downto 0); -- counter for delay time signal start : std_logic; -- signals for toggling outputs signal hourglass : std_logic; -- same signal Zsk: std_logic;-- same signal ffs: std_logic; -- sync. flipflop signal dclk_aktiv : std_logic; -- brings up Dclk when needed begin doutx <= unsigned(PD & SER_DFR & Mode & MulX & S); douty <= unsigned(PD & SER_DFR & Mode & MulY & S); Status : Process(clk,Reset,next_state) begin if Reset = '1' then current_state <= idle; elsif rising_edge(clk) then current_state <= next_state; end if; end Process; --------------------------------------------------- --Div the clk from 100MHz to 2MHz --locks the output Dclk till ADC request Data (learn and conv stats) -- ---------------------------------------------------- clk_div : Process(clk,Reset,dclk_aktiv) begin if Reset = '1' then qdclk <= (others => '0'); doclk <= '0'; elsif rising_edge(clk) then if dclk_aktiv = '1' then if qdclk = "11000" then --24 doclk <= not doclk; qdclk <= (others => '0'); else qdclk <= qdclk +1; end if; else doclk <= '0'; end if; end if; end Process; ---------------------------------------------------- --Time delay to avoid buncing by touching -- -- ---------------------------------------------------- wait_a_sec : Process (clk,Reset,PENIRQ) begin if Reset = '1' then qdelay <= (others => '0'); elsif rising_edge(clk) then if PENIRQ = '0' then qdelay <= qdelay+1; else qdelay <= (others => '0'); end if; end if; end Process; el_statos_machinos : Process(current_state,PENIRQ,doclk,qdin,qdelay,doutx,busy) begin case(current_state) is ---------------------------------------------------- -- state idle: wait for touch on screen -- -- ---------------------------------------------------- when idle =>CS <='1'; Data_out_tp <= '0'; ffs <= '0'; dclk_aktiv <= '0'; qdin <= 0; qdout <= 15; dinx2 <= (others => '0'); diny <= (others => '0'); if PENIRQ = '0' then if qdelay = "1111111111111111" then -- delay try to avoid multipli touch by pressing once next_state <= learnx; else next_state <= idle; end if; else next_state <= idle; end if; start_button <= '1'; -- are routed to LED's to see wich satus is reached hour_glass_button <= '0';-- same ---------------------------------------------------- -- satus learnx: teach the ADC which Coordinate i want to sample -- Data from falling_edge to falling_edge of Dclk -- --==Data1===>|<===Data2=====>|<=====Data3 (Data to touch) -- _______| _______| --___| |_______| |_____ (Dclk) --must be seriell....... ---------------------------------------------------- when learnx => CS <= '0'; qdout <= 15; ffs <= '0'; dclk_aktiv <= '1'; dinx2 <=(others => '0'); diny <= (others => '0'); if qdin <= 7 and Busy = '0' then Data_out_tp <= doutx(qdin); else Data_out_tp <= '0'; end if; if falling_edge(doclk) then if Busy = '0' then qdin <= qdin+1; else qdin <= 0; end if; if qdin >= 7 then next_state <= convx; else next_state <= learnx; end if; end if; start_button <= '0'; hour_glass_button <= '0'; ---------------------------------------------------- -- status convx: request sampled data -- Data comes in seriell tried to bring it to a vector -- everytime on rising_edge of dclk -- --==Sample1=====>|<=======Sample2=========>|<========Sample3=========>| (Samples from Touch) -- _________| _____________| ____________| --_____| |___________| |_____________| |__ (Dclk) -- --_____|<====== Data1 ======>|<===== Data2 =============>|<========Data3=== (Data read in) -- convert from seriell to parallel ---------------------------------------------------- when convx => CS <= '0'; qdin <= 0; Data_out_tp <= '0'; diny <= (others => '0'); dclk_aktiv <= '1'; if rising_edge(doclk) then if Busy = '0' then qdout <= qdout-1; ffs <= Data_in_tp; dinx2(qdout) <= ffs;-- sync read in, ffs to avoid metastability end if; elsif falling_edge(doclk) then if qdout = 0 then next_state <= hold; else next_state <= convx; end if; end if; start_button <= '0'; hour_glass_button <= '0'; ---------------------------------------------------- --same as learnx just for Y-coordinate -- -- ---------------------------------------------------- -- when learny => CS <= '0'; -- qdout <= 15; -- ffs <= '0'; -- dclk_aktiv <= '1'; -- dinx2 <=(others => '0'); -- diny <= (others => '0'); -- if qdin <= 7 and Busy = '0' then -- Data_out_tp <= douty(qdin); -- else -- Data_out_tp <= '0'; -- end if; -- if falling_edge(doclk) then -- if Busy = '0' then -- qdin <= qdin+1; -- else -- qdin <= 0; -- end if; -- if qdin >= 7 then -- next_state <= convy; -- else -- next_state <= learny; -- end if; -- end if; -- start_button <= '0'; -- hour_glass_button <= '0'; ---------------------------------------------------- -- same as convx just for Y-sampling -- -- ---------------------------------------------------- -- when convy => CS <= '0'; -- qdin <= 0; -- Data_out_tp <= '0'; -- dinx2 <= (others => '0'); -- dclk_aktiv <= '1'; -- if rising_edge(doclk) then -- ffs <= Data_in_tp; -- diny(qdout) <= ffs;-- sync read in, ffs to avoid metastability -- if Busy = '0' then -- qdout <= qdout-1; -- end if; -- elsif falling_edge(doclk) then -- if qdout = 0 then -- next_state <= hold; -- else -- next_state <= convy; -- end if; -- end if; -- start_button <= '0'; -- hour_glass_button <= '0'; ---------------------------------------------------- -- status hold: for holding till touch on screen is released -- -- ---------------------------------------------------- when hold => CS <= '1'; qdin <= 0; qdout <= 15; ffs <= '0'; Data_out_tp <= '0'; dclk_aktiv <= '0'; -- dinx2 <= (others => '0'); diny <= (others => '0'); if PENIRQ = '1' then next_state <= idle; else next_state <= hold; end if; start_button <= '0'; hour_glass_button <= '1'; when others => NULL; end case; end Process; ---------------------------------------------------- -- -- -- ---------------------------------------------------- xy : Process(clk,Reset,dinx2,zsk) begin if Reset ='1' then zsk <= '0'; elsif rising_edge(clk) then if dinx2(15 downto 4) >= "111101100000" then zsk <= not zsk; end if; end if; end Process; ---------------------------------------------------- -- -- -- ---------------------------------------------------- LED(5 downto 0) <= STD_LOGIC_VECTOR(dinx2(9 downto 4)); -- to see if a Sample was read in Dclk <= doclk; -- dclk for touch go_ZSK <= zsk; end BEHAVIORAL;