View previous topic :: View next topic |
Author |
Message |
HexMeister Guest
|
LFINTOSC |
Posted: Fri Jun 17, 2005 4:20 am |
|
|
Hi!
How to get corect time counting after switching from HFINTOCS (1MHZ) to
LFINTOSC (125 KHZ).
I change the HF to LF when i go to sleep but i must ( or not ) change the recalculation of time ( regarding the new clock speed )...
Time will count further in LF mode.
How to do this ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 17, 2005 4:55 pm |
|
|
Is your problem with using the CCS delay routines with a two-speed
clock ? The following program shows one way to adjust for the
speed difference by placing different #use delay() statements in
the program. If you have a lot of #use delay() statements then
perhaps a better way than this should be used.
Code: | #include <16F688.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock = 1000000)
int8 slow_speed;
void main()
{
setup_oscillator(OSC_1MHZ);
slow_speed = FALSE;
if(slow_speed == TRUE)
{
#use delay(clock = 125000)
delay_ms(10);
}
else
{
#use delay(clock = 1000000)
delay_ms(10);
}
// This line will use the 1 MHz clock speed,
// because the last #use delay() is for 1 MHz.
delay_ms(5);
while(1);
} |
|
|
|
HexMeister Guest
|
|
Posted: Sat Jun 18, 2005 3:42 am |
|
|
TYPING ERROR: both clock speeds are using HFINTOSC
I have "a lot" delays so i was thinking of some new approach.
I have been switching directly thru oscon reg but i found some interesting routines in CCS so maybe i can use them
He is internal oscilators so the delay time should not be so critic. The greater problem i that i must recalculate the time and i dont know what is the bast way to make this in CCS...
Example
HFINTOSC (1MHZ) --> time 1.25.22
Enter "sleep"
Switch to 125 KHZ
HFINTOSC (125KHZ) --> time 1.25.23
Time should be counting without "break" and continiusly so the switching part should not effect at time count. After some keypress i switch back to 1MHZ. You can look at this like of some kind of sleep action.
Timer 1 is used for HFINTOSC.
Calculation
1000000 / (4*65536) -- HFINTOSC // 3.81
125000 / (4*65536) -- HFINTOSC // 0.47
Problem
How would you make right RTC time calculation so you would not be loosing second with switch part?
Should i define another counter in timer 1 which should be counting on 125 KHZ clock , and then simply switch from 1MHZ counter to 125 khz counter ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 18, 2005 10:18 am |
|
|
Can you state what PIC you're using, so we can look at it and
see what the options are ? |
|
|
HexMeister Guest
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 19, 2005 5:08 pm |
|
|
If you are switching clock speeds, I think it would be easier to
use an external 32.768 KHz crystal on the Timer1 pins. Then
Timer1 will always run at the same speed (suitable for a RTC).
You can then change the PIC clock speed to 1 MHz, 125 KHz,
or even Sleep mode, and Timer1 will still keep running at 32.768 KHz. |
|
|
|