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

Subversion Repositories raytrac

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

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
                subwidth        : integer := 0;
36
                width           : integer := 5
37
        );
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 151 jguarin200
 
51 145 jguarin200
        signal scount_d, scount_q, sgo : std_logic_vector(width-1 downto 0);
52
        signal seob_flag : std_logic;
53 142 jguarin200
 
54
begin
55 145 jguarin200
 
56
        --!Compara los bits superiores solamente, si subwidth es 4 y width es 9 comparara los 9-4=5 bits superiores.
57
        steadyEqualFlag:
58
        if EQUALFLAG/="YES" generate
59
                eq_flag <= '0';
60
        end generate steadyEqualFlag;
61
        equalFlagsProcess:
62
        if EQUALFLAG="YES" generate
63
                process (scount_d(width-1 downto subwidth),cmpBlockValue,clk,rst)
64
                begin
65
                        if rst=rstMasterValue then
66
                                eq_flag <= '0';
67
                        elsif clk'event and clk='1' then
68
                                if scount_d(width-1 downto subwidth)=cmpBlockValue then
69
                                        eq_flag <= '1';
70
                                else
71
                                        eq_flag <= '0';
72
                                end if;
73
                        end if;
74
                end process;
75
        end generate equalFlagsProcess;
76
 
77
        --Backwards or Forwards.
78
        forwardGenerator:
79
        if BACKWARDS="NO" generate
80
                sgo(width-1 downto 1) <= (others => '0');
81
                sgo(0) <= go;
82
        end generate forwardGenerator;
83
 
84
        backwardGenerator:
85
        if BACKWARDS="YES" generate
86
                sgo(width-1 downto 0) <= (others => go);
87
        end generate backwardGenerator;
88
 
89
 
90
        --! Si en los par&aacute;metros no se encuentra especificado que detecte el zero entonces la salida zero_flag estar&aacute; en cero siempre.
91
        steadyZeroFlag:
92
        if ZEROFLAG/="YES" generate
93
                zero_flag <= '0';
94
        end generate steadyZeroFlag;
95
 
96
        --! Si el par&aacute;metro para la bandera de cero se especifica, entonces se instancia un proceso que depende del valor del conteo.    
97
        zeroFlagProcess:
98
        if ZEROFLAG="YES" generate
99
                --! Proceso para calcular la bandera de cero, en el conteo.
100
                process (scount_d,clk,rst)
101
                begin
102
                        if rst=rstMasterValue then
103
                                zero_flag <= '0';
104
                        elsif clk'event and clk='1' then
105
                                zero_flag <= '1';
106
                                for i in width-1 downto 0 loop
107
                                        if scount_d(i) = '1' then
108
                                                zero_flag <= '0';
109
                                                exit;--the loop;
110
                                        end if;
111
                                end loop;
112
                        end if;
113
                end process;
114
        end generate zeroFlagProcess;
115
 
116
 
117
        --! 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.
118
        steadyEobFlag:
119
        if EOBFLAG/="YES" generate
120
                eob_flag <= '0';
121
        end generate steadyEobFlag;
122
        eobFlagProcess:
123
        if EOBFLAG="YES" generate
124
                process (scount_d(subwidth-1 downto 0),clk,rst)
125
                begin
126
                        if rst=rstMasterValue then
127
                                eob_flag <= '0';
128
                        elsif clk'event and clk='1' then
129
                                eob_flag <= '1';
130
                                for i in subwidth-1 downto 0 loop
131
                                        if scount_d(i) /= '1' then
132
                                                eob_flag <= '0';
133
                                                exit;--the loop
134
                                        end if;
135
                                end loop;
136
                        end if;
137
                end process;
138
        end generate eobFlagProcess;
139
 
140
        --! Salida combinatoria del contador.
141 142 jguarin200
        count <= scount_d;
142 145 jguarin200
 
143
        --! Proceso de control del conteo.
144 142 jguarin200
        add_proc:
145 145 jguarin200
        process (scount_q,sgo,set,setValue)
146 142 jguarin200
        begin
147 145 jguarin200
                case set is
148
                        --! 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. 
149
                        when '1'  => scount_d(subwidth-1 downto 0) <= (others => '0');scount_d(width-1 downto subwidth) <= setValue;
150
                        when others => scount_d <= scount_q+sgo;
151 142 jguarin200
                end case;
152
        end process;
153
 
154
        count_proc:
155
        process (clk,rst)
156
        begin
157
                if rst=rstMasterValue then
158
                        scount_q <= (others => '0');
159
                elsif clk='1' and clk'event then
160
                        scount_q <= scount_d;
161
                end if;
162
        end process;
163
end architecture;
164
 
165
 

powered by: WebSVN 2.1.0

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