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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [trunk/] [rtl/] [vhdl/] [core/] [counter_sync.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 JonasDC
------------------------------------------------------------------------------------ 
2
--                      
3
-- Geoffrey Ottoy - DraMCo research group
4
--
5
-- Module Name: counter_sync.vhd / entity counter_sync
6
-- 
7
-- Last Modified:       23/01/2012 
8
-- 
9
-- Description:         counter with synchronous count enable. It generates an
10
--                                              overflow when max_value is reached
11
--
12
--
13
-- Dependencies:        none
14
--
15
-- Revision:
16
-- Revision 2.00 - moved max_value from generic to port so it is changeable in runtime
17
--      Revision 1.00 - Architecture
18
--      Revision 0.01 - File Created
19
--
20
--
21
------------------------------------------------------------------------------------
22
--
23
-- NOTICE:
24
--
25
-- Copyright DraMCo research group. 2011. This code may be contain portions patented
26
-- by other third parties!
27
--
28
------------------------------------------------------------------------------------
29
library IEEE;
30
use IEEE.STD_LOGIC_1164.ALL;
31
use IEEE.STD_LOGIC_ARITH.ALL;
32
use IEEE.STD_LOGIC_UNSIGNED.ALL;
33
 
34
---- Uncomment the following library declaration if instantiating
35
---- any Xilinx primitives in this code.
36
--library UNISIM;
37
--use UNISIM.VComponents.all;
38
 
39
entity counter_sync is
40
        generic(max_value : integer := 1024
41
        );
42
   port(reset_value : in integer;
43
                        core_clk : in  STD_LOGIC;
44
                             ce : in  STD_LOGIC;
45
                          reset : in  STD_LOGIC;
46
                  overflow : out STD_LOGIC
47
        );
48
end counter_sync;
49
 
50
architecture Behavioral of counter_sync is
51
 
52
        signal overflow_i : std_logic := '0';
53
begin
54
 
55
        overflow <= overflow_i;
56
 
57
        COUNT_PROC: process(core_clk, ce, reset)
58
                variable steps_counter : integer range 0 to max_value-1 := 0;
59
        begin
60
                if reset = '1' then  -- reset counter
61
                        steps_counter := 0;
62
                        overflow_i <= '0';
63
                elsif rising_edge(core_clk) then
64
                        if ce = '1' then -- count
65
                                if steps_counter = (reset_value-1) then -- generate overflow and reset counter
66
                                        steps_counter := 0;
67
                                        overflow_i <= '1';
68
                                else    -- just count
69
                                        steps_counter := steps_counter + 1;
70
                                        overflow_i <= '0';
71
                                end if;
72
                        else
73
                                overflow_i <= '0';
74
                                steps_counter := steps_counter;
75
                        end if;
76
                end if;
77
        end process;
78
 
79
end Behavioral;

powered by: WebSVN 2.1.0

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