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

Subversion Repositories jart

[/] [jart/] [branches/] [ver0branch/] [yu.vhd] - Blame information for rev 81

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

Line No. Rev Author Line
1 77 jguarin200
-- Author : Julian Andres Guarin Reyes.
2
-- Project : JART, Just Another Ray Tracer.
3
-- email : jguarin2002 at gmail.com, j.guarin at javeriana.edu.co
4
 
5
-- This code was entirely written by Julian Andres Guarin Reyes.
6
-- The following code is licensed under GNU Public License
7
-- http://www.gnu.org/licenses/gpl-3.0.txt.
8
 
9
 -- This file is part of JART (Just Another Ray Tracer).
10
 
11
    -- JART (Just Another Ray Tracer) is free software: you can redistribute it and/or modify
12
    -- it under the terms of the GNU General Public License as published by
13
    -- the Free Software Foundation, either version 3 of the License, or
14
    -- (at your option) any later version.
15
 
16
    -- JART (Just Another Ray Tracer) is distributed in the hope that it will be useful,
17
    -- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
    -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
    -- GNU General Public License for more details.
20
 
21
    -- You should have received a copy of the GNU General Public License
22
    -- along with JART (Just Another Ray Tracer).  If not, see <http://www.gnu.org/licenses/>.library ieee;
23
 
24
-- Unitary ray vector Y component integrator. In a memory block of 1x16384 bits, it is stored the FY' that represents the first derivate of FY, this function is the Y function along any horizontal line in the image.
25
-- The derivative is stored in this way: logic 0 means a 0 pendant and logic 1 means a -1 pendant. So a counter with enable / disable control it is everything we need, and of course a load input  to represent the initial value added to the integral.   
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.std_logic_signed.all;
30
use work.powerGrid.all;
31
 
32
 
33
entity yu is
34
        generic (
35
                TOP : integer := 1024;                                                          -- Define the max counting number.. the number must be expressed as 2 power, cause the range of counting is going to be defined as TOP-1 downto TOP/2.
36
                                                                                                                        -- However this is going to be by now, cause in the future the ray generation will GO on for higher resolution images , and perhaps it would be required a more extended range for the yu component.
37 80 jguarin200
                SCREENW : integer := 320                        --  resolution width is 320 
38 77 jguarin200
        );
39
        port (
40 80 jguarin200
                clk,rst,ena             : in std_logic;
41 77 jguarin200
                lineDone                : out std_logic;                                        -- Finished image row. once a hundred and sixty times....
42
                ypos                    : out integer range TOP/2 to TOP-1
43
--              ocntr                   : out integer range 0 to SCREENW/2 
44
        );
45
end entity;
46
 
47
architecture rtl of yu is
48
 
49
        -- 1x16384 bits, true dual port, ROM Memory declaration.
50
        -- This memory uses 2 cycles.. a memory fetch cycle and a data to q memory cycle.
51
        component yurom
52
        port
53
        (
54
                address_a       : in std_logic_vector (13 downto 0);
55
                address_b       : in std_logic_vector (13 downto 0);
56
                clock           : in std_logic ;
57
                q_a                     : out std_logic_vector (0 downto 0);
58
                q_b                     : out std_logic_vector (0 downto 0)
59
        );
60
 
61
        end component;
62
 
63
 
64
        constant linefeed : integer range 0 to (SCREENW/2) := (SCREENW/2)-4;
65
 
66
 
67
        -- Support signals.
68
        signal s1addf0  : std_logic_vector (13 downto 0);        -- The function 0 is the function of the y component derivative.
69
        signal s1addf1  : std_logic_vector (13 downto 0);        -- The function 1 is the function of the y component integration curve initial constant.
70
        signal sf0              : std_logic_vector (0 downto 0);  -- Derivative function
71
        signal sf1              : std_logic_vector (0 downto 0);  -- Derivative curve, initial constant derivative function.
72
 
73
        -- Some Initial Locks.
74
        signal sneglock : std_logic;
75
begin
76
 
77
        derivate : yurom
78
        port map (
79
                address_a       => s1addf0,
80
                address_b       => s1addf1,
81
                clock           => clk,
82
                q_a                     => sf0,
83
                q_b                     => sf1
84
        );
85
 
86
        integrate : process(clk,rst,ena)
87
 
88
                variable f0 : integer range TOP/2 to TOP-1;
89
                variable f1 : integer range TOP/2 to TOP-1;
90
                variable cc     : integer range 0 to SCREENW/2;
91
 
92
        begin
93
 
94
                if rst='0' then
95
 
96
                        f0:=TOP-10;
97
                        f1:=TOP-1;
98
                        cc:=linefeed;
99
 
100
                        -- Right from the start.
101
                        s1addf0 (13 downto 1) <= (others=>'0');          -- 0000.
102
                        s1addf0 (0) <= '1';
103
                        s1addf1 <= "11111010000000";    -- 3E7F.        
104
 
105
                        -- Locks
106
                        sneglock<='0';
107
 
108
 
109
                elsif rising_edge(clk) and ena='1' then --ADD!
110
 
111
 
112
                        -- Count f0 address
113
                        if sneglock='1' then
114
                                s1addf0 <= s1addf0+1;
115
                        end if;
116
 
117
                        -- Count f1 address (156)
118
                        if cc=linefeed then
119
                                s1addf1 <= s1addf1+1;
120
                        end if;
121
 
122
                        -- Unlock first stage f0 address (157)
123
                        if cc=linefeed+1 then
124
                                sneglock<='1';
125
                        end if;
126
 
127
                        -- Now, the integration function, cause we are at a new line..
128
                        if cc = 0 then
129
                                ypos <= f1;
130
                                f0 := f1;
131 80 jguarin200
 
132 77 jguarin200
                        else
133
                                ypos <= f0;
134
                                if sf0(0)='1' then
135
                                        f0 := f0 - 1;
136
                                end if;
137
                        end if;
138
 
139
                        -- Count when reach linefeed +3 (159) then turn cc into 0, else turn it into cc+1!
140
                        if cc=linefeed+3 then
141 80 jguarin200
                                lineDone <='1';
142 77 jguarin200
                                if sf1(0) = '1' then
143
                                        f1 := f1 - 1;
144
                                end if;
145
                                cc:=0;
146
                        else
147 80 jguarin200
                                lineDone <='0';
148 77 jguarin200
                                cc:=cc+1;
149
                        end if;
150
 
151
                end if;
152
 
153
        end process;
154
 
155
 
156
 
157
end rtl;
158
 
159
 
160
 
161
 
162
 
163
 

powered by: WebSVN 2.1.0

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