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

doubt

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







doubt
PostPosted: Tue Feb 15, 2005 4:09 pm     Reply with quote

Hi everyone,
I have a small doubt. I am enabling a timer in PIC that interrupts every 15ms. I have a subroutine, that has a delay statement with delay of 20ms. I would like to know, whether timer interrupts in between the delay statements or not. I believe that delay statements are just NOP commands in Assembly and timer would interrupt in between them, if it overflows. Please post any comments and corrections if I am wrong.

sk
flip



Joined: 15 Feb 2005
Posts: 11

View user's profile Send private message

doubt
PostPosted: Tue Feb 15, 2005 4:16 pm     Reply with quote

Yes. the timer interrupts when the program is in the delay subroutine.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 15, 2005 4:32 pm     Reply with quote

The interrupt flag is set, but the interrupt may not be serviced
immediately in certain cases.

See these threads for the reason why:
http://www.ccsinfo.com/forum/viewtopic.php?t=20704
http://www.ccsinfo.com/forum/viewtopic.php?t=21367
Also see this thread which discusses it more,
and provides a link to Darren Rook's FAQ article
with a work-around solution.
http://www.ccsinfo.com/forum/viewtopic.php?t=18356
flip



Joined: 15 Feb 2005
Posts: 11

View user's profile Send private message

Timer0 interrupt
PostPosted: Tue Feb 15, 2005 5:21 pm     Reply with quote

I cant get my timer0 interrupt to work do you know what the problem is ?

Code:


#include <18F458.h>     //up/down counter with 3 7 segment displays no max or min
#use delay(clock=20000000)
#fuses HS, OSCSEN, BROWNOUT, BORV20, STVREN, DEBUG, LVP

int t = 0;


#int_TIMER0 // interrupt occurs every 3.2micro sec * 256 = 819.12 micro seconds
TIMER0_isr()
{
   
   if (t++ == 244)   // After t gets up to 2441 , 2 seconds has lapsed 819.12 micro seconds * 2442 = 2 seconds
   {
      t = 0;
      output_c(0x03);  // output a light every 2 seconds
      delay_ms(100);
   }

}

void main()
{


   set_tris_d(0xFF);
   set_tris_a(0xFF);
   set_tris_b(0xFF);
   set_tris_c(0xFF);
   set_tris_e(0xFF);

   setup_counters(RTCC_INTERNAL, RTCC_DIV_32); //pulse occurs every 3.2 micro seconds (1/(40MHz/4*32))
   enable_interrupts(INT_TIMER0);
   enable_interrupts(global);

   while(1)
   {
   
    output_c(0x01);

         
    }
 }
flip



Joined: 15 Feb 2005
Posts: 11

View user's profile Send private message

Timer0 interrupt
PostPosted: Tue Feb 15, 2005 5:22 pm     Reply with quote

I cant get my timer0 interrupt to work do you know what the problem is ?

Code:


#include <18F458.h>     //up/down counter with 3 7 segment displays no max or min
#use delay(clock=20000000)
#fuses HS, OSCSEN, BROWNOUT, BORV20, STVREN, DEBUG, LVP

int t = 0;


#int_TIMER0 // interrupt occurs every 3.2micro sec * 256 = 819.12 micro seconds
TIMER0_isr()
{
   
   if (t++ == 244)   // After t gets up to 2441 , 2 seconds has lapsed 819.12 micro seconds * 2442 = 2 seconds
   {
      t = 0;
      output_c(0x03);  // output a light every 2 seconds
      delay_ms(100);
   }

}

void main()
{


   set_tris_d(0xFF);
   set_tris_a(0xFF);
   set_tris_b(0xFF);
   set_tris_c(0xFF);
   set_tris_e(0xFF);

   setup_counters(RTCC_INTERNAL, RTCC_DIV_32); //pulse occurs every 3.2 micro seconds (1/(40MHz/4*32))
   enable_interrupts(INT_TIMER0);
   enable_interrupts(global);

   while(1)
   {
   
    output_c(0x01);

         
    }
 }
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Tue Feb 15, 2005 9:11 pm     Reply with quote

Rember that any function you call from an isr and from the main program will have interrupts disabled. This includes the delay_ms() routine.
bluetooth



Joined: 08 Jan 2005
Posts: 74

View user's profile Send private message

PostPosted: Wed Feb 16, 2005 8:19 am     Reply with quote

Even though fast_io is not specified, I wonder why all the TRIS's are being set to 0xff - makes generating an output really tough....

Microchip DDR = ~Motorola DDR!

My $0.02....
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