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

Subversion Repositories flha

[/] [flha/] [trunk/] [VHDL/] [Core/] [Counter.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 songching
---- $Author: songching $
2
---- $Date: 2004-04-07 15:38:47 $
3
---- $Revision: 1.1 $
4
----------------------------------------------------------------------
5
---- $Log: not supported by cvs2svn $
6
----------------------------------------------------------------------
7
----
8
---- Copyright (C) 2004 Song Ching Koh, Free Software Foundation, Inc. and OPENCORES.ORG
9
----
10
---- This program is free software; you can redistribute it and/or modify
11
---- it under the terms of the GNU General Public License as published by
12
---- the Free Software Foundation; either version 2 of the License, or
13
---- (at your option) any later version.
14
----
15
---- This program is distributed in the hope that it will be useful,
16
---- but WITHOUT ANY WARRANTY; without even the implied warranty of
17
---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
---- GNU General Public License for more details.
19
----
20
---- You should have received a copy of the GNU General Public License
21
---- along with this program; if not, write to the Free Software
22
---- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 
24
library IEEE;
25
use IEEE.STD_LOGIC_1164.ALL;
26
use IEEE.STD_LOGIC_ARITH.ALL;
27
use IEEE.STD_LOGIC_UNSIGNED.ALL;
28
 
29
--  Uncomment the following lines to use the declarations that are
30
--  provided for instantiating Xilinx primitive components.
31
--library UNISIM;
32
--use UNISIM.VComponents.all;
33
 
34
entity counter is
35
    port (CLK, RST, START: in std_logic;
36
                         DONE: out std_logic;
37
          q : out std_logic_vector (2 downto 0));
38
end counter;
39
 
40
architecture counter_structure of counter is
41
        type state_type is (INIT, DN);
42
        signal present_state, next_state: state_type := INIT;
43
   signal count : std_logic_vector (2 downto 0) := "000";
44
begin
45
        state_process: process(CLK, present_state, count, START)
46
        begin
47
                case present_state is
48
                        when INIT =>
49
                                DONE <= '0';
50
                                if(count = "111") then
51
                                        next_state <= DN;
52
                                else
53
                                        next_state <= INIT;
54
                                end if;
55
                        when DN =>
56
                                DONE <= '1';
57
                                if(START = '0') then
58
                                        next_state <= INIT;
59
                                else
60
                                        next_state <= DN;
61
                                end if;
62
                        when others => next_state <= INIT;
63
                end case;
64
        end process state_process;
65
 
66
        count_process: process(CLK, RST, present_state, count)
67
        begin
68
                if(rising_edge(CLK)) then
69
                        if(RST = '1') then
70
                                count <= (others=>'0');
71
                        elsif(start = '1') then
72
                                count <= count + '1';
73
                        end if;
74
                end if;
75
        end process count_process;
76
 
77
   CLK_Process: process(CLK, RST, next_state)
78
        begin
79
                if(rising_edge(CLK)) then
80
                        if(RST = '1') then
81
                                present_state <= INIT;
82
                        else
83
                                present_state <= next_state;
84
                        end if;
85
                end if;
86
        end process CLK_Process;
87
   q <= count;
88
end counter_structure;

powered by: WebSVN 2.1.0

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