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

Subversion Repositories ax8

[/] [ax8/] [trunk/] [rtl/] [vhdl/] [AX_TC8.vhd] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jesus
--
2
-- AT90Sxxxx compatible microcontroller core
3
--
4 24 jesus
-- Version : 0221
5 3 jesus
--
6
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
7
--
8
-- All rights reserved
9
--
10
-- Redistribution and use in source and synthezised forms, with or without
11
-- modification, are permitted provided that the following conditions are met:
12
--
13
-- Redistributions of source code must retain the above copyright notice,
14
-- this list of conditions and the following disclaimer.
15
--
16
-- Redistributions in synthesized form must reproduce the above copyright
17
-- notice, this list of conditions and the following disclaimer in the
18
-- documentation and/or other materials provided with the distribution.
19
--
20
-- Neither the name of the author nor the names of other contributors may
21
-- be used to endorse or promote products derived from this software without
22
-- specific prior written permission.
23
--
24
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
28
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
-- POSSIBILITY OF SUCH DAMAGE.
35
--
36
-- Please report bugs to the author, but before you do so, please
37
-- make sure that this is not a derivative work and that
38
-- you have the latest version of this file.
39
--
40
-- The latest version of this file can be found at:
41
--      http://www.opencores.org/cvsweb.shtml/t51/
42
--
43
-- Limitations :
44
--
45
-- File history :
46
--
47 24 jesus
--      0146    : First release
48
--      0221    : Removed tristate
49 3 jesus
 
50
library IEEE;
51
use IEEE.std_logic_1164.all;
52
use IEEE.numeric_std.all;
53
 
54
entity AX_TC8 is
55
        port(
56
                Clk                     : in std_logic;
57
                Reset_n         : in std_logic;
58
                T                       : in std_logic;
59
                TCCR_Sel        : in std_logic;
60
                TCNT_Sel        : in std_logic;
61
                Wr                      : in std_logic;
62
                Data_In         : in std_logic_vector(7 downto 0);
63 24 jesus
                TCCR            : out std_logic_vector(2 downto 0);
64
                TCNT            : out std_logic_vector(7 downto 0);
65 3 jesus
                Int                     : out std_logic
66
        );
67
end AX_TC8;
68
 
69
architecture rtl of AX_TC8 is
70
 
71 24 jesus
        signal  TCCR_i          : std_logic_vector(2 downto 0);  -- Control Register
72
        signal  TCNT_i          : std_logic_vector(7 downto 0);  -- Timer/Counter
73 3 jesus
 
74
        signal  Tick            : std_logic;
75
 
76
begin
77
 
78 24 jesus
        TCCR <= TCCR_i;
79
        TCNT <= TCNT_i;
80
 
81 3 jesus
        -- Registers and counter
82
        process (Reset_n, Clk)
83
        begin
84
                if Reset_n = '0' then
85 24 jesus
                        TCCR_i<= "000";
86
                        TCNT_i <= "00000000";
87 3 jesus
                        Int <= '0';
88
                elsif Clk'event and Clk = '1' then
89
                        if TCCR_Sel = '1' and Wr = '1' then
90 24 jesus
                                TCCR_i <= Data_In(2 downto 0);
91 3 jesus
                        end if;
92
                        Int <= '0';
93
                        if Tick = '1' then
94 24 jesus
                                TCNT_i <= std_logic_vector(unsigned(TCNT_i) + 1);
95
                                if TCNT_i = "11111111" then
96 3 jesus
                                        Int <= '1';
97
                                end if;
98
                        end if;
99
                        if TCNT_Sel = '1' and Wr = '1' then
100 24 jesus
                                TCNT_i <= Data_In;
101 3 jesus
                                Int <= '0';
102
                        end if;
103
                end if;
104
        end process;
105
 
106
        -- Tick generator
107
        process (Clk, Reset_n)
108
                variable Prescaler : unsigned(9 downto 0);
109
                variable T_r : std_logic_vector(1 downto 0);
110
        begin
111
                if Reset_n = '0' then
112
                        Prescaler := (others => '0');
113
                        Tick <= '0';
114
                        T_r := "00";
115
                elsif Clk'event and Clk='1' then
116
                        Tick <= '0';
117 24 jesus
                        case TCCR_i is
118 3 jesus
                        when "000" =>
119
                        when "001" =>
120
                                Tick <= '1';
121
                        when "010" =>
122
                                if T_r(1) = '1' and T_r(0) = '0' then
123
                                        Tick <= '1';
124
                                end if;
125
                                T_r(1) := T_r(0);
126
                                T_r(0) := Prescaler(2);
127
                        when "011" =>
128
                                if T_r(1) = '1' and T_r(0) = '0' then
129
                                        Tick <= '1';
130
                                end if;
131
                                T_r(1) := T_r(0);
132
                                T_r(0) := Prescaler(5);
133
                        when "100" =>
134
                                if T_r(1) = '1' and T_r(0) = '0' then
135
                                        Tick <= '1';
136
                                end if;
137
                                T_r(1) := T_r(0);
138
                                T_r(0) := Prescaler(7);
139
                        when "101" =>
140
                                if T_r(1) = '1' and T_r(0) = '0' then
141
                                        Tick <= '1';
142
                                end if;
143
                                T_r(1) := T_r(0);
144
                                T_r(0) := Prescaler(9);
145
                        when "110" =>
146
                                if T_r(1) = '1' and T_r(0) = '0' then
147
                                        Tick <= '1';
148
                                end if;
149
                                T_r(1) := T_r(0);
150
                                T_r(0) := T;
151
                        when others =>
152
                                if T_r(1) = '0' and T_r(0) = '1' then
153
                                        Tick <= '1';
154
                                end if;
155
                                T_r(1) := T_r(0);
156
                                T_r(0) := T;
157
                        end case;
158
                        Prescaler := Prescaler + 1;
159
                end if;
160
        end process;
161
 
162
end;

powered by: WebSVN 2.1.0

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