OpenCores
URL https://opencores.org/ocsvn/tm1637/tm1637/trunk

Subversion Repositories tm1637

[/] [tm1637/] [trunk/] [hdl/] [intel_qp/] [dec_counter/] [tm1637_decimal_count.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 mongoq
-- https://www.engineersgarage.com/vhdl/decimal-counter-in-vhdl/
2
-- https://www.edaboard.com/threads/counting-pulses-in-one-second-with-vhdl.341476/
3
 
4
LIBRARY ieee;
5
USE ieee.std_logic_1164.ALL;
6
USE ieee.numeric_std.ALL;
7
 
8
entity tm1637_decimal_count is
9
  generic (divider : integer);
10
  port (clk25, en: IN std_logic;
11
        out3, out2, out1, out0: OUT std_logic_vector(3 DOWNTO 0));
12
end tm1637_decimal_count;
13
 
14
architecture behavioral OF tm1637_decimal_count IS
15
  signal d1000Curr, d100Curr, d1000Next, d100Next, d10Curr, d10Next, d1Curr, d1Next: unsigned(3 DOWNTO 0) := (OTHERS =>'0');
16
  signal clkdiv : integer range 0 to divider-1 := 0;
17
  signal ce: std_logic := '0';
18
begin
19
 
20
process (clk25) begin
21
 if rising_edge(clk25) then
22
  if (clkdiv < divider-1) then
23
    clkdiv <= clkdiv + 1;
24
    ce <= '0';
25
   else
26
    clkdiv <= 0;
27
    ce <= '1';
28
   end if;
29
  end if;
30
end process;
31
 
32
process(clk25)
33
begin
34
 if (rising_edge(clk25)) then
35
  if (ce='1') then
36
   if (d1000Curr=9 AND d100Curr=9 AND d10Curr=9 AND d1Curr=9) then
37
    d1000Next <= "0000";
38
   elsif (d100Curr=9 AND d10Curr=9 AND d1Curr=9) then
39
    d1000Next <= d1000Curr+1;
40
   else
41
    d1000Next <= d1000Curr;
42
   end if;
43
   if (d100Curr=9 AND d10Curr=9 AND d1Curr=9) then
44
    d100Next <= "0000";
45
   elsif (d10Curr=9 AND d1Curr=9) then
46
    d100Next <= d100Curr+1;
47
   else
48
    d100Next <= d100Curr;
49
   end if;
50
   if (d10Curr=9 AND d1Curr=9) then
51
    d10Next  <= "0000";
52
   elsif (d1Curr=9) then
53
    d10Next <= d10Curr+1;
54
   else
55
    d10Next <= d10Curr;
56
  end if;
57
  if (d1Curr=9) then
58
   d1Next   <= "0000";
59
  else
60
   d1Next <= d1Curr+1;
61
  end if;
62
 
63
  end if;
64
 d1000Curr <= d1000Next;
65
 d100Curr <= d100Next;
66
 d10Curr  <= d10Next;
67
 d1Curr   <= d1Next;
68
end if;
69
end process;
70
 
71
 out0 <= std_logic_vector(d1000Curr);
72
 out1 <= std_logic_vector(d100Curr);
73
 out2 <= std_logic_vector(d10Curr);
74
 out3 <= std_logic_vector(d1Curr);
75
 
76
end behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.