View previous topic :: View next topic |
Author |
Message |
jpage
Joined: 23 Jun 2004 Posts: 24
|
Running timer1()_isr on external clock |
Posted: Mon Sep 27, 2004 11:19 am |
|
|
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
|
|
Posted: Mon Sep 27, 2004 12:27 pm |
|
|
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
|
Running timer1()_isr on external clock |
Posted: Mon Sep 27, 2004 2:27 pm |
|
|
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
|
|
Posted: Mon Sep 27, 2004 3:58 pm |
|
|
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. |
|
|
|