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

Last change on this file since 11514 was 10037, checked in by weitzel, 14 years ago
FTU counter changed from 16 to 30 bit
File size: 3.8 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-- Revision 0.02 - counter range changed from 16 to 30 bit, 19.10.2010, Q. Weitzel
18-- Revision 0.03 - no local clock division anymore, 20.10.2010, Q. Weitzel
19-- Additional Comments:
20--
21----------------------------------------------------------------------------------
22
23library IEEE;
24use IEEE.STD_LOGIC_1164.ALL;
25use IEEE.STD_LOGIC_ARITH.ALL;
26use IEEE.STD_LOGIC_UNSIGNED.ALL;
27
28library ftu_definitions;
29USE ftu_definitions.ftu_array_types.all;
30USE ftu_definitions.ftu_constants.all;
31
32---- Uncomment the following library declaration if instantiating
33---- any Xilinx primitives in this code.
34--library UNISIM;
35--use UNISIM.VComponents.all;
36
37entity FTU_rate_counter is
38 port(
39 clk : in std_logic;
40 cntr_reset : in std_logic;
41 trigger : in std_logic;
42 prescaling : in std_logic_vector(7 downto 0);
43 counts : out integer range 0 to 2**30 - 1 := 0;
44 overflow : out std_logic := '0';
45 new_rate : out std_logic
46 );
47end FTU_rate_counter;
48
49architecture Behavioral of FTU_rate_counter is
50
51 signal counting_period : integer range 0 to 128*COUNTER_FREQUENCY := 128*COUNTER_FREQUENCY;
52 signal period_finished : std_logic := '0';
53 signal trigger_counts : integer range 0 to 2**30 - 1 := 0;
54 signal overflow_sig : std_logic := '0';
55 signal new_rate_sig : std_logic := '0';
56
57begin
58
59 process(cntr_reset, clk)
60
61 variable clk_cntr : integer range 0 to 128*COUNTER_FREQUENCY := 0;
62
63 begin
64
65 if cntr_reset = '1' then
66
67 clk_cntr := 0;
68 period_finished <= '1';
69 new_rate_sig <= '0';
70 counts <= 0;
71 overflow <= '0';
72
73 elsif rising_edge(clk) then
74
75 if (clk_cntr < counting_period - 1) then
76 clk_cntr := clk_cntr + 1;
77 period_finished <= '0';
78 new_rate_sig <= '0';
79 else
80 clk_cntr := 0;
81 period_finished <= '1';
82 new_rate_sig <= '1';
83 counts <= trigger_counts;
84 overflow <= overflow_sig;
85 end if;
86 end if;
87 end process;
88
89 process(trigger, period_finished)
90 begin
91 if period_finished = '1' then
92 trigger_counts <= 0;
93 overflow_sig <= '0';
94 else
95 if rising_edge(trigger) then
96 if (trigger_counts < 2**30 - 1) then
97 trigger_counts <= trigger_counts + 1;
98 else
99 trigger_counts <= 0;
100 overflow_sig <= '1';
101 end if;
102 end if;
103 end if;
104 end process;
105
106 process(cntr_reset, prescaling)
107 begin
108 if rising_edge(cntr_reset) then
109 --calculate counting period from prescaling value
110 --default is 0.5s - 128s if CNTR_FREQ_DIVIDER = 1
111 --if (prescaling = "00000000") then
112 --counting_period <= COUNTER_FREQUENCY / (2 * CNTR_FREQ_DIVIDER);
113 --elsif (prescaling = "11111111") then
114 --counting_period <= 128 * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER);
115 --else
116 --counting_period <= ((conv_integer(unsigned(prescaling)) + 1) / 2) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER);
117 --end if;
118 if ((conv_integer(unsigned(prescaling))) mod 2 = 0) then
119 counting_period <= ((((conv_integer(unsigned(prescaling)) / 2)) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER)) + (COUNTER_FREQUENCY / (2 * CNTR_FREQ_DIVIDER)));
120 else
121 counting_period <= (((conv_integer(unsigned(prescaling)) - 1) / 2) + 1) * (COUNTER_FREQUENCY / CNTR_FREQ_DIVIDER);
122 end if;
123 end if;
124 end process;
125
126 new_rate <= new_rate_sig;
127
128end Behavioral;
Note: See TracBrowser for help on using the repository browser.