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 support@ccsinfo.com

Two clock speeds

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



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

Two clock speeds
PostPosted: Mon Mar 12, 2012 1:51 pm     Reply with quote

I'm running a PIC18F67J50 with 8MHz and PLL at 48MHZ when the PIC is awake, but when is in low power mode I'm running from different clock, depending how much work must do; it can run from INTRC 8MHz or from TMR1 OSC at 32.768KHz.

I'm wondering how I must to manage the #use delay() directive. In the help it says that the #use delay directive can be used as many time as needed but I don't understand if they cancel each other or what.

I.E.

Code:

#use delay(48M)
char speed=1;
void Delay_1S (void)
{
   if(speed==1)
    {
       #use delay(48M)
      delay_ms(1000);
    }
   else
    {
       #use delay(8M)
      delay_ms(1000);
    }
}
void RoutineX(void)
{
....
delay_ms(1)
....
}



It's this code OK?
What about the remaining routines? The delay, for those routines(RoutineX), are computed/calculated for 48MHz or 8MHz? Question
_________________
Electric Blue
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 12, 2012 2:21 pm     Reply with quote

All code that occurs after a #use delay() statement in the file
will use that specified frequency to calculate delays and timings.
This is linear, from top to bottom in a file. If another #use delay()
statement occurs farther down in the file, then all code after that
#use delay() will have the delays based on that frequency.

However, you have to keep in mind where the compiler is doing the
calculations. For example, the baudrate generator for the UART is
setup by ASM code placed at the beginning of main() by the compiler.
You can see this in the .LST file. If you change the PIC's oscillator speed,
and you want to keep the same UART baud rate, then you need to put
a #use delay() statement, followed by a call to set_uart_speed().

Ttelmah has another way to do it in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=32903

This thread also has information on it:
http://www.ccsinfo.com/forum/viewtopic.php?t=32758
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Wed Mar 14, 2012 12:50 pm     Reply with quote

Thanks for the links!

Reading & Testing. Wink
_________________
Electric Blue
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