1 |
d93979b7
|
Arnaud Dieumegard
|
library IEEE;
|
2 |
|
|
|
3 |
|
|
use IEEE.std_logic_1164.all;
|
4 |
|
|
|
5 |
|
|
entity display_manager is
|
6 |
|
|
generic
|
7 |
|
|
(
|
8 |
|
|
---- For implementation:
|
9 |
|
|
-- g_clock_cycle_per_display: natural := 125000
|
10 |
|
|
---- For testing, we recommend using:
|
11 |
|
|
g_clock_cycle_per_display: natural := 2
|
12 |
|
|
);
|
13 |
|
|
port
|
14 |
|
|
(
|
15 |
|
|
i_clock: in std_logic; -- System clock.
|
16 |
|
|
i_reset: in std_logic; -- System reset.
|
17 |
|
|
i_curr_0001_time: in natural range 0 to 9; -- Centiseconds
|
18 |
|
|
i_curr_0010_time: in natural range 0 to 9; -- deciseconds
|
19 |
|
|
i_curr_0100_time: in natural range 0 to 9; -- seconds
|
20 |
|
|
i_curr_1000_time: in natural range 0 to 5; -- decaseconds
|
21 |
|
|
o_display: out natural range 0 to 9; -- number on display
|
22 |
|
|
o_an: out std_logic_vector (3 downto 0) -- selected display
|
23 |
|
|
);
|
24 |
|
|
end display_manager;
|
25 |
|
|
|
26 |
|
|
architecture Behavioral of display_manager is
|
27 |
|
|
-- Types --------------------------------------------------------------------
|
28 |
|
|
-- Our display has four seven-segments components, each of which corresponds
|
29 |
|
|
-- to one of these states.
|
30 |
|
|
type t_display_index is (D0001, D0010, D0100, D1000);
|
31 |
|
|
|
32 |
|
|
-- We have to count the number of clock cycles so we alternate between each
|
33 |
|
|
-- seven-segment display neither too fast for the hardware, neither too slow
|
34 |
|
|
-- for the human eye. This is the durationg for each seven-segment.
|
35 |
|
|
|
36 |
|
|
-- Signals ------------------------------------------------------------------
|
37 |
|
|
-- Which seven-segment we are currently drawing.
|
38 |
|
|
signal futur_state: t_display_index;
|
39 |
|
|
signal current_state: t_display_index;
|
40 |
|
|
|
41 |
|
|
-- Timer to know when to switch to another seven-segment.
|
42 |
|
|
signal display_timer: natural range 1 to g_clock_cycle_per_display;
|
43 |
|
|
begin
|
44 |
|
|
P_DISPLAY_MUX : process
|
45 |
|
|
(
|
46 |
|
|
current_state,
|
47 |
|
|
i_curr_0001_time,
|
48 |
|
|
i_curr_0010_time,
|
49 |
|
|
i_curr_0100_time,
|
50 |
|
|
i_curr_1000_time
|
51 |
|
|
)
|
52 |
|
|
begin
|
53 |
|
|
o_an <= B"1111";
|
54 |
|
|
case current_state is
|
55 |
|
|
when D0001 => -- Centiseconds -----------------------------------------
|
56 |
|
|
o_an(3) <= '0';
|
57 |
|
|
futur_state <= D0010;
|
58 |
|
|
o_display <= i_curr_0001_time;
|
59 |
|
|
when D0010 => -- Deciseconds ------------------------------------------
|
60 |
|
|
o_an(2) <= '0';
|
61 |
|
|
futur_state <= D0100;
|
62 |
|
|
o_display <= i_curr_0010_time;
|
63 |
|
|
when D0100 => -- Seconds ---------------------------------------------
|
64 |
|
|
o_an(1) <= '0';
|
65 |
|
|
futur_state <= D1000;
|
66 |
|
|
o_display <= i_curr_0100_time;
|
67 |
|
|
when others => -- Decaseconds & Shenanigans ---------------------------
|
68 |
|
|
o_an(0) <= '0';
|
69 |
|
|
futur_state <= D0001;
|
70 |
|
|
o_display <= i_curr_1000_time;
|
71 |
|
|
end case;
|
72 |
|
|
end process;
|
73 |
|
|
|
74 |
|
|
P_TIME_COUNTER: process (i_clock, i_reset)
|
75 |
|
|
begin
|
76 |
|
|
if (i_reset = '1')
|
77 |
|
|
then
|
78 |
|
|
display_timer <= 1;
|
79 |
|
|
else
|
80 |
|
|
if (rising_edge(i_clock))
|
81 |
|
|
then
|
82 |
|
|
if (display_timer >= g_clock_cycle_per_display)
|
83 |
|
|
then
|
84 |
|
|
display_timer <= 1;
|
85 |
|
|
else
|
86 |
|
|
display_timer <= (display_timer + 1);
|
87 |
|
|
end if;
|
88 |
|
|
end if;
|
89 |
|
|
end if;
|
90 |
|
|
end process;
|
91 |
|
|
|
92 |
|
|
P_FSM_STATE_SWITCH: process (i_clock, i_reset)
|
93 |
|
|
begin
|
94 |
|
|
if (i_reset = '1')
|
95 |
|
|
then
|
96 |
|
|
current_state <= D0001;
|
97 |
|
|
else
|
98 |
|
|
if (rising_edge(i_clock))
|
99 |
|
|
then
|
100 |
|
|
if (display_timer >= g_clock_cycle_per_display)
|
101 |
|
|
then
|
102 |
|
|
current_state <= futur_state;
|
103 |
|
|
end if;
|
104 |
|
|
end if;
|
105 |
|
|
end if;
|
106 |
|
|
end process;
|
107 |
|
|
end;
|