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

Subversion Repositories ppx16

[/] [ppx16/] [trunk/] [rtl/] [vhdl/] [PPX_TMR.vhd] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jesus
--
2
-- PIC16xx compatible microcontroller core
3
--
4 11 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
--      Registers implemented in this entity are INDF, PCL, STATUS, FSR, (PCLATH)
45
--      other registers must be implemented externally including GPR
46
--
47
-- File history :
48
--
49
 
50
library IEEE;
51
use IEEE.std_logic_1164.all;
52
use IEEE.numeric_std.all;
53
 
54
entity PPX_TMR is
55
        port(
56
                Clk                     : in std_logic;
57
                Reset_n         : in std_logic;
58
                CKI                     : in std_logic;
59
                SE                      : in std_logic;
60
                CS                      : in std_logic;
61
                PS                      : in std_logic_vector(2 downto 0);
62
                PSA                     : in std_logic;
63
                TMR_Sel         : in std_logic;
64
                Wr                      : in std_logic;
65
                Data_In         : in std_logic_vector(7 downto 0);
66
                Data_Out        : out std_logic_vector(7 downto 0);
67
                TOF                     : out std_logic
68
        );
69
end PPX_TMR;
70
 
71
architecture rtl of PPX_TMR is
72
 
73
        signal  TMR             : std_logic_vector(7 downto 0);
74
 
75
        signal  Tick    : std_logic;
76
 
77
begin
78
 
79 11 jesus
        Data_Out <= TMR;
80
 
81 3 jesus
        -- Registers and counter
82
        process (Reset_n, Clk)
83
        begin
84
                if Reset_n = '0' then
85
                        TMR <= "00000000";
86
                        TOF <= '0';
87
                elsif Clk'event and Clk = '1' then
88
                        TOF <= '0';
89
                        if Tick = '1' then
90
                                TMR <= std_logic_vector(unsigned(TMR) + 1);
91
                                if TMR = "11111111" then
92
                                        TOF <= '1';
93
                                end if;
94
                        end if;
95
                        if TMR_Sel = '1' and Wr = '1' then
96
                                TMR <= Data_In;
97
                                TOF <= '0';
98
                        end if;
99
                end if;
100
        end process;
101
 
102
        -- Tick generator
103
        process (Clk, Reset_n)
104
                variable Prescaler : unsigned(7 downto 0);
105
                variable CKI_r : std_logic_vector(1 downto 0);
106
                variable P_r : std_logic_vector(1 downto 0);
107
                variable Tick0 : std_logic;
108
        begin
109
                if Reset_n = '0' then
110
                        Prescaler := (others => '0');
111
                        Tick <= '0';
112
                        Tick0 := '0';
113
                        CKI_r := "00";
114
                        P_r := "00";
115
                elsif Clk'event and Clk='1' then
116
                        P_r(1) := P_r(0);
117
                        case PS is
118
                        when "000" => P_r(0) := Prescaler(0);
119
                        when "001" => P_r(0) := Prescaler(1);
120
                        when "010" => P_r(0) := Prescaler(2);
121
                        when "011" => P_r(0) := Prescaler(3);
122
                        when "100" => P_r(0) := Prescaler(4);
123
                        when "101" => P_r(0) := Prescaler(5);
124
                        when "110" => P_r(0) := Prescaler(6);
125
                        when others => P_r(0) := Prescaler(7);
126
                        end case;
127
 
128
                        Tick0 := '0';
129
                        if SE = '0' then -- low-to-high
130
                                if CKI_r(1) = '1' and CKI_r(0) = '0' then
131
                                        Tick0 := '1';
132
                                end if;
133
                        else
134
                                if CKI_r(1) = '0' and CKI_r(0) = '1' then
135
                                        Tick0 := '1';
136
                                end if;
137
                        end if;
138
                        if CS = '0' then
139
                                Tick0 := '1';
140
                        end if;
141
                        CKI_r(1) := CKI_r(0);
142
                        CKI_r(0) := CKI;
143
 
144
                        Tick <= '0';
145
                        if PSA = '1' then
146
                                Tick <= Tick0;
147
                        elsif P_r(1) = '1' and P_r(0) = '0' then
148
                                Tick <= '1';
149
                        end if;
150
 
151
                        if Tick0 = '1' then
152
                                Prescaler := Prescaler + 1;
153
                        end if;
154
                end if;
155
        end process;
156
 
157
end;

powered by: WebSVN 2.1.0

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