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

Running timer1()_isr on external clock

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



Joined: 23 Jun 2004
Posts: 24

View user's profile Send private message

Running timer1()_isr on external clock
PostPosted: Mon Sep 27, 2004 11:19 am     Reply with quote

Does anyone know how to keep the internal clock (4MHZ) from running while executing the timer1_isr.

The interrupt is working correctly by shutting off the internal clock and running only on the external clock (32.768 Khz).--Sleep mode
It causes an interrupt every 2 seconds, but noticed that the 4MHZ xtal is running when it executes the timer1_isr.

I don't want the 4MHZ xtal to run everytime it accesses the timer1_isr.
I am trying to conserve as much battery power as possible by only turning on the 4MHZ xtal when transmitting data.


I will eventually just have a counter in the timer_isr, which will increment everytime the isr is accessed.
The LED is just for testing purposes.

Thanks for any help.


Code:


#include <18f4320.H>
#fuses HS,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP, NOWDT, NOFCMEN  // Added NOWDT and NOFCMEN
#use delay (clock=4000000)

#define POWER_LED      PIN_E0
#define CAL_LED         PIN_B4   
////////////////////////////////////////////////////TMR1 InterrruptService Routine//////////////////
#int_TIMER1
void timer1_isr()
{

output_high(CAL_LED);            //XT crystal takes over here
delay_ms(1000);
output_low(CAL_LED);
}
////////////////////////////////////////////////Main//////////////////////////////////////////////
void main()
{
int x;
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT); // 1:1 Prescalar Value
set_timer1(0);
 
enable_interrupts(GLOBAL);        // required for tmr1 interrupt
enable_interrupts(INT_TIMER1);     //
 
output_low(CAL_LED);   

while(1)
  {
   for (x=0;x<2;++x)           // Changed '<=' to '<'
    {
      output_high(POWER_LED);   //test OK indicator//
      delay_ms(250);
      output_low(POWER_LED);
      delay_ms(250);
   set_timer1(0);              
   sleep();               //will wake when timer1 times out; ISR serviced with XT crystal

   }

  }
}

Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Sep 27, 2004 12:27 pm     Reply with quote

It sounds like what you should be doing is oscilator switching instead of sleep mode or maybe in adition to sleep mode. Look at the fuses for the PIC. You should be able to switch to the fast ocilator for comunications and then switch to the slow oscilator for everyhting else. As it is right now you have a power drain while the 4Mhz oscilator is being powered on as you come out of sleep mode. You probably spend more time powering up the 4Mhz oscilator than you spend in the interupt routine when it wakes up.
jpage



Joined: 23 Jun 2004
Posts: 24

View user's profile Send private message

Running timer1()_isr on external clock
PostPosted: Mon Sep 27, 2004 2:27 pm     Reply with quote

Thanks for the reply.

I looked at the fuses as you mentioned and added the "#fuses EC" to the timer1_isr() and it kills the 4MHZ and timer1 oscillator (32.768KHZ).

Is there another way to do what you suggested by switching the clock xtals??

Code:


#int_TIMER1
void timer1_isr()
{

#fuses EC  //Added this and kills both the 4MHZ and 32.768KHZ Clocks
output_high(CAL_LED);            //XT crystal takes over here
delay_ms(1000);
output_low(CAL_LED);
}
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Sep 27, 2004 3:58 pm     Reply with quote

The fuse you want is;

OSCSEN Oscillator switching is enabled

Refer to the data sheet as well. This is a function thats is I believe available on most of the PIC18 series.

You may find that switching oscilators on the fly brings your power usage down enough that you don't have to use sleep mode at all.
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