source: firmware/FTM/trigger/drivers/time_window/time_counter.vhd@ 18066

Last change on this file since 18066 was 10366, checked in by weitzel, 14 years ago
FTM trigger manager from MCSE added; DCM arrangement changed; changes in FTM ethernet module
File size: 4.2 KB
Line 
1--=======================================================================================
2-- TITLE : Timer
3-- DESCRIPTION : Timer for time coincidence windows
4-- FILE : time_counter.vhd
5-- COMPANY : Micro-Cameras & Space Exploration SA
6--=======================================================================================
7-- CREATION
8-- DATE AUTHOR PROJECT REVISION
9-- 02/03/2011 JGi FTM 110302a
10--=======================================================================================
11-- MODIFICATION HISTORY
12-- DATE AUTHOR PROJECT REVISION COMMENTS
13-- 02/03/2011 JGi FTM 110302a Description
14--=======================================================================================
15-- Library Definition
16library ieee;
17 use ieee.std_logic_1164.all;
18 use ieee.numeric_std.all;
19
20-- Entity Definition
21entity time_counter is
22 port( --clock
23 clk_250MHz : in std_logic;
24 --control
25 enable : in std_logic;
26 window : in std_logic_vector(3 downto 0);
27 --I/O
28 start_rise : in std_logic;
29 start_fall : in std_logic;
30 counting : out std_logic);
31end time_counter;
32
33-- Architecture Definition
34architecture RTL of time_counter is
35
36 type t_reg is record
37 -- Internal register declaration
38 enable : std_logic;
39 started : std_logic;
40 done : std_logic;
41 window : unsigned(3 downto 0);
42 counter : unsigned(3 downto 0);
43 -- Ouput register declaration
44 counting : std_logic;
45 end record;
46
47 signal i_next_reg : t_reg := (enable => '0',
48 started => '0',
49 done => '0',
50 window => (others => '0'),
51 counter => (others => '0'),
52 counting => '0');
53 signal i_reg : t_reg := (enable => '0',
54 started => '0',
55 done => '0',
56 window => (others => '0'),
57 counter => (others => '0'),
58 counting => '0');
59
60begin
61
62 -- Combinatorial logic
63 process(enable, window, start_rise, start_fall, i_reg)
64 variable v_reg : t_reg := (enable => '0',
65 started => '0',
66 done => '0',
67 window => (others => '0'),
68 counter => (others => '0'),
69 counting => '0');
70 begin
71 v_reg := i_reg;
72 --===================================================================================
73
74 --===================================================================================
75 -- Counter management
76 --===================================================================================
77 -- Register activation signal (From active FTU list)
78 v_reg.enable := enable;
79 -- Register window width to improve speed
80 v_reg.window := unsigned(window);
81 -- Register enables to detect rising edges on them
82 v_reg.started := start_rise or start_fall;
83
84 -- Counter is counting permanently
85 v_reg.counter := i_reg.counter+1;
86
87 -- If enabled and input rising edge, reset counter
88 if i_reg.enable = '1' and (start_rise = '1' or start_fall = '1') and
89 i_reg.started = '0' then
90 v_reg.counting := '1';
91 v_reg.counter := (others => '0');
92 end if;
93
94 v_reg.done := '0';
95 -- If inputs rised and counter reahc the value then done
96 if i_reg.counter = i_reg.window and i_reg.counting = '1' then
97 v_reg.done := '1';
98 end if;
99
100 -- Disable counter comparison if done
101 if i_reg.done = '1' then
102 v_reg.counting := '0';
103 end if;
104 --===================================================================================
105
106 --===================================================================================
107 -- Drive register input
108 i_next_reg <= v_reg;
109
110 --===================================================================================
111 -- Output assignation
112 counting <= i_reg.counting;
113 --===================================================================================
114 end process;
115
116 -- Sequential logic
117 process(clk_250MHz)
118 begin
119 if rising_edge(clk_250MHz) then
120 i_reg <= i_next_reg;
121 end if;
122 end process;
123
124end RTL;
Note: See TracBrowser for help on using the repository browser.