uS Delay Function Using Core Timer

//******************************
//******************************
//********** DELAY US **********
//******************************
//******************************
//Uses Core Timer
void delay_us (uint16_t delay)
{
	unsigned int int_status;

	int_status = INTDisableInterrupts();
	OpenCoreTimer((INSTRUCTION_CLOCK_FREQUENCY / 2000000) * delay);	// Core Timer updates every 2 ticks
	mCTClearIntFlag();					//Clear core timer interrupt flag before re-enabling interrupts to avoid posibility of ISR from another interrupt causing us to miss the CT interrupt.
	INTRestoreInterrupts(int_status);
	while( !mCTGetIntFlag() )
		;

	mCTClearIntFlag();
}

mS Delay Function Using Core Timer

//#define	INSTRUCTION_CLOCK_FREQUENCY	80000000
  
//******************************
//******************************
//********** DELAY MS **********
//******************************
//******************************
//Uses Core Timer
void delay_ms (uint16_t delay)
{
	unsigned int int_status;
	while(delay--)
	{
		int_status = INTDisableInterrupts();
		OpenCoreTimer(INSTRUCTION_CLOCK_FREQUENCY / 2000);	// Core Timer updates every 2 ticks
		mCTClearIntFlag();					//Clear core timer interrupt flag before re-enabling interrupts to avoid posibility of ISR from another interrupt causing us to miss the CT interrupt.
		INTRestoreInterrupts(int_status);
		while( !mCTGetIntFlag() )
			;
	}
	mCTClearIntFlag();
}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.