Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 10:57:21 01/17/2018
  6. -- Design Name:
  7. -- Module Name: deux_un_chombart_delannel - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. ---- Uncomment the following library declaration if instantiating
  26. ---- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29. entity deux_un_chombart_delannel is
  30. Port ( SYS_CLK : in STD_LOGIC;
  31. DATA : in STD_LOGIC;
  32. CLK : in STD_LOGIC;
  33. X : out STD_LOGIC_VECTOR (7 downto 0);
  34. Y : out STD_LOGIC_VECTOR (7 downto 0);
  35. COLOR : out STD_LOGIC_VECTOR (1 downto 0);
  36. WRITE : out STD_LOGIC);
  37. end deux_un_chombart_delannel;
  38.  
  39.  
  40. architecture Behavioral of deux_un_chombart_delannel is
  41.  
  42. --Signaux intermédiaires utilisés
  43. signal XX : STD_LOGIC_VECTOR (7 downto 0);
  44. signal YY : STD_LOGIC_VECTOR (7 downto 0);
  45. signal CCOLOR : STD_LOGIC_VECTOR(1 downto 0);
  46. signal movX, movY : STD_LOGIC;
  47. signal prevstat : STD_LOGIC := '0';
  48. signal WWRITE : STD_LOGIC := '0';
  49. signal ERROR : STD_LOGIC := '0';
  50.  
  51. --Déclaration d'état
  52. type etat_sys is (waitingcontrol, control, waitingmovX, Xmov, waitingmovY, Ymov, endstate);
  53. signal etat_actuel : etat_sys := waitingcontrol;
  54.  
  55. signal PositionComp : integer range 0 to 9;
  56.  
  57. begin
  58.  
  59. --Process d'écriture sur la sortie synchrone avec c le front montant de l'CLK système
  60. process(SYS_CLK)
  61.  
  62. variable i : integer := 0;
  63. variable Xcomp : STD_LOGIC_VECTOR(7 downto 0) := "00000000";
  64. variable Ycomp : STD_LOGIC_VECTOR(7 downto 0) := "00000000";
  65.  
  66. begin
  67. --Detection de front montant
  68. if(rising_edge(SYS_CLK)) then
  69. if(WWRITE = '1' and ERROR='0') then
  70.  
  71. --WRITE de la COLOR
  72. COLOR<=CCOLOR;
  73.  
  74. --Calcul de X (complémenté ou non)
  75. Xcomp:=XX;
  76. if(Xcomp(7)='1') then
  77. Xcomp(6 downto 0):="1111111";
  78. end if;
  79. Xcomp(7):='0';
  80. ---
  81. if(movX = '0') then
  82. Xcomp := not Xcomp;
  83. Xcomp := Xcomp + "00000001";
  84. end if;
  85. ---
  86.  
  87. -- Calcul de Y (complémenté ou non)
  88. Ycomp:=YY;
  89. if(Ycomp(7)='1') then
  90. Ycomp(6 downto 0):="1111111";
  91. end if;
  92. Ycomp(7):='0';
  93. ---
  94. if(movY = '0') then
  95. Ycomp := not Ycomp;
  96. Ycomp := Ycomp + "00000001";
  97. end if;
  98. ---
  99.  
  100. --WRITE de X et Y
  101. Y<=Ycomp;
  102. X<=Xcomp;
  103.  
  104. --Indication d'écriture
  105. WRITE<='1';
  106.  
  107. else
  108. --Remise à l'état bas de l'impulsion d'écriture
  109. WRITE<='0';
  110. end if;
  111. end if;
  112.  
  113. end process;
  114.  
  115.  
  116. --Process de lecture de lecture de la séquence synchrone au signal d'CLK de la souris
  117. process(CLK)
  118.  
  119. variable parity : STD_LOGIC;
  120.  
  121. begin
  122. --Detection de front montant
  123. if(rising_edge(CLK)) then
  124.  
  125. --Détection du bit de start et changement d'état associé
  126. if(prevstat = '1' and DATA='0') then
  127. if(etat_actuel=waitingcontrol) then
  128. CCOLOR<="00";
  129. etat_actuel<=control;
  130. PositionComp <= 1;
  131.  
  132. elsif(etat_actuel=waitingmovX) then
  133. etat_actuel<=Xmov;
  134. PositionComp <= 1;
  135.  
  136. elsif(etat_actuel=waitingmovY) then
  137. etat_actuel<=Ymov;
  138. PositionComp <= 1;
  139. end if;
  140.  
  141. elsif(DATA = '1') then
  142. prevstat<='1';
  143. end if;
  144.  
  145. --Remise à zero de la machine d'état : mise en attente d'une nouvelle séquence
  146. if(etat_actuel=endstate) then
  147. etat_actuel<=waitingcontrol;
  148. ERROR<='0';
  149. WWRITE <= '0';
  150. end if;
  151.  
  152. --Si on est dans l'état de lecture des "boutons"
  153. if(etat_actuel = control) then
  154. case(PositionComp) is
  155. when 0 =>
  156. when 1 =>
  157. if(DATA='1') then
  158. CCOLOR <="11";
  159. end if;
  160. parity:=DATA;
  161. when 2 =>
  162. if(CCOLOR = "11") then
  163. else
  164. if(DATA = '1') then
  165. CCOLOR <= "10";
  166. else
  167. CCOLOR <= "00";
  168. end if;
  169. end if;
  170. parity:=parity xor DATA;
  171. when 3 => parity:=parity xor DATA;
  172. when 4 => parity:=parity xor DATA;
  173. when 5 =>
  174. if(DATA = '1') then
  175. movX<='1';
  176. else
  177. movX<='0';
  178. end if;
  179. parity:=parity xor DATA;
  180. when 6 =>
  181. if(DATA = '1') then
  182. movY<='1';
  183. else
  184. movY<='0';
  185. end if;
  186. parity:=parity xor DATA;
  187. when 7 => parity:=parity xor DATA;
  188. when 8 => parity:=parity xor DATA;
  189. when 9 =>
  190. parity :=parity xor DATA;
  191. if(parity = '0') then
  192. ERROR<='1';
  193. end if;
  194. etat_actuel<=waitingmovX;
  195. prevstat<='0';
  196. end case;
  197.  
  198.  
  199. --Si on est dans l'état de lecture du déplacement de X
  200. elsif(etat_actuel = Xmov) then
  201.  
  202. if(PositionComp >= 1 and PositionComp <=8) then
  203. XX(PositionComp-1)<=DATA;
  204. if(PositionComp = 1) then
  205. parity:= DATA;
  206. else
  207. parity := parity xor DATA;
  208. end if;
  209. elsif(PositionComp = 9) then
  210. parity:= parity xor DATA;
  211. if(parity = '0') then
  212. ERROR<='1';
  213. end if;
  214. etat_actuel<=waitingmovY;
  215. prevstat<='0';
  216. end if;
  217.  
  218.  
  219. --Si on est dans l'état de lecture du déplacement de Y
  220. elsif(etat_actuel = Ymov) then
  221.  
  222. if(PositionComp >= 1 and PositionComp <=8) then
  223. YY(PositionComp-1)<=DATA;
  224. if(PositionComp = 1) then
  225. parity:= DATA;
  226. else
  227. parity := parity xor DATA;
  228. end if;
  229. elsif(PositionComp = 9) then
  230. parity:= parity xor DATA;
  231. if(parity = '0') then
  232. ERROR<='1';
  233. end if;
  234. etat_actuel<=endstate;
  235. prevstat<='0';
  236. WWRITE <= '1';
  237. end if;
  238.  
  239.  
  240.  
  241. end if;
  242.  
  243. --On incrémente le compteur si on est dans un des trois blocs de lecture
  244. if(etat_actuel = control or etat_actuel = Xmov or etat_actuel = Ymov) then
  245. if(PositionComp<9) then
  246. PositionComp <= PositionComp+1;
  247. else
  248. PositionComp<=0;
  249. end if;
  250. end if;
  251.  
  252.  
  253. end if;
  254.  
  255.  
  256. end process;
  257.  
  258.  
  259.  
  260.  
  261. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement