OpenCores
URL https://opencores.org/ocsvn/system05/system05/trunk

Subversion Repositories system05

[/] [system05/] [trunk/] [rtl/] [vhdl/] [timer.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dilbert57
--===========================================================================--
2
--
3
--  S Y N T H E Z I A B L E    timer  dual 8 Bit timer
4
--
5
--  This core adheres to the GNU public license  
6
--
7
-- File name      : timer.vhd
8
--
9
-- Purpose        : Implements 2 x 8 bit timers
10
--                  
11
-- Dependencies   : ieee.Std_Logic_1164
12
--                  ieee.std_logic_unsigned
13
--
14
-- Uses           : None
15
--
16
-- Author         : John E. Kent      
17
--
18
--===========================================================================----
19
--
20
-- Revision History:
21
--===========================================================================--
22
--
23
-- Initial version - John Kent - 6 Sept 2002
24
--      Make CS & reset positive sense - John Kent - 30th May 2004
25
--
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.std_logic_unsigned.all;
30
 
31
entity timer is
32
        port (
33
         clk       : in  std_logic;
34
    rst       : in  std_logic;
35
    cs        : in  std_logic;
36
    rw        : in  std_logic;
37
    addr      : in  std_logic_vector(2 downto 0);
38
    data_in   : in  std_logic_vector(7 downto 0);
39
         data_out  : out std_logic_vector(7 downto 0);
40
         irq_out   : out std_logic;
41
         tim0_in   : in  std_logic;
42
         tim0_out  : out std_logic;
43
         tim1_in   : in  std_logic;
44
         tim1_out  : out std_logic
45
  );
46
end;
47
 
48
architecture timer_arch of timer is
49
signal timer_ctrl_reg : std_logic_vector(7 downto 0);
50
signal timer0_reg : std_logic_vector(7 downto 0);
51
signal timer1_reg : std_logic_vector(7 downto 0);
52
signal count0     : std_logic_vector(7 downto 0);
53
signal count1     : std_logic_vector(7 downto 0);
54
begin
55
 
56
--------------------------------
57
--
58
-- write control registers
59
-- doesn't do anything yet
60
--
61
--------------------------------
62
write_timer_control : process( clk, rst, cs, rw, addr, data_in, timer0_reg, timer1_reg, timer_ctrl_reg )
63
begin
64
  if clk'event and clk = '0' then
65
    if cs = '1' and rw = '0' then
66
           case addr is
67
           when "000" =>
68
                  timer_ctrl_reg <= data_in;
69
                  timer0_reg <= timer0_reg;
70
                  timer1_reg <= timer1_reg;
71
      when "010" =>
72
             timer_ctrl_reg <= timer_ctrl_reg;
73
                  timer0_reg <= data_in;
74
                  timer1_reg <= timer1_reg;
75
           when "011" =>
76
             timer_ctrl_reg <= timer_ctrl_reg;
77
                  timer0_reg <= timer0_reg;
78
                  timer1_reg <= data_in;
79
           when others =>
80
             timer_ctrl_reg <= timer_ctrl_reg;
81
                  timer0_reg <= timer0_reg;
82
                  timer1_reg <= timer1_reg;
83
                end case;
84
         else
85
           timer_ctrl_reg <= timer_ctrl_reg;
86
                timer0_reg <= timer0_reg;
87
                timer1_reg <= timer1_reg;
88
    end if;
89
  end if;
90
end process;
91
 
92
read_timer_control : process( addr, timer_ctrl_reg, timer0_reg, timer1_reg, count0, count1 )
93
begin
94
  case addr is
95
  when "000" =>
96
    data_out <= timer_ctrl_reg;
97
  when "010" =>
98
    data_out <= timer0_reg;
99
  when "011" =>
100
    data_out <= timer1_reg;
101
  when "110" =>
102
    data_out <= count0;
103
  when "111" =>
104
    data_out <= count1;
105
  when others =>
106
    data_out <= "00000000";
107
  end case;
108
  irq_out <= timer_ctrl_reg(0);
109
end process;
110
 
111
--------------------------------
112
--
113
-- counters
114
--
115
--------------------------------
116
 
117
my_counter: process( clk, rst, count0, count1, tim0_in, tim1_in )
118
begin
119
  if rst = '1' then
120
         count0 <= "00000000";
121
  elsif tim0_in'event and tim0_in = '0' then
122
           if count0 = timer0_reg then
123
                  count0 <= "00000000";
124
                else
125
             count0 <= count0 + 1;
126
                end if;
127
  end if;
128
 
129
  if rst = '1' then
130
         count1 <= "00000000";
131
  elsif tim1_in'event and tim1_in = '1' then
132
           if count1 = timer1_reg then
133
                  count1 <= "00000000";
134
                else
135
             count1 <= count1 + 1;
136
                end if;
137
  end if;
138
 
139
  tim0_out <= count0(7);
140
  tim1_out <= count1(7);
141
end process;
142
 
143
end timer_arch;
144
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.