1 | ENTITY clockmodule IS
|
2 | PORT(
|
3 | reset : in std_logic; -- reset
|
4 | clk50_in : IN std_logic;
|
5 |
|
6 | VGA_R : OUT std_logic_vector (9 downto 0);
|
7 | VGA_G : OUT std_logic_vector (9 downto 0);
|
8 | VGA_B : OUT std_logic_vector (9 downto 0);
|
9 | VGA_HS_out : OUT std_logic;
|
10 | VGA_VS_out : OUT std_logic;
|
11 |
|
12 | VGA_CLK : OUT std_logic;
|
13 | VGA_BLANK : OUT std_logic;
|
14 | VGA_SYNC : OUT std_logic
|
15 | );
|
16 | END clockmodule;
|
17 |
|
18 | ARCHITECTURE behaviour OF clockmodule IS
|
19 |
|
20 | -- Video parameters
|
21 | constant HTOTAL : integer := 800;
|
22 | constant HSYNC : integer := 96;
|
23 | constant HBACK_PORCH : integer := 48;
|
24 | constant HACTIVE : integer := 640;
|
25 | constant HFRONT_PORCH : integer := 16;
|
26 | constant VTOTAL : integer := 525;
|
27 | constant VSYNC : integer := 2;
|
28 | constant VBACK_PORCH : integer := 33;
|
29 | constant VACTIVE : integer := 480;
|
30 | constant VFRONT_PORCH : integer := 10;
|
31 | constant RECTANGLE_HSTART : integer := 100;
|
32 | constant RECTANGLE_HEND : integer := 540;
|
33 | constant RECTANGLE_VSTART : integer := 100;
|
34 | constant RECTANGLE_VEND : integer := 380;
|
35 |
|
36 | signal clk25 : std_logic; -- 25MHz clock -> should be 25.125 MHz
|
37 |
|
38 | -- Horizontal position (0-800)
|
39 | signal horizontal_counter : std_logic_vector (9 downto 0);
|
40 |
|
41 | -- Vertical position (0-524)
|
42 | signal vertical_counter : std_logic_vector (9 downto 0);
|
43 |
|
44 |
|
45 | signal EndOfLine, EndOfField : std_logic;
|
46 | signal vga_hblank, vga_hsync, vga_vblank, vga_vsync : std_logic; -- Sync. signals
|
47 | signal rectangle_h, rectangle_v, rectangle : std_logic; -- rectangle area
|
48 | begin
|
49 |
|
50 | -- generate a 25 MHz clock
|
51 | process (clk50_in)
|
52 | begin
|
53 | if clk50_in'event and clk50_in = '1' then
|
54 | if (clk25 = '0') then
|
55 | clk25 <= '1';
|
56 | else
|
57 | clk25 <= '0';
|
58 | end if;
|
59 | end if;
|
60 | end process;
|
61 |
|
62 |
|
63 | HCounter : process (clk25, reset)
|
64 | begin
|
65 | if reset = '1' then
|
66 | horizontal_counter <= (others => '0');
|
67 | elsif clk25'event and clk25 = '1' then
|
68 | if EndOfLine = '1' then
|
69 | horizontal_counter <= (others => '0');
|
70 | else
|
71 | horizontal_counter <= horizontal_counter + 1;
|
72 | end if;
|
73 | end if;
|
74 | end process HCounter;
|
75 |
|
76 | EndOfLine <= '1' when horizontal_counter = HTOTAL - 1 else '0';
|
77 |
|
78 | VCounter: process (clk25, reset)
|
79 | begin
|
80 | if reset = '1' then
|
81 | vertical_counter <= (others => '0');
|
82 | elsif clk25'event and clk25 = '1' then
|
83 | if EndOfLine = '1' then
|
84 | if EndOfField = '1' then
|
85 | vertical_counter <= (others => '0');
|
86 | else
|
87 | vertical_counter <= vertical_counter + 1;
|
88 | end if;
|
89 | end if;
|
90 | end if;
|
91 | end process VCounter;
|
92 |
|
93 |
|
94 |
|
95 | HSyncGen : process (clk25, reset)
|
96 | begin
|
97 | if reset = '1' then
|
98 | vga_hsync <= '1';
|
99 | elsif clk25'event and clk25 = '1' then
|
100 | if EndOfLine = '1' then
|
101 | vga_hsync <= '1';
|
102 | elsif horizontal_counter = HSYNC - 1 then
|
103 | vga_hsync <= '0';
|
104 | end if;
|
105 | end if;
|
106 | end process HSyncGen;
|
107 |
|
108 |
|
109 | HBlankGen : process (clk25, reset)
|
110 | begin
|
111 | if reset = '1' then
|
112 | vga_hblank <= '1';
|
113 | elsif clk25'event and clk25 = '1' then
|
114 | if horizontal_counter = HSYNC + HBACK_PORCH then
|
115 | vga_hblank <= '0';
|
116 | elsif horizontal_counter = HSYNC + HBACK_PORCH + HACTIVE then
|
117 | vga_hblank <= '1';
|
118 | end if;
|
119 | end if;
|
120 | end process HBlankGen;
|
121 |
|
122 |
|
123 |
|
124 | -- Vertical Signals!
|
125 | VSyncGen : process (clk25, reset)
|
126 | begin
|
127 | if reset = '1' then
|
128 | vga_vsync <= '1';
|
129 | elsif clk25'event and clk25 = '1' then
|
130 | if EndOfLine ='1' then
|
131 | if EndOfField = '1' then
|
132 | vga_vsync <= '1';
|
133 | elsif vertical_counter = VSYNC - 1 then
|
134 | vga_vsync <= '0';
|
135 | end if;
|
136 | end if;
|
137 | end if;
|
138 | end process VSyncGen;
|
139 |
|
140 |
|
141 | VBlankGen : process (clk25, reset)
|
142 | begin
|
143 | if reset = '1' then
|
144 | vga_vblank <= '1';
|
145 | elsif clk25'event and clk25 = '1' then
|
146 | if EndOfLine = '1' then
|
147 | if vertical_counter = VSYNC + VBACK_PORCH - 1 then
|
148 | vga_vblank <= '0';
|
149 | elsif vertical_counter = VSYNC + VBACK_PORCH + VACTIVE - 1 then
|
150 | vga_vblank <= '1';
|
151 | end if;
|
152 | end if;
|
153 | end if;
|
154 | end process VBlankGen;
|
155 |
|
156 |
|
157 | RectangleHGen : process (clk25, reset)
|
158 | begin
|
159 | if reset = '1' then
|
160 | rectangle_h <= '1';
|
161 | elsif clk25'event and clk25 = '1' then
|
162 | if horizontal_counter = HSYNC + HBACK_PORCH + RECTANGLE_HSTART then
|
163 | rectangle_h <= '1';
|
164 | elsif horizontal_counter = HSYNC + HBACK_PORCH + RECTANGLE_HEND then
|
165 | rectangle_h <= '0';
|
166 | end if;
|
167 | end if;
|
168 | end process RectangleHGen;
|
169 |
|
170 |
|
171 | RectangleVGen : process (clk25, reset)
|
172 | begin
|
173 | if reset = '1' then
|
174 | rectangle_v <= '0';
|
175 | elsif clk25'event and clk25 = '1' then
|
176 | if EndOfLine = '1' then
|
177 | if vertical_counter = VSYNC + VBACK_PORCH - 1 + RECTANGLE_VSTART then
|
178 | rectangle_v <= '1';
|
179 | elsif vertical_counter = VSYNC + VBACK_PORCH - 1 + RECTANGLE_VEND then
|
180 | rectangle_v <= '0';
|
181 | end if;
|
182 | end if;
|
183 | end if;
|
184 | end process RectangleVGen;
|
185 |
|
186 |
|
187 | rectangle <= rectangle_h and rectangle_v;
|
188 |
|
189 |
|
190 |
|
191 | VideoOut: process (clk25, reset)
|
192 | begin
|
193 | if reset = '1' then
|
194 | VGA_R <= "0000000000";
|
195 | VGA_G <= "0000000000";
|
196 | VGA_B <= "0000000000";
|
197 | elsif clk25'event and clk25 = '1' then
|
198 | if rectangle = '1' then
|
199 | VGA_R <= "1111111111";
|
200 | VGA_G <= "1111111111";
|
201 | VGA_B <= "1111111111";
|
202 | elsif vga_hblank = '0' and vga_vblank ='0' then
|
203 | VGA_R <= "0000000000";
|
204 | VGA_G <= "0000000000";
|
205 | VGA_B <= "1111111111";
|
206 | else
|
207 | VGA_R <= "0000000000";
|
208 | VGA_G <= "0000000000";
|
209 | VGA_B <= "0000000000";
|
210 | end if;
|
211 | end if;
|
212 | end process VideoOut;
|
213 |
|
214 |
|
215 | VGA_CLK <= clk25;
|
216 | VGA_HS_out <= not vga_hsync;
|
217 | VGA_VS_out <= not vga_vsync;
|
218 | VGA_SYNC <= '0';
|
219 | VGA_BLANK <= not (vga_hsync or vga_vsync);
|
220 |
|
221 |
|
222 | end behaviour;
|