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

Subversion Repositories lq057q3dc02

[/] [lq057q3dc02/] [trunk/] [design/] [vsyncx_control.vhd] - Blame information for rev 47

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 jwdonal
------------------------------------------------------------------------------
2
-- Copyright (C) 2007 Jonathon W. Donaldson
3
--                    jwdonal a t opencores DOT org
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
--
19
------------------------------------------------------------------------------
20
--
21
-- $Id: vsyncx_control.vhd,v 1.1 2008-11-07 00:48:12 jwdonal Exp $
22
--
23
-- Description:
24
--  This file controls VSYNCx.  VSYNCx is dependent upon the number of HSYNCx
25
--  activations (i.e. the numbers of lines) that have passed.  The really cool
26
--  thing about the VSYNCx control state machine is that it is _EXACTLY_ the
27
--  same as the HSYNCx control state machine expect that instead of have the
28
--  counter process counting CLK_LCD cycles we have counting HSYNCx cycles!
29
--  It's really that simple!
30
--
31
--  VSYNCx signifies the start of a frame.  HSYNCx must pulse exactly 7 times
32
--  (i.e. 7 lines) after (minimum of 0 ns after - TVh) VSYNCx pulse occurs
33
--  before sending data to the LCD.  You can consider these 7 lines as blank
34
--  lines that "live" above the physical top of the screen.  After 7 HSYNCx
35
--  pulses have passed we can then start with line 1 and go to line 240 for a
36
--  total of 7 + 240 lines = 247 lines (or HSYNCx pulses) for every complete
37
--  image or "frame" drawn to the screen!
38
--
39
-- Note: Even though VSYNCx controls the start of a frame you cannot simply
40
-- disable HSYNCx cycling once the data has been shifted into the LCD.  This
41
-- is b/c there is a MAX cycle time spec in the datasheet of 450 clocks!
42
-- It is simplest to just leave HSYNCx running at all times no matter what.
43
--
44
-- Structure:
45
--   - xupv2p.ucf
46
--   - components.vhd
47
--   - lq057q3dc02_tb.vhd
48
--   - lq057q3dc02.vhd
49
--     - dcm_sys_to_lcd.xaw
50
--     - video_controller.vhd
51
--       - enab_control.vhd
52
--       - hsyncx_control.vhd
53
--       - vsyncx_control.vhd
54
--       - clk_lcd_cyc_cntr.vhd
55
--     - image_gen_bram.vhd
56
--       - image_gen_bram_red.xco
57
--       - image_gen_bram_green.xco
58
--       - image_gen_bram_blue.xco
59
--
60
------------------------------------------------------------------------------
61
--
62
-- Naming Conventions:
63
--   active low signals                                       "*x"
64
--   clock signal                                             "CLK_*"
65
--   reset signal                                             "RST"
66
--   generic/constant                                         "C_*"
67
--   user defined type                                        "TYPE_*"
68
--   state machine next state                                 "*_ns"
69
--   state machine current state                              "*_cs""
70
--   pipelined signals                                        "*_d#"
71
--   register delay signals                                   "*_p#"
72
--   signal                                                   "*_sig"
73
--   variable                                                 "*_var"
74
--   storage register                                         "*_reg"
75
--   clock enable signals                                     "*_ce"
76
--   internal version of output port used as connecting wire  "*_wire"
77
--   input/output port                                        "ALL_CAPS"
78
--   process                                                  "*_PROC"
79
--
80
------------------------------------------------------------------------------
81
 
82
--////////////////////--
83
-- LIBRARY INCLUSIONS --
84
--////////////////////--
85
LIBRARY IEEE;
86
USE IEEE.STD_LOGIC_1164.ALL;
87
USE IEEE.STD_LOGIC_ARITH.ALL;
88
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
89
 
90
--////////////////////--
91
-- ENTITY DECLARATION --
92
--////////////////////--
93
ENTITY vsyncx_control IS
94
 
95
  -----------------------------------------------------------------
96
  -- Generic Descriptions:
97
  --
98
  -- C_LINE_NUM_WIDTH   -- Must be at least 9 bits to hold maximum
99
  --                    -- timespec of 280 lines.
100
  -----------------------------------------------------------------
101
  generic (
102
 
103
    C_VSYNC_TV,
104
    C_VSYNC_TVP,
105
    C_LINE_NUM_WIDTH : POSITIVE
106
 
107
  );
108
 
109
  port (
110
 
111
    RSTx,
112
    CLK_LCD,
113
    HSYNCx : IN STD_LOGIC;
114
 
115
    LINE_NUM : OUT STD_LOGIC_VECTOR(C_LINE_NUM_WIDTH-1 downto 0);
116
 
117
    VSYNCx : OUT STD_LOGIC
118
 
119
  );
120
 
121
END ENTITY vsyncx_control;
122
 
123
--////////////////////////--
124
-- ARCHITECTURE OF ENTITY --
125
--////////////////////////--
126
ARCHITECTURE vsyncx_control_arch OF vsyncx_control IS
127
 
128
  --Enables/Disables the line counter process
129
  signal line_cnt_en_sig : std_logic;
130
 
131
  --Stores current line number.
132
  --This register is attached to the LINE_NUM output.
133
  signal line_num_reg : std_logic_vector(C_LINE_NUM_WIDTH-1 downto 0) := (others => '0');
134
 
135
  ---------------------------------------------------------------
136
  -- States for VSYNCx_Line_Cntr_*_PROC
137
  ---------------------------------------------------------------
138
  --FRAME_START => Start of a new frame
139
  --ADD => Add one (1) to the line count
140
  --ADD_WAIT => Wait for HSYNCx pulse to pass
141
  --READY => Get ready to add one (1) for the next line
142
  type TYPE_Line_Cntr_Sts is ( FRAME_START, ADD, ADD_WAIT, READY );
143
  signal Line_Cntr_cs : TYPE_Line_Cntr_Sts;
144
  signal Line_Cntr_ns : TYPE_Line_Cntr_Sts;
145
 
146
begin
147
 
148
  --///////////////////////--
149
  -- CONCURRENT STATEMENTS --
150
  --///////////////////////--
151
  LINE_NUM <= line_num_reg;
152
 
153
 
154
  --///////////--
155
  -- PROCESSES --
156
  --///////////--
157
 
158
  ------------------------------------------------------------------
159
  --  Process Description:
160
  --    This is finite state machine process 1 of 3 for the VSYNCx
161
  --    signal controller.  This process only controls the reset of
162
  --    the state and the "current state to next state" assignment.
163
  --  
164
  --  Inputs:
165
  --    RSTx
166
  --    CLK_LCD
167
  --  
168
  --  Outputs:
169
  --    Line_Cntr_cs
170
  --
171
  --  Notes:
172
  --    N/A
173
  ------------------------------------------------------------------
174
  VSYNCx_Line_Cntr_1_PROC : process( RSTx, CLK_LCD )
175
  begin
176
 
177
    if( RSTx = '0' ) then
178
 
179
      Line_Cntr_cs <= READY;
180
 
181
    elsif( CLK_LCD'event and CLK_LCD = '1' ) then
182
 
183
      Line_Cntr_cs <= Line_Cntr_ns;
184
 
185
    end if;
186
 
187
  end process VSYNCx_Line_Cntr_1_PROC;
188
 
189
 
190
  ------------------------------------------------------------------
191
  --  Process Description:
192
  --    This is finite state machine process 2 of 3 for the VSYNCx
193
  --    signal controller.  This process controls all of the state
194
  --    changes.
195
  --  
196
  --  Inputs:
197
  --    Line_Cntr_cs
198
  --    HSYNCx
199
  --    line_num_reg
200
  --  
201
  --  Outputs:
202
  --    Line_Cntr_ns
203
  --
204
  --  Notes:
205
  --    We only want to start counting lines at the first HSYNCx pulse
206
  --    we see _after_ VSYNCx has been activated.  This is because
207
  --    VSYNCx must occur before HSYNCx can be counted (NOTE: there is
208
  --    no sense in couting lines unless we know that a new frame has
209
  --    started - this is _most_ important for the ENAB_Cntrl process!)
210
  ------------------------------------------------------------------
211
  VSYNCx_Line_Cntr_2_PROC : process( Line_Cntr_cs, HSYNCx, line_num_reg )
212
  begin
213
 
214
    case Line_Cntr_cs is
215
 
216
      when FRAME_START =>  --reset the counter because we have started a new frame!
217
 
218
        if( HSYNCx = '0' ) then -- a new frame is starting (controlled by VSYNCx_control state machine) and here is our first line!
219
 
220
          Line_Cntr_ns <= ADD_WAIT; -- do not add +1 lines until HSYNCx goes high!  The rising edge is what counts as a line, not the falling edge!
221
 
222
        else
223
 
224
          Line_Cntr_ns <= FRAME_START; -- keep waiting for first line to occur after start of new frame
225
 
226
        end if;
227
 
228
      when ADD_WAIT =>
229
 
230
        if( HSYNCx = '1' ) then
231
 
232
          Line_Cntr_ns <= ADD;  -- line_num_reg + 1 !
233
 
234
        else
235
 
236
          Line_Cntr_ns <= ADD_WAIT; -- stay here until HSYNCx has been released b/c we only want to count the rising edge of HSYNCx as a line!
237
 
238
        end if;
239
 
240
      when ADD =>
241
 
242
        Line_Cntr_ns <= READY;  -- get ready to count another line if necessary
243
 
244
      when READY =>
245
 
246
        if( line_num_reg = C_VSYNC_TV - 1 ) then -- 0 to 254 = 255 lines (first make sure we haven't reach the end of the VSYNC cycle - which is just a little bit longer than the actual number of lines on the screen - TV)
247
 
248
          Line_Cntr_ns <= FRAME_START; -- if we've reached the max VSYNC cycle time (i.e. TV) then start over!
249
 
250
        elsif( HSYNCx = '0' ) then
251
 
252
          Line_Cntr_ns <= ADD_WAIT; -- a new line has started!  line_num_reg + 1!!
253
 
254
        else
255
 
256
          Line_Cntr_ns <= READY; -- stay here until HSYNCx pulse occurs
257
 
258
        end if;
259
 
260
      when others => --UH OH!  How did we get here???
261
 
262
        Line_Cntr_ns <= FRAME_START;
263
 
264
    end case;
265
 
266
  end process VSYNCx_Line_Cntr_2_PROC;
267
 
268
 
269
  ------------------------------------------------------------------
270
  --  Process Description:
271
  --    This is finite state machine process 3 of 3 for the VSYNCx
272
  --    signal controller.  This process only controls the change of
273
  --    of output values based on the current state.
274
  --  
275
  --  Inputs:
276
  --    Line_Cntr_cs
277
  --  
278
  --  Outputs:
279
  --    line_cnt_en_sig
280
  --
281
  --  Notes:
282
  --    N/A
283
  ------------------------------------------------------------------
284
  VSYNCx_Line_Cntr_3_PROC : process( Line_Cntr_cs )
285
  begin
286
 
287
    case Line_Cntr_cs is
288
 
289
      when FRAME_START => --reset line_num_reg at start of new frame
290
 
291
        line_cnt_en_sig <= '0';
292
 
293
      when READY =>
294
 
295
        line_cnt_en_sig <= '0';
296
 
297
      when ADD_WAIT =>
298
 
299
        line_cnt_en_sig <= '0';
300
 
301
      when ADD => --we will only ever be in this state for one CLK_LCD cycle.  This is IMPORTANT! b/c we only want to count one CLK_LCD cycle worth of the HSYNCx active pulse no matter how long the HSYNCx pulse is!
302
 
303
        line_cnt_en_sig <= '1';
304
 
305
      when others => --UH OH!  How did we get here???
306
 
307
        line_cnt_en_sig <= '0';
308
 
309
    end case;
310
 
311
  end process VSYNCx_Line_Cntr_3_PROC;
312
 
313
 
314
  ------------------------------------------------------------------
315
  --  Process Description:
316
  --    This process starts, stops, and resets the line counter
317
  --    based on the line count enable signal and the current state
318
  --    of the line counter state machine.
319
  --  
320
  --  Inputs:
321
  --    RSTx
322
  --    CLK_LCD
323
  --  
324
  --  Outputs:
325
  --    line_num_reg
326
  --
327
  --  Notes:
328
  --    N/A
329
  ------------------------------------------------------------------
330
  Line_cntr_PROC : process( RSTx, CLK_LCD )
331
  begin
332
  if( RSTx = '0' ) then
333
 
334
    line_num_reg <= (others => '0');
335
 
336
  elsif( CLK_LCD'event and CLK_LCD = '1' ) then
337
 
338
    if( line_cnt_en_sig = '1' ) then
339
 
340
      line_num_reg <= line_num_reg + 1;
341
 
342
    elsif( Line_Cntr_cs = FRAME_START ) then
343
 
344
      line_num_reg <= (others => '0');
345
 
346
    else
347
 
348
      line_num_reg <= line_num_reg;
349
 
350
    end if;
351
 
352
  end if;
353
 
354
  end process Line_cntr_PROC;
355
 
356
 
357
  ------------------------------------------------------------------
358
  --  Process Description:
359
  --    This process activates/deactivates the VSYNCx signal depending
360
  --    on the current line number relative to the VSYNC pulse width
361
  --    paramter.
362
  --  
363
  --  Inputs:
364
  --    RSTx
365
  --    CLK_LCD
366
  --  
367
  --  Outputs:
368
  --    VSYNCx
369
  --
370
  --  Notes:
371
  --    N/A
372
  ------------------------------------------------------------------
373
  VSYNCx_cntrl_PROC : process( RSTx, CLK_LCD )
374
  begin
375
 
376
    if( RSTx = '0' ) then
377
 
378
      VSYNCx <= '1';  --INACTIVE
379
 
380
    elsif( CLK_LCD'event and CLK_LCD = '1' ) then
381
 
382
      if( line_num_reg < C_VSYNC_TVP ) then
383
 
384
        VSYNCx <= '0'; --ACTIVE
385
 
386
      else
387
 
388
        VSYNCx <= '1'; --INACTIVE
389
 
390
      end if;
391
 
392
    end if;
393
 
394
  end process VSYNCx_cntrl_PROC;
395
 
396
 
397
END ARCHITECTURE vsyncx_control_arch;

powered by: WebSVN 2.1.0

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