-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblink.vhd
131 lines (102 loc) · 3.1 KB
/
blink.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
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY blink is
port
(
i_clk : IN STD_LOGIC;
o_ledring : OUT std_logic_vector(23 downto 0);
o_ledtrans : OUT STD_LOGIC;
o_flashing : OUT STD_LOGIC
);
end blink;
-- Architecture Body
architecture blink_architecture of blink is
-- Constants to create the frequencies needed:
-- 50MHZ/1Hz * 50% duty = 25,000,000
-- 50MHZ/10hz * 50% duty = 2,500,000
constant c_CNT_1HZ : natural := 25000000;
constant c_CNT_10HZ : natural := 2500000;
-- Counter signals:
signal r_CNT_1HZ : natural range 0 to c_CNT_1HZ;
signal r_CNT_10HZ : natural range 0 to c_CNT_10HZ;
constant c_NUM_LEDS : natural := 12; -- Define the number of entries in the array
signal r_CNT_LEDARR : natural range 0 to 24 := 0;
-- these signals hold toggle status:
signal r_TOGGLE_1HZ : std_logic := '0';
signal r_TOGGLE_10HZ: std_logic := '0';
TYPE machine IS(idle, transmitting, finished); -- state machine
signal state : machine := idle;
type data_array_type is array (natural range <>) of std_logic_vector(23 downto 0);
signal data : std_logic_vector(23 downto 0) := x"0000FF";
signal data_arrayz : data_array_type(0 to c_NUM_LEDS - 1) := (
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000",
x"FF0000"
);
begin
p_1HZ : process (i_clk) is
begin
if rising_edge(i_clk) then
if r_CNT_1HZ = c_CNT_1HZ - 1 then
r_TOGGLE_1HZ <= not r_TOGGLE_1HZ;
r_CNT_1HZ <= 0;
else
r_CNT_1HZ <= r_CNT_1HZ + 1;
end if;
end if;
end process;
p_10HZ : process (i_clk) is
begin
if rising_edge(i_clk) then
if r_CNT_10HZ = c_CNT_10HZ - 1 then
r_TOGGLE_10HZ <= not r_TOGGLE_10HZ;
r_CNT_10HZ <= 0;
else
r_CNT_10HZ <= r_CNT_10HZ + 1;
end if;
end if;
end process;
p_LED_transmit : process (i_clk) is
begin
if rising_edge(i_clk) then
if r_TOGGLE_10HZ = '1' and state = idle then
state <= transmitting;
--r_CNT_LEDARR <= 0;
end if;
case state is
when transmitting =>
if r_CNT_LEDARR > 12 then -- ALWAYS EQUAL TO 13???
data <= x"00ff00";
else
data <= x"000010";
end if;
--data <= x"101010";
--data <= data_arrayz(0);
if r_CNT_LEDARR > c_NUM_LEDS then
r_CNT_LEDARR <= 0;
state <= finished;
end if;
r_CNT_LEDARR <= r_CNT_LEDARR + 1;
when finished =>
--r_CNT_LEDARR <= 0;
if r_TOGGLE_10HZ = '0' then
state <= idle;
end if;
when idle =>
r_CNT_LEDARR <= 0;
end case;
end if;
end process;
o_ledring <= data;
o_flashing <= r_TOGGLE_10HZ;
o_ledtrans <= r_TOGGLE_10HZ;
end blink_architecture;