-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbwehr3.vhd
170 lines (118 loc) · 4.07 KB
/
Abwehr3.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 09/16/2021 01:10:56 PM
-- Design Name:
-- Module Name: Abwehr1 - 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.numeric_std.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Abwehr3 is
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
FC: in integer;
strobe: in std_logic;
resetn:in std_logic;
rand: in std_logic_vector (9 downto 0);
AB3Col: out std_logic_vector(11 downto 0);
collall :in std_logic_vector(2 downto 0);
colswitcher: in std_logic;
poswitch : in std_logic;
Exist: out std_logic
);
end Abwehr3;
architecture Behavioral of Abwehr3 is
constant maxrad : integer := 10;
constant Black: std_logic_vector (11 downto 0) := X"000";
constant Red: std_logic_vector (11 downto 0) := X"F00";
constant yellow: std_logic_vector (11 downto 0) := X"FF0";
--Startposition random
signal randcov : integer range 200 to 400;
--Richtung random
signal xdir : integer range 0 to 3;
signal ydir : integer range 0 to 3;
begin
randcov <= to_integer(unsigned(rand(4 downto 0)));
xdir <= to_integer(unsigned(rand(1 downto 0)));
ydir <= to_integer(unsigned(rand(3 downto 2)));
process(randcov)
begin
if randcov> 400 then
randcov <= randcov - 112;
elsif randcov < 200 then
randcov <= randcov + 200;
end if;
end process;
process(clk25, poswitch, randcov, xdir, ydir)
variable NewPosx : integer range 0 to 640;
variable NewPosy : integer range 0 to 480;
variable newDirx : integer range -3 to 3;
variable newDiry : integer range -3 to 3;
begin
if poswitch ='1' then
NewPosx := 320;
NewPosy := 240;
newDirx := xdir;
newDiry := ydir;
elsif rising_edge(clk25) then
if strobe ='1' then
if FC mod 1 = 0 then
-- if newPosx < 200 or newPosx > 400 then
-- -- newDirx := -newDirx;
-- else
if collall(2)='1' then
newDiry := -newDiry ;--Rand
elsif collall(1) = '1' then
newDirx := -newDirx;
newDiry := -newDiry; --AB3Col
elsif collall="001" then
newDirx := -newDirx;
newDiry := -newDiry; --Abwehr2
elsif NewPosx <=150 or Newposx >= 500 then
newDirx := -newDirx;
else
newDiry := newDiry;
end if;
-- end if;
NewPosx := NewPosx + newDirx;
NewPosy := NewPosy + newDiry;
end if;
end if;
if (((HC-NewPosx)**2 + (VC -NewPosy)**2 ) <= (maxrad+3)**2 ) then
Exist <= '1';
AB3Col<= Black;
elsif (((HC -NewPosx)*2)**2 + ((VC-NewPosy)**2) <= (maxrad*3)**2) then
Exist <= '1';
if colswitcher='1' then
AB3Col<= red;
else
AB3Col <= yellow;
end if;
else
Exist <= '0';
end if;
end if;
end process;
end Behavioral;