Click here to Skip to main content
14,238,591 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I'm trying to combine two of my code to run together to calculate the frequency and number of line in HYSNC and VSYNC signal. I have got the VGA signal from a cpu and im using change notification to capture the VSYNC signal and timer/counter to capture or count the number of HSYNC lines in the signal between one period of VSYNC. I cant get the code working according to what i want. I need some help in getting this code working..thanks so much...

#include<plib.h>
// Configuration Bit settings
// SYSCLK = 80 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV)
// PBCLK = 40 MHz
// Primary Osc w/PLL (XT+,HS+,EC+PLL)
// WDT OFF
// Other options are don't care
//
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_8
#define CONFIG          (CN_ON | CN_IDLE_CON)
#define PINS            (CN15_ENABLE)
#define PULLUPS         (CN15_PULLUP_ENABLE)
#define INTERRUPT       (CHANGE_INT_ON | CHANGE_INT_PRI_2)
#define SYS_FREQ         (80000000L)
char a = 0;	//flag
char done = 0;
void init (void)
{
	unsigned int temp;
	//Configure cache, wait states and peripheral bus clock
	SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
	//configure the port registers
	PORTSetPinsDigitalOut(IOPORT_D, BIT_0 | BIT_1);
        PORTSetPinsDigitalIn(IOPORT_F, BIT_5);
	
	//initialize the port pin states = outputs low
	mPORTDClearBits(BIT_0 | BIT_1);
	
	//enable change notice, enable discrete pins and weak pullups
	mCNOpen(CONFIG, PINS, PULLUPS);
	//read port(s) to clear mismatch on change notice pins
	temp = mPORTFRead();
	
	//clear change notice interrupt flag
	ConfigIntCN(INTERRUPT);
	//enable multi-vector interrupts
	INTEnableSystemMultiVectoredInt();
}
void Timer (void)
{
	//configure Timer 2
	OpenTimer2(T2_ON | T2_SOURCE_EXT | T2_PS_1_1, 1);
	//set up the timer interrupt with a priority of 2
	ConfigIntTimer2(T2_INT_ON | T2_INT_PRIOR_2);
}
int main(void)
{
	init();
	while(1)
   {
       // .. add things to do
   };
}
void __ISR(_CHANGE_NOTICE_VECTOR, ipl5) ChangeNotice_Handler(void)
{
    unsigned int temp;
	
    // clear the mismatch condition
    temp = mPORTFRead();
	
    // clear the interrupt flag
    mCNClearIntFlag();
	
	if (PORTReadBits(IOPORT_F, BIT_5) !=0 )
	{	
		if (done == 0)
		{
			char count = 0;
			// .. things to do .. toggle the led
	    	mPORTDToggleBits(BIT_0);
			Timer();
			a = 1;	//flag
			count = ReadTimer2();
		}
		else
		{
			CloseTimer2();
		}
	}
	if (PORTReadBits(IOPORT_F, BIT_5) ==0 )
	{
		CloseTimer2();
		a = 0;
		done = 1;
	}
}
void __ISR(_TIMER_2_VECTOR, ipl2) Timer1Handler(void)
{
    // clear the interrupt flag
    mT2ClearIntFlag();
    // .. things to do
    // .. in this case, toggle the LED
    mPORTDToggleBits(BIT_1);
}
Posted
Updated 12-May-10 18:01pm
v2
Comments
Michel Godfroid 13-May-10 2:17am
   
You're unlikely to find an answer here. First because you do no tell us what is your exact problem ("I cant get the code working according to what i want" is a statement, not a question). And even then, you would be hard-pressed to find a PIC32 specialist here. I suggest you take this question (after turning it into a question) to specialised hardware forum, probably associated with your hardware manufacturer.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Micheal Godfroid is right in that you will probably get a better response from a more dedicated forum - there are PIC people here, but they are few and far between.

In the mean time, I would start by checking inputs etc: Hook up a dual channel sig gen at a low frequency and check you catch everything. Then slowly increase to the frequency / pulse width combination you expect in real life, before connecting to the real signal. Since VGA is only about 36KHz Hsync, it shouldn't be a problem, but it may be something silly, like you missing pulses because they are too short, wrong voltage, line loading, etc.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100