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

Subversion Repositories patterngen

[/] [patterngen/] [trunk/] [rtl/] [xcounter.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 lfmunoz
----------------------------------------------------------------------------------
2
-- Company:            ISI/Nallatech
3
-- Engineer:           Luis Munoz
4
-- Email:              lfmunoz4@gmail.com
5
-- 
6
-- Create Date:        06:01:23 01/01/2011 
7
--
8
-- Module Name:        XCOUNTER - Behavioral 
9
--
10
-- Project Name:       Counter
11
--
12
-- Target Devices:     Any
13
--
14
-- Description:        This module increments on the risinge edge of CLK_i when CLKen_i 
15
--                     is high. It counts from 0 to XVAL and wraps around, on the last value,
16
--                     XVAL, DONE_o goes high.
17
--
18
-- Revision:           1.0 Initial Release
19
--
20
-- Additional Comments: 
21
 
22
----------------------------------------------------------------------------------
23
library IEEE;
24
use IEEE.STD_LOGIC_1164.ALL;
25
use IEEE.STD_LOGIC_UNSIGNED.ALL;
26
 
27
 
28
entity xcounter is
29
generic(
30
    XVAL      : std_logic_vector := x"3"
31
);
32
port(
33
    CLK_i     : in std_logic;
34
    RST_i     : in std_logic;
35
    CLKen_i   : in std_logic;
36
    COUNT_o   : out std_logic_vector(XVAL'length-1 downto 0);
37
    DONE_o    : out std_logic
38
 
39
);
40
end xcounter;
41
 
42
architecture Behavioral of xcounter is
43
 
44
   constant lastVal        : std_logic_vector(XVAL'length-1 downto 0) := XVAL;
45
   signal   counter_r      : std_logic_vector(XVAL'length-1 downto 0);
46
 
47
begin
48
-------------------------------------------------
49
    process(CLK_i, CLKen_i, RST_i)
50
    begin
51
        if rising_edge(CLK_i) then
52
            if(RST_i = '1') then
53
                counter           <= (others=>'0');
54
            elsif( CLKen_i = '1') then
55
                if( counter_r = lastVal) then
56
                    counter_r     <= (others=>'0');
57
                else
58
                    counter_r     <= counter_r + 1;
59
                end if;
60
            end if;
61
        end if;
62
    end process;
63
    -- two output signals done and the counter value
64
    DONE_o    <= '1' when counter_r = lastVal  else '0';
65
    COUNT_o   <= counter_r;
66
-------------------------------------------------
67
end Behavioral;
68
 

powered by: WebSVN 2.1.0

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