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

timer1 interrupt does not fire

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
[email protected]



Joined: 24 Mar 2010
Posts: 24

View user's profile Send private message Send e-mail

timer1 interrupt does not fire
PostPosted: Thu Dec 23, 2010 3:36 am     Reply with quote

Hi,

I am using pic16f882 with ccs PCM 4.077.

My application goes to sleep after finishes task.

Between sleeps (during the task) I need timer1 to fire an interrupt every ~33ms (see my code).

What happens is that the interrupt fires only once before entering sleep in main loop.

Important note: when I replaced the SLEEP() command with while(1); the interrupt fires correctly and I see a ~33ms pulse as expected.

Can you tell me what is wrong with my code?

Thanks
Code:

#INT_TIMER1
void Timer1_ISR()   
{
    set_timer1(0xFFFF);      //every ~33m sec interrupt and recharge timer
   
   
    if (temporar == 0)
    {
        output_high (no_connected_RA5);    //pulse to measure timer interval
        temporar = 1;
       
    }
    else
    {
        output_low (no_connected_RA5);     //pulse to measure timer interval
        temporar = 0;
       
    }
   
}



void main(void)
{
   BYTE i;
   // set the internal clock to 8MHz ...
   setup_oscillator(OSC_8MHZ);
   setup_timer_1(T1_DIV_BY_1 | T1_INTERNAL);   
   
   INTCON = 0x00; // clear all interrupts
   
   
   set_tris_a(0x00);
   

   port_B_pullups(pin_B0);
   output_float(pin_B0);  //INPUT INT PIN B0
   IOCB = 0x00; // int RB not active
   SETUP_CCP1(CCP_OFF);
   SETUP_CCP2(CCP_OFF);
   SETUP_ADC(ADC_OFF);
   output_low (not_connected_B5);
   output_low (no_connected_RA5);
   output_low (no_connected_RA6);
   output_low (no_connected_RA7);
   

   CLEAR_INTERRUPT(INT_TIMER1);
   
   enable_interrupts (INT_TIMER1);
   enable_interrupts (INT_SSP);
   enable_interrupts (GLOBAL);
     
   #asm  // here interrupt enter !!!   
       NOP  //window for interrupt entry
       NOP  //window for interrupt entry
       NOP  //window for interrupt entry
       NOP  //window for interrupt entry
   #endasm

        disable_interrupts (GLOBAL);

      //--------------------------------
      // enter sleep mode
      //--------------------------------
   
   while(1)
   {
       
       INTCON = 0xD0;             // enable interrupts
       
       TMR1ON = 0;
       SLEEP();                       
   
   
       CLEAR_INTERRUPT(INT_TIMER1);     
       enable_interrupts (INT_TIMER1);
       TMR1ON = 1;
       setup_uart(TRUE);
       
       setup_timer_1(T1_DIV_BY_1 | T1_INTERNAL); 

       INTCON = 0x00;            // disable interrupts

   }
}

_________________
Gil F.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Thu Dec 23, 2010 3:50 am     Reply with quote

Study the data sheet.
Section 14.6.1.
Then the second list of numbered items. Number 1. Note the _limitation_ about Timer1. _Is_ your timer operating as an asynchronous counter?....
(Internal clock _stops_ when you sleep)

Best Wishes
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