kamilosxd678

ISP LAST LAB!!!!!!!!!

Jun 1st, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 08:36:32 05/28/2013
  6. -- Design Name:
  7. -- Module Name: main - 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. use IEEE.NUMERIC_STD.ALL;
  25.  
  26. ---- Uncomment the following library declaration if instantiating
  27. ---- any Xilinx primitives in this code.
  28. --library UNISIM;
  29. --use UNISIM.VComponents.all;
  30.  
  31. entity main is
  32. Port ( clk_i : in STD_LOGIC;
  33. rgb_o : out STD_LOGIC_VECTOR(2 downto 0);
  34. hsync_o : out STD_LOGIC;
  35. vsync_o : out STD_LOGIC;
  36. sw_i : in STD_LOGIC_VECTOR(7 downto 0);
  37. btn_i : in STD_LOGIC_VECTOR(3 downto 0));
  38. end main;
  39.  
  40. architecture Structural of main is
  41.  
  42. function divide (a : UNSIGNED; b : UNSIGNED) return UNSIGNED is
  43. variable a1 : unsigned(a'length-1 downto 0):=a;
  44. variable b1 : unsigned(b'length-1 downto 0):=b;
  45. variable p1 : unsigned(b'length downto 0):= (others => '0');
  46. variable i : integer:=0;
  47.  
  48. begin
  49. for i in 0 to b'length-1 loop
  50. p1(b'length-1 downto 1) := p1(b'length-2 downto 0);
  51. p1(0) := a1(a'length-1);
  52. a1(a'length-1 downto 1) := a1(a'length-2 downto 0);
  53. p1 := p1-b1;
  54. if(p1(b'length-1) ='1') then
  55. a1(0) :='0';
  56. p1 := p1+b1;
  57. else
  58. a1(0) :='1';
  59. end if;
  60. end loop;
  61. return a1;
  62.  
  63. end divide;
  64.  
  65. component memory
  66. port (
  67. clka: IN std_logic;
  68. dina: IN std_logic_VECTOR(0 downto 0);
  69. addra: IN std_logic_VECTOR(17 downto 0);
  70. wea: IN std_logic_VECTOR(0 downto 0);
  71. clkb: IN std_logic;
  72. addrb: IN std_logic_VECTOR(17 downto 0);
  73. doutb: OUT std_logic_VECTOR(0 downto 0));
  74. end component;
  75.  
  76. component sinus IS
  77. PORT (
  78. DATA : IN STD_LOGIC_VECTOR(15 DOWNTO 0);
  79. WE : IN STD_LOGIC;
  80. A : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
  81. CLK : IN STD_LOGIC;
  82. SCLR : IN STD_LOGIC;
  83. CHANNEL : OUT STD_LOGIC_VECTOR(0 DOWNTO 0);
  84. RDY : OUT STD_LOGIC;
  85. SINE : OUT STD_LOGIC_VECTOR(10 DOWNTO 0)
  86. );
  87. END component;
  88.  
  89. component VGAsync is
  90. Port ( clk_i : in STD_LOGIC;
  91. hsync_o : out STD_LOGIC;
  92. vsync_o : out STD_LOGIC;
  93. pixelX : out integer range 640 downto 0;
  94. pixelY : out integer range 480 downto 0);
  95. end component;
  96.  
  97. signal lowClk : std_logic := '0';
  98.  
  99. signal addrW : std_logic_vector(17 downto 0);
  100. signal addrR : std_logic_vector(17 downto 0);
  101. signal x : std_logic;
  102. signal y : std_logic;
  103. signal memRead : std_logic_vector(0 downto 0);
  104. signal memWrite : std_logic_vector(0 downto 0);
  105. signal writeEnable : std_logic_vector(0 downto 0);
  106. signal pixelX : integer range 640 downto 0;
  107. signal pixelY : integer range 480 downto 0;
  108. signal pixAddr : integer range 147456 downto 0;
  109.  
  110. signal singenData : std_logic_vector(15 downto 0);
  111. signal addrSel : std_logic_vector(4 downto 0);
  112. signal wrEnable : std_logic := '0';
  113. signal resetGen : std_logic := '0';
  114.  
  115. signal channel : std_logic_vector(0 downto 0);
  116. signal genRdy : std_logic;
  117. signal sinOut : std_logic_vector(10 downto 0);
  118.  
  119. constant PIXEL : std_logic_vector(2 downto 0) := "111";
  120. constant BACKGROUND : std_logic_vector(2 downto 0) := "000";
  121.  
  122. signal Xoffset : integer range 640 downto 0 := 128;
  123. signal Yoffset : integer range 480 downto 0 := 48;
  124.  
  125. signal clearScr : std_logic := '1';
  126.  
  127. signal button3 : std_logic := '0'; --nowa zmienna
  128.  
  129. begin
  130.  
  131. videoMem : memory port map(
  132. clka => clk_i,
  133. dina => memWrite,
  134. addra => addrW,
  135. wea => writeEnable,
  136. clkb => clk_i,
  137. addrb => addrR,
  138. doutb => memRead );
  139.  
  140. generator : sinus PORT map(
  141. DATA => singenData, -- data input to the gen.
  142. WE => wrEnable, -- write enable - read from DATA into registers PINC or POFF
  143. A => addrSel, -- address select for DATA to write to when WE
  144. -- 00000 to 01111 phase increment for ch. 0 through 15 (PINC)
  145. -- 10000 to 11111 phase offset for ch. 0 through 15 (POFF)
  146. CLK => clk_i, -- clock
  147. SCLR => resetGen, -- synchronous clear
  148. CHANNEL => channel, -- shows which channel is currently displayed
  149. RDY => genRdy, -- indicates that the data is ready to read
  150. SINE => sinOut -- output sinus data
  151. );
  152.  
  153. setMemory : process (clk_i)
  154. variable Xmemory : integer range 386 downto 0 := 386;
  155. variable Ymemory : integer range 386 downto 0 := 386;
  156. variable wrtAddr : integer range 147456 downto 0 := 0;
  157. begin
  158. if rising_edge(clk_i) then
  159. if btn_i(3)='1' then --nowy if do wyeliminowania wyscigow na buttonie 3
  160. button3 <= '1'
  161. end if;
  162. if button3 = '1' then
  163. Xmemory := 0;
  164. Ymemory := 0;
  165. clearScr <= '1';
  166. resetGen <= '1';
  167. button3 <= '0';
  168. elsif clearScr='1' then
  169. if resetGen='1' then
  170. resetGen <= '0';
  171. end if;
  172. if lowClk='1' then
  173. writeEnable(0) <= '0';
  174. elsif Xmemory<385 and Ymemory<385 then
  175. wrtAddr := (Xmemory) + ((Ymemory)*384);
  176. memWrite(0) <= '0';
  177. addrW <= std_logic_vector(to_unsigned(wrtAddr, 18));
  178. writeEnable(0) <= '1';
  179. Xmemory := Xmemory + 1;
  180. if Xmemory=385 then
  181. Ymemory := Ymemory + 1;
  182. Xmemory := 0;
  183. end if;
  184. elsif Ymemory=385 then
  185. clearScr <= '0';
  186. end if;
  187. else
  188. if writeEnable(0)='1' then
  189. writeEnable(0) <= '0';
  190. end if;
  191. if genRdy='1' then
  192. if channel(0)='0' then
  193. Xmemory := conv_integer(sinOut)*3/16 + 192;
  194. else
  195. Ymemory := conv_integer(sinOut)*3/16 + 192;
  196. wrtAddr := (Xmemory) + ((Ymemory)*384);
  197. memWrite(0) <= '1';
  198. addrW <= std_logic_vector(to_unsigned(wrtAddr, 18));
  199. writeEnable(0) <= '1';
  200. end if;
  201. end if;
  202. end if;
  203. end if;
  204. end process;
  205.  
  206. monitor_sync : VGAsync port map(
  207. clk_i => lowClk,
  208. hsync_o => hsync_o,
  209. vsync_o => vsync_o,
  210. pixelX => pixelX,
  211. pixelY => pixelY );
  212.  
  213. clockDivider : process(clk_i)
  214. begin
  215. if rising_edge(clk_i) then
  216. if lowClk='0' then
  217. lowClk <= '1';
  218. else
  219. lowClk <= '0';
  220. end if;
  221. end if;
  222. end process;
  223.  
  224. writeRGB : process(pixelX, pixelY)
  225. variable tmpXoffset : integer range 640 downto 0 := 0;
  226. variable tmpYoffset : integer range 480 downto 0 := 0;
  227. begin
  228.  
  229. tmpXoffset := Xoffset + 12;
  230. tmpYoffset := Yoffset + 7;
  231.  
  232. if (pixelX >= tmpXoffset) and (pixelY >= tmpYoffset) and (pixelX < tmpXoffset + 384) then
  233. pixAddr <= (pixelX-tmpXoffset) + ((pixelY-tmpYoffset)*384); -- a tutaj +2
  234. addrR <= std_logic_vector(to_unsigned(pixAddr, 18));
  235. if memRead(0)='1' then
  236. rgb_o <= PIXEL;
  237. else
  238. rgb_o <= BACKGROUND;
  239. end if;
  240. else
  241. rgb_o <= BACKGROUND;
  242. end if;
  243. end process;
  244.  
  245. buttons : process(clk_i)
  246.  
  247. begin
  248. if rising_edge(clk_i) then -- ponizej buttony maja byc porownywane do 1 a nie do 0
  249. if btn_i(0)='1' then
  250. singenData(15 downto 0) <= "00000000"&sw_i;
  251. addrSel <= "00000";
  252. wrEnable <= '1';
  253. elsif btn_i(1)='1' then
  254. singenData(`5 downto 0) <= "00000000"&sw_i;
  255. addrSel <= "00001";
  256. wrEnable <= '1';
  257. elsif btn_i(2)='1' then
  258. singenData(15 downto 0) <= sw_i&"00000000";
  259. addrSel <= "10000";
  260. wrEnable <= '1';
  261. else
  262. wrEnable <= '0';
  263. end if;
  264. end if;
  265. end process;
  266.  
  267. end Structural;
Advertisement
Add Comment
Please, Sign In to add comment