source: firmware/FTU/counter/FTU_rate_counter.vhd@ 9882

Last change on this file since 9882 was 9880, checked in by weitzel, 14 years ago
FTU_rate_counter added and FTU_control state machine extended
File size: 3.6 KB
Line 
1----------------------------------------------------------------------------------
2-- Company: ETH Zurich, Institute for Particle Physics
3-- Engineer: Q. Weitzel, P. Vogler
4--
5-- Create Date: 10:38:40 08/18/2010
6-- Design Name:
7-- Module Name: FTU_rate_counter - Behavioral
8-- Project Name:
9-- Target Devices:
10-- Tool versions:
11-- Description: Entity to count trigger and sum patch rates of FTU board
12--
13-- Dependencies:
14--
15-- Revision:
16-- Revision 0.01 - File Created
17-- Additional Comments:
18--
19----------------------------------------------------------------------------------
20
21library IEEE;
22use IEEE.STD_LOGIC_1164.ALL;
23use IEEE.STD_LOGIC_ARITH.ALL;
24use IEEE.STD_LOGIC_UNSIGNED.ALL;
25
26library ftu_definitions;
27USE ftu_definitions.ftu_array_types.all;
28USE ftu_definitions.ftu_constants.all;
29
30---- Uncomment the following library declaration if instantiating
31---- any Xilinx primitives in this code.
32--library UNISIM;
33--use UNISIM.VComponents.all;
34
35entity FTU_rate_counter is
36 port(
37 clk : in std_logic;
38 cntr_reset : in std_logic;
39 trigger : in std_logic;
40 prescaling : in std_logic_vector(7 downto 0);
41 counts : out integer range 0 to 2**16 - 1;
42 overflow : out std_logic
43 );
44end FTU_rate_counter;
45
46architecture Behavioral of FTU_rate_counter is
47
48 signal counting_period : integer range 0 to 128*COUNTER_FREQUENCY := 128*COUNTER_FREQUENCY;
49 signal period_finished : std_logic := '0';
50 signal trigger_counts : integer range 0 to 2**16 - 1 := 0;
51 signal clk_1M_sig : std_logic;
52 signal overflow_sig : std_logic := '0';
53
54 component Clock_Divider
55 port(
56 clock_in : IN STD_LOGIC;
57 clock_out : OUT STD_LOGIC
58 );
59 end component;
60
61begin
62
63 Inst_Clock_Divider : Clock_Divider
64 port map (
65 clock_in => clk,
66 clock_out => clk_1M_sig
67 );
68
69 process(cntr_reset, clk_1M_sig)
70 variable clk_cntr : integer range 0 to 128*COUNTER_FREQUENCY := 0;
71 begin
72 if (cntr_reset = '1') then
73 counting_period <= ((conv_integer(unsigned(prescaling)) + 1) / 2)*COUNTER_FREQUENCY;
74 clk_cntr := 0;
75 period_finished <= '1';
76 elsif rising_edge(clk_1M_sig) then
77 if (clk_cntr < counting_period - 1) then
78 clk_cntr := clk_cntr + 1;
79 period_finished <= '0';
80 else
81 clk_cntr := 0;
82 period_finished <= '1';
83 counts <= trigger_counts;
84 end if;
85 end if;
86 end process;
87
88 process(trigger, period_finished)
89 begin
90 if rising_edge(period_finished) then
91 trigger_counts <= 0;
92 else
93 if rising_edge(trigger) then
94 trigger_counts <= trigger_counts + 1;
95 end if;
96 end if;
97 end process;
98
99 overflow <= overflow_sig;
100
101end Behavioral;
102
103----------------------------------------------------------------------------------
104
105library IEEE;
106use IEEE.STD_LOGIC_1164.ALL;
107use IEEE.STD_LOGIC_ARITH.ALL;
108use IEEE.STD_LOGIC_UNSIGNED.ALL;
109
110library ftu_definitions;
111USE ftu_definitions.ftu_array_types.all;
112USE ftu_definitions.ftu_constants.all;
113
114entity Clock_Divider is
115 generic(
116 divider : integer := INT_CLK_FREQUENCY / COUNTER_FREQUENCY
117 );
118 port(
119 clock_in : in std_logic;
120 clock_out : out std_logic := '0'
121 );
122end entity Clock_Divider;
123
124architecture RTL of Clock_Divider is
125
126begin
127
128 process (clock_in)
129 variable Z: integer range 0 to divider - 1;
130 begin
131 if rising_edge(clock_in) then
132 if (Z < divider - 1) then
133 Z := Z + 1;
134 else
135 Z := 0;
136 end if;
137 if (Z = 0) then
138 clock_out <= '1';
139 end if;
140 if (Z = divider / 2) then
141 clock_out <= '0';
142 end if;
143 end if;
144 end process;
145
146end architecture RTL;
Note: See TracBrowser for help on using the repository browser.