-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.vhd
163 lines (138 loc) · 3.39 KB
/
main.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
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 16:26:07 12/07/2019
-- Design Name:
-- Module Name: main - 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;
-- 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 primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity main is
port (
SYSCLK : in STD_LOGIC; -- System Clock
RESET : in STD_LOGIC;
-- display anodes and catodes
DISPLAY : out STD_LOGIC_VECTOR (0 to 15);
-- diodes ports
DIODE_X_R : out STD_LOGIC;
DIODE_X_G : out STD_LOGIC;
DIODE_Y_R : out STD_LOGIC;
DIODE_Y_G : out STD_LOGIC;
--SPI Interface Signals
SCLK : out STD_LOGIC;
MOSI : out STD_LOGIC;
MISO : in STD_LOGIC;
SS : out STD_LOGIC
);
end main;
architecture Behavioral of main is
subtype axis is integer range 0 to 2047;
component ADXL362Ctrl
port ( SYSCLK : in STD_LOGIC; -- System Clock
RESET : in STD_LOGIC;
-- Accelerometer data signals
ACCEL_X : out STD_LOGIC_VECTOR (11 downto 0);
ACCEL_Y : out STD_LOGIC_VECTOR (11 downto 0);
--SPI Interface Signals
SCLK : out STD_LOGIC;
MOSI : out STD_LOGIC;
MISO : in STD_LOGIC;
SS : out STD_LOGIC);
end component;
component DisplayViewer
port ( SYSCLK : in STD_LOGIC;
NUM_L : in axis;
NUM_R : in axis;
Q : out STD_LOGIC_VECTOR (0 to 15));
end component;
component Indicator
port ( Success : in STD_LOGIC;
R : out STD_LOGIC;
G : out STD_LOGIC );
end component;
function Deviation (A: axis) return axis is
begin
if A <= 1024 then
return A;
else
return 2048 - A;
end if;
end;
function isSuccess (DEV: axis) return std_logic is
begin
if DEV <= 30 then
return '1';
else
return '0';
end if;
end;
signal x_vec : std_logic_vector (11 downto 0);
signal y_vec : std_logic_vector (11 downto 0);
signal x : axis;
signal y : axis;
signal x_dev : axis;
signal y_dev : axis;
signal success_x : std_logic := '0';
signal success_y : std_logic := '0';
begin
accel: ADXL362Ctrl port map (
SYSCLK => SYSCLK,
RESET => RESET,
ACCEL_X => x_vec,
ACCEL_Y => y_vec,
SCLK => SCLK,
MOSI => MOSI,
MISO => MISO,
SS => SS
);
accel_converter: process (x_vec, y_vec)
begin
x <= to_integer(unsigned(x_vec));
y <= to_integer(unsigned(y_vec));
end process;
deviation_calc: process (x, y)
begin
x_dev <= Deviation(x);
y_dev <= Deviation(y);
end process;
displ: DisplayViewer port map (
SYSCLK => SYSCLK,
NUM_L => x_dev,
NUM_R => y_dev,
Q => DISPLAY
);
calc_success: process (x_dev, y_dev)
begin
success_x <= isSuccess(x_dev);
success_y <= isSuccess(y_dev);
end process;
indicate_x: Indicator port map (
Success => success_x,
R => DIODE_X_R,
G => DIODE_X_G
);
indicate_y: Indicator port map (
Success => success_y,
R => DIODE_Y_R,
G => DIODE_Y_G
);
end Behavioral;