Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/16/06 12:46
Read: times


 
#118409 - Update of the code...
Responding to: ???'s previous message
An update of the code. I just count TempCount again after 1 attempt and the code works, but I don't know why :(
Do you know what was wrong with the code?

unsigned short MeasureClockfrequency()
{
	unsigned short TempCount;
	EA=0;
	//Make sure RTC is disabled to make it possible to write to RTCH, RTCL and other bits of RTCCON
	RTCCON = 0x00;
  	RTCCON = 0x00;
	// set reload value
  	// count frequency = clock source / 128 / RTCH,RTCL
  	RTCH = 0x00;
//  	RTCL = 0x01;
	RTCL = 0x2F;	

	//RTCPD=1;

	//First attempt, Result isn't good
	TempCount=0;
  	// select External crystal oscillator, disable interrupt source
  	RTCCON = 0x00;

	// start real time clock
	RTCCON |= 0x01;

	//Increase counter while the RTC doesn't time-out
	while (!(RTCCON & 0x80)) TempCount++;

	// clear RTCF interrupt flag and stop the real time clock
	RTCCON &= ~0x81;	

	//Try to determine frequency again, this result is good
	TempCount=0;
  	// select External crystal oscillator, disable interrupt source
  	RTCCON = 0x00;

	// start real time clock
	RTCCON |= 0x01;

	//Increase counter while the RTC doesn't time-out
	while (!(RTCCON & 0x80)) TempCount++;

	// clear RTCF interrupt flag and stop the real time clock
	RTCCON &= ~0x81;

	EA=1;

	return TempCount;
}


List of 6 messages in thread
TopicAuthorDate
Measuring frequency clock input LPC931            01/01/70 00:00      
   Update of the code...            01/01/70 00:00      
   what does "below" mean            01/01/70 00:00      
      below 7MHz            01/01/70 00:00      
         of course            01/01/70 00:00      
            thanks            01/01/70 00:00      

Back to Subject List