------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------
|
--
|
--
|
-- Geoffrey Ottoy - DraMCo research group
|
-- Geoffrey Ottoy - DraMCo research group
|
--
|
--
|
-- Module Name: counter_sync.vhd / entity counter_sync
|
-- Module Name: counter_sync.vhd / entity counter_sync
|
--
|
--
|
-- Last Modified: 23/01/2012
|
-- Last Modified: 23/01/2012
|
--
|
--
|
-- Description: counter with synchronous count enable. It generates an
|
-- Description: counter with synchronous count enable. It generates an
|
-- overflow when max_value is reached
|
-- overflow when max_value is reached
|
--
|
--
|
--
|
--
|
-- Dependencies: none
|
-- Dependencies: none
|
--
|
--
|
-- Revision:
|
-- Revision:
|
-- Revision 2.00 - moved max_value from generic to port so it is changeable in runtime
|
-- Revision 2.00 - moved max_value from generic to port so it is changeable in runtime
|
-- Revision 1.00 - Architecture
|
-- Revision 1.00 - Architecture
|
-- Revision 0.01 - File Created
|
-- Revision 0.01 - File Created
|
--
|
--
|
--
|
--
|
------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------
|
--
|
--
|
-- NOTICE:
|
-- NOTICE:
|
--
|
--
|
-- Copyright DraMCo research group. 2011. This code may be contain portions patented
|
-- Copyright DraMCo research group. 2011. This code may be contain portions patented
|
-- by other third parties!
|
-- by other third parties!
|
--
|
--
|
------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------
|
library IEEE;
|
library IEEE;
|
use IEEE.STD_LOGIC_1164.ALL;
|
use IEEE.STD_LOGIC_1164.ALL;
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
|
|
---- Uncomment the following library declaration if instantiating
|
---- Uncomment the following library declaration if instantiating
|
---- any Xilinx primitives in this code.
|
---- any Xilinx primitives in this code.
|
--library UNISIM;
|
--library UNISIM;
|
--use UNISIM.VComponents.all;
|
--use UNISIM.VComponents.all;
|
|
|
entity counter_sync is
|
entity counter_sync is
|
generic(max_value : integer := 1024
|
generic(max_value : integer := 1024
|
);
|
);
|
port(reset_value : in integer;
|
port(reset_value : in integer;
|
core_clk : in STD_LOGIC;
|
core_clk : in STD_LOGIC;
|
ce : in STD_LOGIC;
|
ce : in STD_LOGIC;
|
reset : in STD_LOGIC;
|
reset : in STD_LOGIC;
|
overflow : out STD_LOGIC
|
overflow : out STD_LOGIC
|
);
|
);
|
end counter_sync;
|
end counter_sync;
|
|
|
architecture Behavioral of counter_sync is
|
architecture Behavioral of counter_sync is
|
|
|
signal overflow_i : std_logic := '0';
|
signal overflow_i : std_logic := '0';
|
begin
|
begin
|
|
|
overflow <= overflow_i;
|
overflow <= overflow_i;
|
|
|
COUNT_PROC: process(core_clk, ce, reset)
|
COUNT_PROC: process(core_clk, ce, reset)
|
variable steps_counter : integer range 0 to max_value-1 := 0;
|
variable steps_counter : integer range 0 to max_value-1 := 0;
|
begin
|
begin
|
if reset = '1' then -- reset counter
|
if reset = '1' then -- reset counter
|
steps_counter := 0;
|
steps_counter := 0;
|
overflow_i <= '0';
|
overflow_i <= '0';
|
elsif rising_edge(core_clk) then
|
elsif rising_edge(core_clk) then
|
if ce = '1' then -- count
|
if ce = '1' then -- count
|
if steps_counter = (reset_value-1) then -- generate overflow and reset counter
|
if steps_counter = (reset_value-1) then -- generate overflow and reset counter
|
steps_counter := 0;
|
steps_counter := 0;
|
overflow_i <= '1';
|
overflow_i <= '1';
|
else -- just count
|
else -- just count
|
steps_counter := steps_counter + 1;
|
steps_counter := steps_counter + 1;
|
overflow_i <= '0';
|
overflow_i <= '0';
|
end if;
|
end if;
|
else
|
else
|
overflow_i <= '0';
|
overflow_i <= '0';
|
steps_counter := steps_counter;
|
steps_counter := steps_counter;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
|
|