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

LFINTOSC

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







LFINTOSC
PostPosted: Fri Jun 17, 2005 4:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 4:55 pm     Reply with quote

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







PostPosted: Sat Jun 18, 2005 3:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 18, 2005 10:18 am     Reply with quote

Can you state what PIC you're using, so we can look at it and
see what the options are ?
HexMeister
Guest







PostPosted: Sun Jun 19, 2005 4:28 am     Reply with quote

This is nanowatt flash device (16F913)...
If you have time please look at this chart:

http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=103&mid=10&lang=en&pageId=74

Incording to pdf this switching part should be peace of cake but i will need your support how to make this in CCS ...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 19, 2005 5:08 pm     Reply with quote

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.
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