source: firmware/FTM/Timing_counters/Timing_counter.vhd@ 10758

Last change on this file since 10758 was 10742, checked in by vogler, 14 years ago
FTM Timing counters added
File size: 3.7 KB
Line 
1----------------------------------------------------------------------------------
2-- Company: ETH Zurich, Institute for Particle Physics
3-- Engineer: Patrick Vogler
4--
5-- Create Date: March 11 2011
6-- Design Name:
7-- Module Name: FTM Timing counter
8-- Project Name:
9-- Target Devices:
10-- Tool versions:
11-- Description: 48 bit counter for time stamping and on-time counting
12--
13-- Dependencies:
14--
15-- Revision:
16-- Revision 0.01 - File Created
17-- Additional Comments:
18--
19--
20-- modifications:
21--
22-- April 12 2011 by Patrick Vogler
23--
24-- May 18 2011 by Patrick Vogler
25----------------------------------------------------------------------------------
26
27library IEEE;
28use IEEE.STD_LOGIC_1164.ALL;
29use IEEE.STD_LOGIC_ARITH.ALL;
30use IEEE.STD_LOGIC_UNSIGNED.ALL;
31
32use IEEE.NUMERIC_STD.ALL;
33
34---- Uncomment the following library declaration if instantiating
35---- any Xilinx primitives in this code.
36library UNISIM;
37use UNISIM.VComponents.all;
38
39library ftm_definitions;
40USE ftm_definitions.ftm_array_types.all;
41USE ftm_definitions.ftm_constants.all;
42
43
44
45entity Timing_counter is
46 port(
47
48-- Clock
49-------------------------------------------------------------------------------
50 clk : in STD_LOGIC; -- 50 MHz system clock
51
52 enable : in STD_LOGIC; -- enable counter
53 reset : in Std_LOGIC; -- reset counter
54
55 -- handshake signal
56 read_counter : in STD_LOGIC; -- read counter
57 reading_started : out STD_LOGIC;
58 reading_valid : out STD_LOGIC; -- counter reading at output ready
59
60 -- counter reading
61 counter_reading : out std_logic_vector (TC_WIDTH - 1 downto 0)
62 );
63end Timing_counter;
64
65
66
67architecture Behavioral of Timing_counter is
68
69type type_read_counter_state is (IDLE, COPY, SET_VALID, RESET_STARTED);
70signal read_counter_state : type_read_counter_state := IDLE;
71
72signal counting : std_logic_vector (TC_WIDTH - 1 downto 0);
73signal counter_reading_sig : std_logic_vector (TC_WIDTH - 1 downto 0);
74signal precounting : std_logic_vector (PRECOUNT_WIDTH - 1 downto 0);
75
76
77begin
78-- counting
79-------------------------------------------------------------------------------
80 count : process (clk, reset, enable)
81 begin
82 if reset = '1' then
83 counting <= (others => '0');
84 precounting <= (others => '0');
85
86 elsif rising_edge(clk) then
87 if enable = '1' then
88 precounting <= precounting + 1;
89 if (precounting = PRECOUNT_DIVIDER) then
90 counting <= counting + 1;
91 precounting <= (others => '0');
92 end if;
93 end if;
94 end if;
95 end process count;
96
97
98-- read counter
99-------------------------------------------------------------------------------
100 readout_counter : process (clk, read_counter)
101 begin
102 if rising_edge(clk) then
103 case read_counter_state is
104
105 when IDLE =>
106 if read_counter = '1' then
107 reading_valid <= '0';
108 reading_started <= '1';
109 read_counter_state <= COPY;
110 end if;
111
112 when COPY =>
113 counter_reading_sig <= counting;
114 read_counter_state <= SET_VALID;
115
116 when SET_VALID =>
117 read_counter_state <= RESET_STARTED;
118
119 when RESET_STARTED =>
120 if read_counter = '0' then
121 reading_started <= '0';
122 reading_valid <= '1';
123 read_counter_state <= IDLE;
124 end if;
125
126 end case;
127 end if;
128end process readout_counter;
129
130counter_reading <= counter_reading_sig;
131
132end Behavioral;
133
134
Note: See TracBrowser for help on using the repository browser.