Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company:
- -- Engineer:
- --
- -- Create Date: 10:57:21 01/17/2018
- -- Design Name:
- -- Module Name: deux_un_chombart_delannel - Behavioral
- -- Project Name:
- -- Target Devices:
- -- Tool versions:
- -- Description:
- --
- -- Dependencies:
- --
- -- Revision:
- -- Revision 0.01 - File Created
- -- Additional Comments:
- --
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- ---- Uncomment the following library declaration if instantiating
- ---- any Xilinx primitives in this code.
- --library UNISIM;
- --use UNISIM.VComponents.all;
- entity deux_un_chombart_delannel is
- Port ( SYS_CLK : in STD_LOGIC;
- DATA : in STD_LOGIC;
- CLK : in STD_LOGIC;
- X : out STD_LOGIC_VECTOR (7 downto 0);
- Y : out STD_LOGIC_VECTOR (7 downto 0);
- COLOR : out STD_LOGIC_VECTOR (1 downto 0);
- WRITE : out STD_LOGIC);
- end deux_un_chombart_delannel;
- architecture Behavioral of deux_un_chombart_delannel is
- --Signaux intermédiaires utilisés
- signal XX : STD_LOGIC_VECTOR (7 downto 0);
- signal YY : STD_LOGIC_VECTOR (7 downto 0);
- signal CCOLOR : STD_LOGIC_VECTOR(1 downto 0);
- signal movX, movY : STD_LOGIC;
- signal prevstat : STD_LOGIC := '0';
- signal WWRITE : STD_LOGIC := '0';
- signal ERROR : STD_LOGIC := '0';
- --Déclaration d'état
- type etat_sys is (waitingcontrol, control, waitingmovX, Xmov, waitingmovY, Ymov, endstate);
- signal etat_actuel : etat_sys := waitingcontrol;
- signal PositionComp : integer range 0 to 9;
- begin
- --Process d'écriture sur la sortie synchrone avec c le front montant de l'CLK système
- process(SYS_CLK)
- variable i : integer := 0;
- variable Xcomp : STD_LOGIC_VECTOR(7 downto 0) := "00000000";
- variable Ycomp : STD_LOGIC_VECTOR(7 downto 0) := "00000000";
- begin
- --Detection de front montant
- if(rising_edge(SYS_CLK)) then
- if(WWRITE = '1' and ERROR='0') then
- --WRITE de la COLOR
- COLOR<=CCOLOR;
- --Calcul de X (complémenté ou non)
- Xcomp:=XX;
- if(Xcomp(7)='1') then
- Xcomp(6 downto 0):="1111111";
- end if;
- Xcomp(7):='0';
- ---
- if(movX = '0') then
- Xcomp := not Xcomp;
- Xcomp := Xcomp + "00000001";
- end if;
- ---
- -- Calcul de Y (complémenté ou non)
- Ycomp:=YY;
- if(Ycomp(7)='1') then
- Ycomp(6 downto 0):="1111111";
- end if;
- Ycomp(7):='0';
- ---
- if(movY = '0') then
- Ycomp := not Ycomp;
- Ycomp := Ycomp + "00000001";
- end if;
- ---
- --WRITE de X et Y
- Y<=Ycomp;
- X<=Xcomp;
- --Indication d'écriture
- WRITE<='1';
- else
- --Remise à l'état bas de l'impulsion d'écriture
- WRITE<='0';
- end if;
- end if;
- end process;
- --Process de lecture de lecture de la séquence synchrone au signal d'CLK de la souris
- process(CLK)
- variable parity : STD_LOGIC;
- begin
- --Detection de front montant
- if(rising_edge(CLK)) then
- --Détection du bit de start et changement d'état associé
- if(prevstat = '1' and DATA='0') then
- if(etat_actuel=waitingcontrol) then
- CCOLOR<="00";
- etat_actuel<=control;
- PositionComp <= 1;
- elsif(etat_actuel=waitingmovX) then
- etat_actuel<=Xmov;
- PositionComp <= 1;
- elsif(etat_actuel=waitingmovY) then
- etat_actuel<=Ymov;
- PositionComp <= 1;
- end if;
- elsif(DATA = '1') then
- prevstat<='1';
- end if;
- --Remise à zero de la machine d'état : mise en attente d'une nouvelle séquence
- if(etat_actuel=endstate) then
- etat_actuel<=waitingcontrol;
- ERROR<='0';
- WWRITE <= '0';
- end if;
- --Si on est dans l'état de lecture des "boutons"
- if(etat_actuel = control) then
- case(PositionComp) is
- when 0 =>
- when 1 =>
- if(DATA='1') then
- CCOLOR <="11";
- end if;
- parity:=DATA;
- when 2 =>
- if(CCOLOR = "11") then
- else
- if(DATA = '1') then
- CCOLOR <= "10";
- else
- CCOLOR <= "00";
- end if;
- end if;
- parity:=parity xor DATA;
- when 3 => parity:=parity xor DATA;
- when 4 => parity:=parity xor DATA;
- when 5 =>
- if(DATA = '1') then
- movX<='1';
- else
- movX<='0';
- end if;
- parity:=parity xor DATA;
- when 6 =>
- if(DATA = '1') then
- movY<='1';
- else
- movY<='0';
- end if;
- parity:=parity xor DATA;
- when 7 => parity:=parity xor DATA;
- when 8 => parity:=parity xor DATA;
- when 9 =>
- parity :=parity xor DATA;
- if(parity = '0') then
- ERROR<='1';
- end if;
- etat_actuel<=waitingmovX;
- prevstat<='0';
- end case;
- --Si on est dans l'état de lecture du déplacement de X
- elsif(etat_actuel = Xmov) then
- if(PositionComp >= 1 and PositionComp <=8) then
- XX(PositionComp-1)<=DATA;
- if(PositionComp = 1) then
- parity:= DATA;
- else
- parity := parity xor DATA;
- end if;
- elsif(PositionComp = 9) then
- parity:= parity xor DATA;
- if(parity = '0') then
- ERROR<='1';
- end if;
- etat_actuel<=waitingmovY;
- prevstat<='0';
- end if;
- --Si on est dans l'état de lecture du déplacement de Y
- elsif(etat_actuel = Ymov) then
- if(PositionComp >= 1 and PositionComp <=8) then
- YY(PositionComp-1)<=DATA;
- if(PositionComp = 1) then
- parity:= DATA;
- else
- parity := parity xor DATA;
- end if;
- elsif(PositionComp = 9) then
- parity:= parity xor DATA;
- if(parity = '0') then
- ERROR<='1';
- end if;
- etat_actuel<=endstate;
- prevstat<='0';
- WWRITE <= '1';
- end if;
- end if;
- --On incrémente le compteur si on est dans un des trois blocs de lecture
- if(etat_actuel = control or etat_actuel = Xmov or etat_actuel = Ymov) then
- if(PositionComp<9) then
- PositionComp <= PositionComp+1;
- else
- PositionComp<=0;
- end if;
- end if;
- end if;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement