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 stop working

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



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

TIMER1 stop working
PostPosted: Tue Oct 05, 2010 2:30 am     Reply with quote

Hi everybody, I have a setup that gets a sensor reading every 15 mins. and stores it in a flash memory. The flash memory communicates via SPI while the sensor uses serial communication. I used an external 32.7658khz oscillator as RTC in TIMER1. With code manipulation, this cause an interrupt every second. It has been working for almost two weeks and suddenly it stopped acquiring data. I noticed that the TIMER1 stopped having interrupts. Its like the TIMER1 stopped working. Can anybody tell me why this happens? I don't have a clue as to why this happens. Please help. Thanks.

Here are snippets of my code.
Code:

#include <18F26K20.h>
#device adc=10
#device PASS_STRINGS = IN_RAM
#include <stdlib.h>
#include <string.h>
#FUSES NOWDT, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, PBADEN, LPT1OSC, MCLR
#use delay(clock=16000000)

#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_B3, stream=PC)
#use rs232(baud=4800, xmit=PIN_B2, rcv=PIN_B1, stream=SNSR)

#Byte TMR1H = 0xFCF   // TIMER1 HIGH BYTE
#Byte T1CON = 0xFCD  //TIMER1 CONFIG REGISTER

//...............................
// i have also enabled these interrupts in main()

 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
 enable_interrupts(INT_TIMER1);
 enable_interrupts(int_rda);
 enable_interrupts(int_ext);
 enable_interrupts(GLOBAL);

// this is my code to handle the interrupt in TIMER1
#int_TIMER1
void TIMER1_isr()   
{
   bit_clear(T1CON,7);
   Bit_Set(TMR1H,7);
   Bit_Set(T1CON,7);
   if (++sec>59){
      sec=0;
      testFlag=true;
      if(++min>59){
         min=0;
         HourGprs++;
         HourBool=1;
         if(++hour>23){
            hour=0;
            ++days;
            if ((days == 29 && Month== 2 && !IS_LEAP(Year))
               || (days == 30 && Month==2)
               || (days == 31 && (month==4 || month==6 || month==9 || month==11))
               || (days == 32)
               ){month++;days=0;}
            if(month == 13) {year++; month=0;}
         }
      }
   }
   if ((min==0) || (min == 15) || (min == 30) || (min == 45) )
   {
      if (checkMinute == FALSE)
      {
         checkMinute = TRUE;
         samplingFlag = TRUE;
      }
   }
   else
      checkMinute = FALSE;
}

Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Tue Oct 05, 2010 7:44 am     Reply with quote

It is probably not the timer, but something else hanging, and stopping the timer from working.
Obvious question, you have INT_RDA enabled, yet neither of the serial streams you show use the pins for the hardware serial?...
If the hardware UART is available, add 'debug' entries to your code, using this, that send one byte when routines are entered, with a different byte value for each routine. The last byte sent when the hang occurs will help to narrow down what is happening. One 'guess' would be that interrupts are getting disabled somewhere and not re-enabled.
If you are using the hardware UART, make sure you are handling overrun errors, or have 'ERRORS' in the UART definition, otherwise a missed character here, could hang the UART, and then the code. This also may be happening even with 'ERRORS' enabled, unless CCS specifically has handling for the two EUSART erratas on this chip.

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