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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [customCounter.vhd] - Blame information for rev 245

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 142 jguarin200
--! @file sm.vhd
2
--! @brief Maquina de Estados. Controla la operación interna y genera los mecanismos de sincronización con el exterior (interrupciones). 
3
--! @author Julián Andrés Guarín Reyes
4
--------------------------------------------------------------
5
-- RAYTRAC
6
-- Author Julian Andres Guarin
7
-- sm.vhd
8
-- This file is part of raytrac.
9
-- 
10
--     raytrac is free software: you can redistribute it and/or modify
11
--     it under the terms of the GNU General Public License as published by
12
--     the Free Software Foundation, either version 3 of the License, or
13
--     (at your option) any later version.
14
-- 
15
--     raytrac is distributed in the hope that it will be useful,
16
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
17
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
--     GNU General Public License for more details.
19
-- 
20
--     You should have received a copy of the GNU General Public License
21
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26
use ieee.std_logic_unsigned.all;
27 151 jguarin200
use work.arithpack.all;
28 142 jguarin200
 
29
entity customCounter is
30
        generic (
31 145 jguarin200
                EOBFLAG         : string := "NO";
32
                ZEROFLAG        : string := "YES";
33
                BACKWARDS       : string := "YES";
34
                EQUALFLAG       : string := "NO";
35 152 jguarin200
                width           : integer := 5;
36
                subwidth        : integer := 0
37 145 jguarin200
        );
38 142 jguarin200
        port (
39
                clk,rst,go,set : in std_logic;
40 145 jguarin200
                setValue, cmpBlockValue : in std_logic_vector (width-1 downto subwidth); --! Los 5 bits de arriba.
41
                zero_flag,eob_flag, eq_flag : out std_logic;
42 142 jguarin200
                count : out std_logic_vector (width - 1 downto 0)
43
        );
44
end entity;
45
 
46
 
47
 
48
architecture customCounter_arch of customCounter is
49
 
50 152 jguarin200
        --!TBXSTART:COUNTING_REGISTERS
51 145 jguarin200
        signal scount_d, scount_q, sgo : std_logic_vector(width-1 downto 0);
52 152 jguarin200
        --!TBXEND
53
        --!TBXSTART:END_OF_BLOCK_FLAG
54 145 jguarin200
        signal seob_flag : std_logic;
55 152 jguarin200
        --!TBXEND
56
 
57 142 jguarin200
 
58
begin
59 145 jguarin200
 
60
        --!Compara los bits superiores solamente, si subwidth es 4 y width es 9 comparara los 9-4=5 bits superiores.
61
        steadyEqualFlag:
62
        if EQUALFLAG/="YES" generate
63
                eq_flag <= '0';
64
        end generate steadyEqualFlag;
65
        equalFlagsProcess:
66
        if EQUALFLAG="YES" generate
67
                process (scount_d(width-1 downto subwidth),cmpBlockValue,clk,rst)
68
                begin
69
                        if rst=rstMasterValue then
70
                                eq_flag <= '0';
71
                        elsif clk'event and clk='1' then
72
                                if scount_d(width-1 downto subwidth)=cmpBlockValue then
73
                                        eq_flag <= '1';
74
                                else
75
                                        eq_flag <= '0';
76
                                end if;
77
                        end if;
78
                end process;
79
        end generate equalFlagsProcess;
80
 
81
        --Backwards or Forwards.
82
        forwardGenerator:
83
        if BACKWARDS="NO" generate
84
                sgo(width-1 downto 1) <= (others => '0');
85
                sgo(0) <= go;
86
        end generate forwardGenerator;
87
 
88
        backwardGenerator:
89
        if BACKWARDS="YES" generate
90
                sgo(width-1 downto 0) <= (others => go);
91
        end generate backwardGenerator;
92
 
93
 
94
        --! Si en los par&aacute;metros no se encuentra especificado que detecte el zero entonces la salida zero_flag estar&aacute; en cero siempre.
95
        steadyZeroFlag:
96
        if ZEROFLAG/="YES" generate
97
                zero_flag <= '0';
98
        end generate steadyZeroFlag;
99
 
100
        --! Si el par&aacute;metro para la bandera de cero se especifica, entonces se instancia un proceso que depende del valor del conteo.    
101
        zeroFlagProcess:
102
        if ZEROFLAG="YES" generate
103
                --! Proceso para calcular la bandera de cero, en el conteo.
104
                process (scount_d,clk,rst)
105
                begin
106
                        if rst=rstMasterValue then
107
                                zero_flag <= '0';
108
                        elsif clk'event and clk='1' then
109
                                zero_flag <= '1';
110
                                for i in width-1 downto 0 loop
111
                                        if scount_d(i) = '1' then
112
                                                zero_flag <= '0';
113
                                                exit;--the loop;
114
                                        end if;
115
                                end loop;
116
                        end if;
117
                end process;
118
        end generate zeroFlagProcess;
119
 
120
 
121
        --! Proceso para controlar la salida de la bandera de fin de bloque. Se colocar&aacute; en uno l&oacute;gico cuando el conteo vaya en multiplo de 32 menos 1.
122
        steadyEobFlag:
123
        if EOBFLAG/="YES" generate
124
                eob_flag <= '0';
125
        end generate steadyEobFlag;
126
        eobFlagProcess:
127
        if EOBFLAG="YES" generate
128
                process (scount_d(subwidth-1 downto 0),clk,rst)
129
                begin
130
                        if rst=rstMasterValue then
131
                                eob_flag <= '0';
132
                        elsif clk'event and clk='1' then
133
                                eob_flag <= '1';
134
                                for i in subwidth-1 downto 0 loop
135
                                        if scount_d(i) /= '1' then
136
                                                eob_flag <= '0';
137
                                                exit;--the loop
138
                                        end if;
139
                                end loop;
140
                        end if;
141
                end process;
142
        end generate eobFlagProcess;
143
 
144
        --! Salida combinatoria del contador.
145 142 jguarin200
        count <= scount_d;
146 145 jguarin200
 
147
        --! Proceso de control del conteo.
148 142 jguarin200
        add_proc:
149 145 jguarin200
        process (scount_q,sgo,set,setValue)
150 142 jguarin200
        begin
151 145 jguarin200
                case set is
152
                        --! Si subwidth es cero, p.ej. cuando se quiere hacer un contador simple y no detectar el final de bloques de 4 bits de ancho, el compilador ignora el statement con la expresi&oacute;n por fuera del rango. 
153 153 jguarin200
                        when '1'  =>
154
                                scount_d(subwidth-1 downto 0) <= (others => '0');
155
                                scount_d(width-1 downto subwidth) <= setValue;
156
                        when others =>
157
                                scount_d <= scount_q+sgo;
158 142 jguarin200
                end case;
159
        end process;
160
 
161
        count_proc:
162
        process (clk,rst)
163
        begin
164
                if rst=rstMasterValue then
165
                        scount_q <= (others => '0');
166
                elsif clk='1' and clk'event then
167
                        scount_q <= scount_d;
168
                end if;
169
        end process;
170
end architecture;
171
 
172
 

powered by: WebSVN 2.1.0

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