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 support@ccsinfo.com

Problem with timer interrupts

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



Joined: 25 May 2013
Posts: 7

View user's profile Send private message

Problem with timer interrupts
PostPosted: Fri Jun 21, 2013 10:28 am     Reply with quote

i'm using the PIC 18F4550.
- [i'm just configing interrupt timer0 but timer timer0 just counts about several seconds then it stops. i don't know why it can not operate. please help me debug, config interrupt for timer.] i solved
- i have new problem that i set timer0 be overflow 10us, but it seems incorrect, please help me check it.
code
Code:
#include <18F4550.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES ICPRT                    //ICPRT enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(crystal=16000000,  clock=16000000)

int16 dem;
#int_TIMER0

void  TIMER0_isr(void)
{
  if(interrupt_active(int_timer0))
   {
 
   set_timer0(236);
   dem++;
   if(dem==50000)
   {
      dem=0;
      output_toggle(pin_c1);
   }
 
   }
}



void main()
{
set_timer0(236);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2|RTCC_8_bit);      //128 us overflow
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);


}



Last edited by hoangtuanthien on Sat Jun 22, 2013 5:25 am; edited 1 time in total
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Jun 21, 2013 11:03 am     Reply with quote

Hi,

I didn't look over your entire code carefully, but I do see one glaring problem immediately. The CCS compiler inserts a hidden sleep instruction
at the end of your code by default. You must not allow your program to ever reach this sleep instruction if you want the code to continue running!
Look at the .lst file that is generated when you compile your code, and you'll see what I mean!

To avoid this issue, add the following code shown in bold in the place shown:

Quote:

enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);

while(1);

}


John
hoangtuanthien



Joined: 25 May 2013
Posts: 7

View user's profile Send private message

PostPosted: Fri Jun 21, 2013 6:25 pm     Reply with quote

thanks, John. it operated
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