blob: da21075cf7555fa34345394302ba5af997b711e0 (
plain)
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
|
-- Author: Patrick Lehmann
-- License: MIT
--
-- A generic counter module used in the StopWatch example.
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
library lib_Utilities;
use lib_Utilities.Utilities_pkg.all;
use work.StopWatch_pkg.all;
entity seg7_Display is
generic (
CLOCK_PERIOD : time := 10 ns;
REFRESH_RATE : time := 200 us;
DIGITS : positive
);
port (
Clock : in std_logic;
DigitValues : in T_BCD_Vector(DIGITS - 1 downto 0);
DotValues : in std_logic_vector(DIGITS - 1 downto 0) := (others => '0');
Seg7_Segments : out std_logic_vector(7 downto 0);
Seg7_Selects : out std_logic_vector(DIGITS - 1 downto 0)
);
end entity;
architecture rtl of seg7_Display is
constant TIMEBASE_COUNTER_MAX : positive := REFRESH_RATE / (CLOCK_PERIOD * ite(IS_SIMULATION, 1_000, 1));
signal Timebase_Counter : unsigned(log2(TIMEBASE_COUNTER_MAX) - 1 downto 0) := (others => '0');
signal Timebase_Tick : std_logic;
signal Digit_Select : unsigned(log2(DIGITS) - 1 downto 0) := (others => '0');
signal Digit_Select_ov : std_logic;
signal Digit : T_BCD;
signal Dot : std_logic;
begin
-- refresh rate
process(Clock)
begin
if rising_edge(Clock) then
if (Timebase_Tick = '1') then
Timebase_Counter <= (others => '0');
else
Timebase_Counter <= Timebase_Counter + 1;
end if;
end if;
end process;
Timebase_Tick <= '1' when (Timebase_Counter = TIMEBASE_COUNTER_MAX - 1) else '0';
-- counter to select digits (time multiplexing)
process(Clock)
begin
if rising_edge(Clock) then
if (Timebase_Tick = '1') then
if (Digit_Select_ov = '1') then
Digit_Select <= (others => '0'); -- to_unsigned(5, Digit_Select'length);
else
Digit_Select <= Digit_Select + 1;
end if;
end if;
end if;
end process;
Digit_Select_ov <= '1' when (Digit_Select = DIGITS - 1) else '0';
-- multiplexer
Digit <= DigitValues(to_index(Digit_Select, DigitValues'high));
Dot <= DotValues(to_index(Digit_Select, DotValues'high));
-- 7-segment encoder
enc: configuration seg7_Encoder
port map (
BCDValue => Digit,
Dot => Dot,
Seg7Code => Seg7_Segments
);
Seg7_Selects <= bin2onehot(Digit_Select, DIGITS);
end architecture;
|