CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sanity check on use of setup_oscillator()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

Sanity check on use of setup_oscillator()
PostPosted: Fri Jul 16, 2004 1:35 pm     Reply with quote

I'm running on a PIC18F2320 @ 8MHz. I've got a state in my program that waits for a specified number of seconds. I'd like this delay to use as little power as possible without resorting to timer interrupts, and a colleague suggested that I set the internal oscillator to 31KHz from 8MHz. I tried the following, but it seemed to render the PIC kaput. I added the #use delay based on the information in PCW's readme.txt.

delay_seconds() uses delay_ms(), which I'm guessing is affected by the #use delay statement.

Code:
case Delay:
   trace ("Delay");
   setup_oscillator(OSC_31KHZ);
   #use delay (clock=31000)
   delay_seconds(60);
   setup_oscillator(OSC_8MHZ);
   #use delay (clock=8000000)
   state = Init_Program;
   break;


--
Jeff S.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 16, 2004 5:58 pm     Reply with quote

I didn't try to solve your problem by compiling your code
and looking at the .LST file.

But I can give you a tip that may pertain to your problem.

The "#use delay" statement is a linear statement. It does not
"follow" code as it goes from one function call to the next.
It just applies to any code that comes after it, until such time
as another #use delay statement is encountered.

So, your delay_seconds() function is very likely being
compiled based on a 8 MHz clock, but you're assuming it
will work with a 31.250 KHz clock as well.

If you want a delay routine that works with the slower clock,
I suggest that you put a "#use delay(31250)" statement
at the end of your program, and put in a new delay_seconds()
function with a special name at that point. Example:

#use delay(clock=31250)
void delay_seconds_31KHz(char seconds)
{
char i;
for(i = 0; i < seconds; i++)
delay_ms(1000);
}

Then change your main program code to call that function
instead of the normal delay_seconds() function. See the
line in bold, below.

case Delay:
trace ("Delay");
setup_oscillator(OSC_31KHZ);
#use delay (clock=31000)
delay_seconds_31KHz(60); // Change this line
setup_oscillator(OSC_8MHZ);
#use delay (clock=8000000)
state = Init_Program;
break;

Also, I assume that the real clock speed is 31.250 KHz, so
you might want to change the #use delay statement to
reflect that.

I don't guarantee this will fix all your problems. There may
be a problem with switching oscillator frequencies, as well.
You should check the .LST file to verify that the code which
sets the frequency is correct. But at least my suggestion
should get you farther along.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group