Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] VGA fix timing error

Status
Not open for further replies.

hdhzero

Newbie level 5
Newbie level 5
Joined
Mar 17, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,382
One more post about VGA. I am working with standard VGA (640x480@60Hz, 25 MHz), my board
has a clock of 50 MHz.

I've made a first version that worked, but then I tried to rewrite the code and now
I get out of sync message from my monitor.

Any tips how to fix it?

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity vga_control is
	port (
		clock_50 : in std_logic;
		sw 	   : in std_logic_vector(9 downto 0);
		vga_hs, vga_vs : out std_logic;
		ledg   : out std_logic_vector(9 downto 0);
		vga_r, vga_g, vga_b : out std_logic_vector(3 downto 0)
	);
end vga_control;

architecture behavior of vga_control is
	signal vcounter : integer;
	signal hcounter : integer;
	
	signal clock : std_logic;
	signal cl : unsigned(1 downto 0);
begin
	ledg  <= "1010101011"; -- ignore

        -- 50 MHz to 25 MHz	
	clock <= cl(1);
	process (clock_50, sw(9))
	begin
		if sw(9) = '1' then
			cl <= "00";
		elsif clock_50'event and clock_50 = '1' then
			cl <= cl + "01";
		end if;
	end process;
	
	vga_r <= "1111" when hcounter < 300 and vcounter < 300 else "0000";
	vga_g <= "1111" when hcounter < 300 and vcounter < 300 else "0000";
	vga_b <= "1111" when hcounter < 300 and vcounter < 300 else "0000";
	
	process (clock, sw(9))
	begin
		if sw(9) = '1' then
			hcounter <= 0;
			vcounter <= 0;
			vga_hs   <= '1';
			vga_vs   <= '1';
		elsif clock'event and clock = '1' then
			if hcounter = 799 then
				hcounter <= 0;
				
				if vcounter = 524 then
					vcounter <= 0;
				else
					vcounter <= vcounter + 1;
				end if;	
			else
				hcounter <= hcounter + 1;
			end if;
			
                        -- the info I have is: visible area: 640, front porch: 16, back porch: 48, retrace: 96
			if hcounter >= 656 and hcounter <= 751 then
				vga_hs <= '0';
			else
				vga_hs <= '1';
			end if;

                        -- the info I have is: visible area: 480, bottom: 10, top: 33, retrace: 2
			if vcounter >= 490 and vcounter <= 491 then
 				vga_vs <= '0';
			else
				vga_vs <= '1';
			end if;
		end if;
	end process;
end behavior;

- - - Updated - - -

Sorry, I've found the mistake. I was dividing the input clock by four, not by two.

Here the fix
Code:
process (clock_50, sw(9))
begin
    if sw(9) = '1' then 
        clock <= '0';
    elsif clock_50'event and clock_50 = '1' then 
        clock <= not clock;
    end if;
end process;
 

Generating the clock this way is not recommended. It can cause timing issues. its much better to create clock enables and use the system clock.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top