]> rtime.felk.cvut.cz Git - fpga/virtex2/msp_motion.git/blob - mcu_periph/qcounter_mcu16.vhd
Motor feedback IRQ generator
[fpga/virtex2/msp_motion.git] / mcu_periph / qcounter_mcu16.vhd
1 library ieee;
2 use ieee.std_logic_1164.ALL;
3 use ieee.std_logic_arith.ALL;
4
5 --------------------------------------------------------------------------------
6
7 entity qcounter_mcu16 is
8   port (
9     -- Peripheral bus interface
10     ACK_O  : out std_logic;
11     ADR_I  : in  std_logic;
12     CLK_I  : in  std_logic;
13     DAT_O  : out std_logic_vector (15 downto 0);
14     SEL_I  : in  std_logic;
15     STB_I  : in  std_logic;
16     -- QCounter component interface
17     QCOUNT : in  std_logic_vector (31 downto 0));
18 end qcounter_mcu16;
19
20 --------------------------------------------------------------------------------
21
22 architecture behavioral of qcounter_mcu16 is
23
24   -- When reading whole 32-bit qcount input, first QCNTL has to be loaded, because
25   -- this event causes QCNTH to latch appropriate value of QCOUNT. This procedure
26   -- ensures that correct value is read.
27
28   -- Register of upper 16 bits of QCOUNT input.
29   signal upper_qcount : std_logic_vector (15 downto 0);
30   signal read_en      : std_logic;
31   
32 --------------------------------------------------------------------------------
33
34 begin
35
36   ACK_O <= read_en;
37   
38   with ADR_I select
39     DAT_O <=
40     QCOUNT (15 downto 0) when '0',
41     upper_qcount         when '1',
42     (others => 'X')      when others;
43
44   read_en <= SEL_I and STB_I;
45
46   
47   -- Upper qcounter register
48   QCNTH : process (CLK_I)
49   begin
50     if rising_edge(CLK_I) then
51       if read_en = '1' then
52         upper_qcount <= QCOUNT (31 downto 16);
53       end if;
54     end if;
55   end process;
56
57
58 end behavioral;
59