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

Subversion Repositories fade_ether_protocol

[/] [fade_ether_protocol/] [trunk/] [stable_jumbo_frames_version/] [fpga/] [src/] [AFCK/] [frq_counter.vhd] - Blame information for rev 41

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

Line No. Rev Author Line
1 37 wzab
-------------------------------------------------------------------------------
2
-- Title      : frq_counter
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : frq_counter.vhd
6
-- Author     : Wojciech M. Zabolotny  <wzab@wzdell.nasz.dom>
7
-- Company    : 
8
-- Created    : 2015-05-15
9
-- Last update: 2015-05-15
10
-- Platform   : 
11
-- Standard   : VHDL'93/02
12
-------------------------------------------------------------------------------
13
-- Description: Simple frequency counter for monitoring of clock frequency
14
--              inside FPGA
15
-------------------------------------------------------------------------------
16
-- Copyright (c) 2015 
17
-------------------------------------------------------------------------------
18
-- Revisions  :
19
-- Date        Version  Author  Description
20
-- 2015-05-15  1.0      wzab    Created
21
-------------------------------------------------------------------------------
22
library ieee;
23
use ieee.std_logic_1164.all;
24
use ieee.numeric_std.all;
25
 
26
entity frq_counter is
27
 
28
  generic (
29
    CNT_TIME   : integer := 10000000; -- Counting time in cycles of ref_clk;
30
    CNT_LENGTH : integer := 32);        -- Length of the pulse counter
31
 
32
  port (
33
    ref_clk : in  std_logic;
34
    rst_p   : in  std_logic;
35
    frq_in  : in  std_logic;
36
    frq_out : out std_logic_vector(CNT_LENGTH-1 downto 0));
37
 
38
end entity frq_counter;
39
 
40
architecture beh of frq_counter is
41
 
42
  signal pulse_cnt : unsigned(CNT_LENGTH-1 downto 0) := (others => '0');
43
  signal gate_cnt : integer range 0 to CNT_TIME+2 := 0;
44
  signal clear, gate, gate_ack, clear_ack : std_logic := '0';
45
 
46
begin  -- architecture beh
47
 
48
  clk1: process (ref_clk, rst_p) is
49
  begin  -- process clk1
50
    if rst_p = '1' then               -- asynchronous reset (active low)
51
      gate_cnt <= 0;
52
      frq_out <= (others => '0');
53
    elsif ref_clk'event and ref_clk = '1' then  -- rising clock edge
54
      if gate_cnt = 0 then
55
        gate <= '1';
56
        gate_cnt <= gate_cnt + 1;
57
      elsif gate_cnt = CNT_TIME then
58
        gate <= '0';
59
        if gate_ack = '0' then
60
          frq_out <= std_logic_vector(pulse_cnt);
61
          clear <= '1';
62
          gate_cnt <= gate_cnt+1;
63
        end if;
64
      elsif gate_cnt = CNT_TIME+1 then
65
        if clear_ack = '1' then
66
          clear <= '0';
67
          gate_cnt <= CNT_TIME+2;
68
        end if;
69
      elsif gate_cnt = CNT_TIME+2 then
70
        if clear_ack = '0' then
71
          gate_cnt <= 0;
72
        end if;
73
      else
74
        gate_cnt <= gate_cnt + 1;
75
      end if;
76
    end if;
77
  end process clk1;
78
 
79
  clk2: process (frq_in, rst_p) is
80
  begin  -- process clk2
81
    if rst_p = '1' then                   -- asynchronous reset (active low)
82
      pulse_cnt <= (others => '0');
83
      gate_ack <= '0';
84
      clear_ack <= '0';
85
    elsif frq_in'event and frq_in = '1' then  -- rising clock edge
86
      gate_ack <= gate;
87
      clear_ack <= clear;
88
      if gate_ack = '1' then
89
        pulse_cnt <= pulse_cnt + 1;
90
      elsif clear_ack = '1' then
91
        pulse_cnt <= (others => '0');
92
      end if;
93
    end if;
94
  end process clk2;
95
 
96
end architecture beh;

powered by: WebSVN 2.1.0

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