forked from salb545/VHDLWhizCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled_controller_8x8.vhd
More file actions
113 lines (79 loc) · 3.43 KB
/
Copy pathled_controller_8x8.vhd
File metadata and controls
113 lines (79 loc) · 3.43 KB
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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library dot_matrix_sim;
use dot_matrix_sim.types.all;
use dot_matrix_sim.constants.all;
--- This module controls EACH & EVERY DOT of the 8x8 LED Matrix
entity led_controller_8x8 is
generic (
PULSE_TIME_US : natural := led_pulse_time_us;
DEADBAND_TIME_US : natural := led_deadband_time_us
);
port (
clk : in std_logic;
rst : in std_logic;
led8x8: in matrix_type; ---- THIS INPUT IS A 64-BIT REPRESENATION OF WHAT LEDS TO "ON" AND WHAT LEDS TO "OFF"
rows : out std_logic_vector(7 downto 0);
cols : out std_logic_vector(7 downto 0)
);
end led_controller_8x8;
architecture rtl of led_controller_8x8 is
---------------------------------------- HOW IS THE LED SWITCHED ON ? -------------------------------
-- Row By Row; illuminating the needed LED's before moving to the next row --------------------------
-- This MUST be done at a frequency high enough to the point that the naked human eye wont notice the
-- difference AND AND AND AND the LED's will look like a STABLE IMAGE!
------------------------------------------------------------------------------------------------------
--------------THE FOLLOWING SECTION SHOWS HOW CLOCK CYCLES ARE MANIPULATED TO CONTROL THE LED REPRESENTATION -------
-- The number of clock cycles to light each LED for
constant clk_cycles_per_pulse : natural
:= natural(clock_frequency / 1.0e6) * PULSE_TIME_US; ---- HOW LONG ILLUMINATE EAACH LED BEFORE MOVING TO THE NEXT ROW
subtype pulse_counter_type is natural range 0 to clk_cycles_per_pulse - 1;
-- The number of clock cycles in the deadband period
constant clk_cycles_deadband : natural
:= natural(clock_frequency / 1.0e6) * DEADBAND_TIME_US;
signal pulse_counter : pulse_counter_type;
signal row_counter : unsigned(2 downto 0);
--- WHEN WRITING ASSERT STATEMENTS IN NON TEST-BENCH CODE, USE CONSTANTS! -------------
begin
-- FILE WONT COMPILE IF THESE ASSERT STATEMENTS FAIL.......
assert clk_cycles_per_pulse > 0 severity failure;
assert clk_cycles_per_pulse < natural(clock_frequency) severity failure;
assert clk_cycles_per_pulse > clk_cycles_deadband severity failure;
PROC_COUNTER : process(clk)
begin
if rising_edge(clk) then
if rst = '1' then
pulse_counter <= 0;
row_counter <= (others => '0');
else
-- When pulse_counter wraps
if pulse_counter = pulse_counter_type'high then --- IF PULSE COUNTER HAS MAXIMUM POSSIBLE PULSE VALUE
pulse_counter <= 0;
row_counter <= row_counter + 1;
else
pulse_counter <= pulse_counter + 1;
end if;
end if;
end if;
end process; -- PROC_COUNTER
PROC_OUTPUT : process(clk)
begin
if rising_edge(clk) then
if rst = '1' then
rows <= (others => '0');
cols <= (others => '0');
else
rows <= (others => '0');
rows(to_integer(row_counter)) <= '1';
cols <= led8x8(to_integer(row_counter));
-- This is within the deadband period
if pulse_counter < clk_cycles_deadband then
rows <= (others => '0');
cols <= (others => '0');
end if;
end if;
end if;
end process; -- PROC_OUTPUT
----- DEADBAND ADDED TO ALLOW SMOOTHER TRANSITION TIME AND TO ENSURE THAT ALL RELEVANT LEDS TURN ON AT ONCE! ------------
end architecture;