Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

VGA Timing trouble

Status
Not open for further replies.

craig_jb

New Member
I am trying to set up a PIC micro to output a solid color to a VGA monitor. I've got the RGB signals hooked to PORTA:0-3 and the HSYNC to PORTB:7 and the VSYNC to PORTB:6

All I get on the screen in blackness. Any help is appreciated.

This is the diagram I tried to base my timing on:
http://www.vga-avr.narod.ru/vga_timing/vga_timing.gif

Here is my code (Running at 40Mhz):

Code:
#include "p18f4685.h"
#include "delays.h"

int i;

#pragma code TheCode=0x2000

void VSync()
{

	Delay1KTCYx(3);
	Delay100TCYx(5);

	PORTBbits.RB6 = 0;

	Delay100TCYx(6);

	PORTBbits.RB6 = 1;

	Delay10KTCYx(1);
	Delay100TCYx(2);

}

void main()
{

	ADCON1bits.PCFG3 = 1;
	ADCON1bits.PCFG2 = 1;
	ADCON1bits.PCFG1 = 1;
	ADCON1bits.PCFG0 = 1;

	TRISA = 0x00;
	TRISB = 0x00;

	PORTA = 0x00;
	PORTB = 0x00;

	PORTA = 0xFF;
	PORTB = 0xFF;

	while(1)
	{

		VSync();

		for(i = 0; i < 480; i++)
		{

		
			Delay100TCYx(2);
			Delay10TCYx(4);
			Nop();
			Nop();	

			_asm

				call	HSync, 0

			_endasm
	
		}

	}

_asm

HSync:

	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	bcf	PORTB, 7, ACCESS
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	bsf	PORTB, 7, ACCESS
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

	return	0

_endasm

}
 
Last edited:
I haven't examined your timing code that closely, but what levels are you inputting to the VGA monitor on the RGB pins? They should be less than 700mv p-p..... Maybe also post a schematic of how you are interfacing the PIC to the 15pin D-SUB VGA connector.
 
I decided to go the asm route to avoid any timing troubles. I still do not get a signal on the vga monitor. Here is my connection scheme:

VGA Connector:

Pin1 - Red (PORTA.0)
Pin2 - Green (PORTA.1)
Pin3 - Blue (PORTA.2) All below .7 volts

Pin10 - Ground

Pin13 - HSync (PORTB.7)
Pin14 - VSync (PORTB.6)

Do I have to connect the other ground pins? I am using the same power supply for all signals.

and here is my revised code (once again at 40Mhz or 10 MIPs on PIC18F4685):

Code:
list p=18f4685

#include <p18f4685.inc>

; PIC18F4685 @ 40Mhz	10 MIPS
; 1uS = 10 instructions

; Connected to VGA as follows
; PORTA.0 = RED
; PORTA.1 = GREEN
; PORTA.2 = BLUE
; PORTB.7 = HSync
; PORTB.6 = VSync

LineCount1 equ 0x60
LineCount2 equ 0x61
VertCount1 equ 0x62
VertCount2 equ 0x63
VertCount3 equ 0x64

Delay10TCY: macro

	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

endm

Delay100TCY: macro

	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY	

endm

org 0

goto Start

org 0x30

Start:

	; set the AD pins to all digital
	bcf	ADCON1, PCFG3
	bsf	ADCON1, PCFG2
	bsf	ADCON1, PCFG1
	bsf	ADCON1, PCFG0

	; set PORTA and PORTB to output
	clrf	TRISA
	clrf	TRISB

	; clear PORTA and PORTB
	clrf	PORTA
	clrf	PORTB

	; set the color to solid red
	bsf	PORTA, 0

	; set the VSync and HSync bits
	bsf	PORTB, 7
	bsf	PORTB, 6

	; set the line counters
	setf	LineCount1

	movlw	0xE0
	movwf	LineCount2

	movlw	0x0D
	movwf	VertCount1

	movlw	0x02
	movwf	VertCount2
	
	movlw	0x21
	movwf	VertCount3

VideoLoop:

LineCounter1Loop:

	; 25.17uS display line approx 251 cycles
	Delay100TCY
	Delay100TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop

	; hsync front porch
	; .94uS approx 9 cycles
	; resert VertCount3
	movlw	0x21
	movwf	VertCount3
	nop
	nop
	nop
	nop
	nop
	nop
	nop

	; hysnc pulse
	; 3.77uS approx 38 cycles
	bcf	PORTB, 7
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	bsf	PORTB, 7
	
	; hsync back porch
	; 1.89uS approx 19 cycles
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	LineCount1
	goto	LineCounter1Loop
	nop

LineCounter2Loop:

	; 25.17uS display line approx 251 cycles
	Delay100TCY
	Delay100TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop

	; hsync front porch
	; .94uS approx 9 cycles
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

	; hysnc pulse
	; 3.77uS approx 38 cycles
	bcf	PORTB, 7
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	bsf	PORTB, 7
	
	; hsync back porch
	; 1.89uS approx 19 cycles
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	LineCount2
	goto	LineCounter2Loop
	nop

; blanking time before vert sync
VertCounter1Loop:

	; 25.17uS display line approx 251 cycles
	Delay100TCY
	Delay100TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop

	; hsync front porch
	; .94uS approx 9 cycles
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

	; hysnc pulse
	; 3.77uS approx 38 cycles
	bcf	PORTB, 7
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	bsf	PORTB, 7
	
	; hsync back porch
	; 1.89uS approx 19 cycles
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	VertCount1
	goto	VertCounter1Loop
	bcf PORTB, 6 ; vert sync signal goes low

; 2 lines of vert sync
VertSyncLoop:

	; 25.17uS display line approx 251 cycles
	Delay100TCY
	Delay100TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop

	; hsync front porch
	; .94uS approx 9 cycles
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

	; hysnc pulse
	; 3.77uS approx 38 cycles
	bcf	PORTB, 7
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	bsf	PORTB, 7
	
	; hsync back porch
	; 1.89uS approx 19 cycles
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	VertCount2
	goto	VertSyncLoop
	bsf	PORTB, 6 ; vert sync goes high

; lines after vert sync
VertCounter3Loop:

	; 25.17uS display line approx 251 cycles
	Delay100TCY
	Delay100TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop

	; hsync front porch
	; .94uS approx 9 cycles
	; reset the other line counters
	setf	LineCount1
	movlw	0xE0
	movwf	LineCount2
	movlw	0x0D
	movwf	VertCount1
	movlw	0x02
	movwf	VertCount3
	nop
	nop

	; hysnc pulse
	; 3.77uS approx 38 cycles
	bcf	PORTB, 7
	Delay10TCY
	Delay10TCY
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	bsf	PORTB, 7
	
	; hsync back porch
	; 1.89uS approx 19 cycles
	Delay10TCY
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	VertCount3
	goto	VertCounter3Loop
	goto	VideoLoop

end
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top