View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
Two clock speeds |
Posted: Mon Mar 12, 2012 1:51 pm |
|
|
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? _________________ Electric Blue |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 12, 2012 2:21 pm |
|
|
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
|
|
Posted: Wed Mar 14, 2012 12:50 pm |
|
|
Thanks for the links!
Reading & Testing. _________________ Electric Blue |
|
|
|