APPLICATION NOTES: Provided by: Tyler Brandon, Chris Blasko, Kevin Lister. This file contains a PS/2 Mouse controller. It should be noted that while this code is mostly functioning, all of the bugs have not been worked out. So if you need a template these programs are a good place to start. Also, as the program is developed the newer versions will be posted to the Application notes. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -- m2.vhd (PS/2 mouse code) -- -- compiles without errors -- Does not produce the correct results when hooked up to the Altera Board -- -- Under construction -- By Tyler Brandon, Chris Blasko, Kevin Lister -- U of Alberta -- library ieee; use ieee.std_logic_1164.ALL; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity m2 is port( Clock : in std_logic; --system clock (pin 91), 25.175MHz mouse_data : in std_logic; --data from the PS/2 mouse (pin 31) mouse_clk : in std_logic; --Clock from the PS/2 mouse (pin 30) --MouseX : buffer std_logic_vector(9 downto 0); --current X position of mouse --MouseY : buffer std_logic_vector(8 downto 0); --current Y position of mouse MouseL : out std_logic; MouseR : out std_logic ); --Left mouse button end m2; architecture behavior of m2 is --signal IncommingDataDetected : std_logic; --Set, when start bit of packet found signal data : std_logic_vector(34 downto 0); --Data from the mouse data packet signal clkCounter : integer range 0 to 1007; signal waitCounter : integer range 0 to 1800; --Division of the clock signal reciving_data : std_logic; begin process( Clock ) begin if rising_edge( Clock ) then if mouse_clk = '1' then waitCounter <= waitCounter + 1; else reciving_data <= '1'; waitCounter <= 0; end if; if waitCounter > 1762 then --if 70us has passed without the mouse_clk --going low, then re-synchronize the system reciving_data <= '0'; waitCounter <= 0; end if; end if; end process; process (mouse_clk) variable NumDataBits : integer range 0 to 34; --Number of bits captured begin if (mouse_clk'EVENT and mouse_clk = '1') then if reciving_data = '1' then data(NumDatabits) <= mouse_data; NumDatabits := NumDatabits + 1; if NumDatabits = 33 then MouseL <= data(1); MouseR <= data(2); end if; else NumDatabits := 0; end if; end if; end process; -- if reset = '0' then --MouseL <= '0'; --mouse button not pressed -- mouse_clk <= '1'; -- NumDatabits <= 0; --Starting coordinates -- MouseX <= START_X; --place mouse initially in 2nd column -- MouseY <= START_Y; --place mouse initially in 3rd row -- elsif NumDatabits <= 33 then -- clkCounter <= clkCounter + 1; -- if clkCounter = 504 then -- mouse_clk <= '1'; -- data(NumDatabits) <= MouseData; -- NumDatabits <= NumDatabits + 1; -- elsif clkCounter = 1007 then -- clkCounter <= 0; -- mouse_clk <= '0'; -- end if; -- else -- waitCounter <= waitCounter + 1; -- if waitCounter = 386352 then -- NumDatabits <= 0; -- waitCounter <= 0; -- end if; -- MouseL <= data(1); -- end if; -- end if; -- end process; end behavior;