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] - Diff between revs 3 and 19

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 19
----------------------------------------------------------------------  
----------------------------------------------------------------------  
----  counter_sync                                                ---- 
----  counter_sync                                                ---- 
----                                                              ---- 
----                                                              ---- 
----  This file is part of the                                    ----
----  This file is part of the                                    ----
----    Modular Simultaneous Exponentiation Core project          ---- 
----    Modular Simultaneous Exponentiation Core project          ---- 
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
----                                                              ---- 
----                                                              ---- 
----  Description                                                 ---- 
----  Description                                                 ---- 
----     counter with synchronous count enable. It generates an   ----
----     counter with synchronous count enable. It generates an   ----
----     overflow when max_value is reached                       ----
----     overflow when max_value is reached                       ----
----                                                              ----
----                                                              ----
----  Dependencies: none                                          ----
----  Dependencies: none                                          ----
----                                                              ----
----                                                              ----
----  Authors:                                                    ----
----  Authors:                                                    ----
----      - Geoffrey Ottoy, DraMCo research group                 ----
----      - Geoffrey Ottoy, DraMCo research group                 ----
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
----                                                              ---- 
----                                                              ---- 
---------------------------------------------------------------------- 
---------------------------------------------------------------------- 
----                                                              ---- 
----                                                              ---- 
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
----                                                              ---- 
----                                                              ---- 
---- This source file may be used and distributed without         ---- 
---- This source file may be used and distributed without         ---- 
---- restriction provided that this copyright statement is not    ---- 
---- restriction provided that this copyright statement is not    ---- 
---- removed from the file and that any derivative work contains  ---- 
---- removed from the file and that any derivative work contains  ---- 
---- the original copyright notice and the associated disclaimer. ---- 
---- the original copyright notice and the associated disclaimer. ---- 
----                                                              ---- 
----                                                              ---- 
---- This source file is free software; you can redistribute it   ---- 
---- This source file is free software; you can redistribute it   ---- 
---- and/or modify it under the terms of the GNU Lesser General   ---- 
---- and/or modify it under the terms of the GNU Lesser General   ---- 
---- Public License as published by the Free Software Foundation; ---- 
---- Public License as published by the Free Software Foundation; ---- 
---- either version 2.1 of the License, or (at your option) any   ---- 
---- either version 2.1 of the License, or (at your option) any   ---- 
---- later version.                                               ---- 
---- later version.                                               ---- 
----                                                              ---- 
----                                                              ---- 
---- This source is distributed in the hope that it will be       ---- 
---- This source is distributed in the hope that it will be       ---- 
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
---- details.                                                     ---- 
---- details.                                                     ---- 
----                                                              ---- 
----                                                              ---- 
---- You should have received a copy of the GNU Lesser General    ---- 
---- You should have received a copy of the GNU Lesser General    ---- 
---- Public License along with this source; if not, download it   ---- 
---- Public License along with this source; if not, download it   ---- 
---- from http://www.opencores.org/lgpl.shtml                     ---- 
---- from http://www.opencores.org/lgpl.shtml                     ---- 
----                                                              ---- 
----                                                              ---- 
----------------------------------------------------------------------
----------------------------------------------------------------------
 
 
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;
 
 
 
-- counter with synchronous count enable. It generates an
 
-- overflow when max_value is reached
entity counter_sync is
entity counter_sync is
  generic(
  generic(
    max_value : integer := 1024
    max_value : integer := 1024 -- maximum value (constraints the nr bits for counter)
  );
  );
  port(
  port(
    reset_value : in integer;
    reset_value : in integer;   -- value the counter counts to
    core_clk    : in std_logic;
    core_clk    : in std_logic; -- clock input
    ce          : in std_logic;
    ce          : in std_logic; -- count enable
    reset       : in std_logic;
    reset       : in std_logic; -- reset input
    overflow    : out std_logic
    overflow    : out std_logic -- gets high when counter reaches reset_value
  );
  );
end counter_sync;
end counter_sync;
 
 
 
 
architecture Behavioral of counter_sync is
architecture Behavioral of counter_sync is
 
 
        signal overflow_i : std_logic := '0';
 
begin
begin
 
 
        overflow <= overflow_i;
        -- counter process with asynchronous active high reset
 
        count_proc: process(core_clk, ce, reset)
        COUNT_PROC: process(core_clk, ce, reset)
                variable steps_counter : integer range 0 to max_value-1;
                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 <= '0';
                elsif rising_edge(core_clk) then
                elsif rising_edge(core_clk) then
                        if ce = '1' then -- count
                        -- counter is enabled, count till reset_value
 
                        if ce = '1' then
                                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 <= '1';
                                else    -- just count
                                else    -- just count
                                        steps_counter := steps_counter + 1;
                                        steps_counter := steps_counter + 1;
                                        overflow_i <= '0';
                                        overflow <= '0';
                                end if;
                                end if;
                        else
                        else
                                overflow_i <= '0';
                        --counter disabled, halt counter
 
                                overflow <= '0';
                                steps_counter := steps_counter;
                                steps_counter := steps_counter;
                        end if;
                        end if;
                end if;
                end if;
        end process;
        end process;
 
 
end Behavioral;
end Behavioral;
 No newline at end of file
 No newline at end of file
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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