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

Problem with PIC24E 32-bit timer

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



Joined: 23 Oct 2012
Posts: 4

View user's profile Send private message

Problem with PIC24E 32-bit timer
PostPosted: Tue Oct 23, 2012 8:21 am     Reply with quote

Hi, I'm beginner to program PIC with CCS PCD compiler.

I'm trying to set a 32-bit timer, but the interrupt is not intercepted.

Here my code:
Code:


#define CSDB_TIMER2_3_THR     0x01C9C3

#int_timer3 //Level = 4
void int_timer23_isr()
{   
   int32 val;
   val = get_timer23();
   
   // TODO
#ifdef PRINT
   printf("int_timer23 intercepted\n");
#endif

}


void main()
{
 // setups TIMER 2-3 for CSDB msg
   setup_timer2(TMR_DIV_BY_256| TMR_32_BIT);

   set_timer23(CSDB_TIMER2_3_THR);           // sets timer thresold
   
   //clear_interrupt(INT_TIMER3);
   enable_interrupts(INT_TIMER3);
}



Can someone tell me where is the error?
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 8:37 am     Reply with quote

Code:

enable_interrupts(INTR_GLOBAL);

always needed.

something to stop the code running off the end:
Code:

do {
} while(TRUE);

Otherwise chip will go to sleep and the timer stop.

Best Wishes
Simone



Joined: 23 Oct 2012
Posts: 4

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 9:03 am     Reply with quote

Thanks,

I added while loop in my code but interrupt is not intercepted yet.

Code:


#define CSDB_TIMER2_3_THR     0x01C9C3

#int_timer3 //Level = 4
void int_timer23_isr()
{   
   int32 val;
   val = get_timer23();
   
   // TODO
#ifdef PRINT
   printf("int_timer23 intercepted\n");
#endif

}


void main ()
{   
   
   while(TRUE)
   {
      setup_timer2(TMR_DIV_BY_256| TMR_32_BIT);
      set_timer23(CSDB_TIMER2_3_THR);           
   
      //clear_interrupt(INT_TIMER3);
      enable_interrupts(INTR_GLOBAL);
      enable_interrupts(INT_TIMER3);
         }

}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 9:13 am     Reply with quote

1) What's your clock frequency?

And

2) How long are you waiting for an interrupt to occur?

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 9:15 am     Reply with quote

First step...cut code for the 'blinking LED' program and confirm the PIC is running!

2nd step...post a COMPLETE small program with the problem. Nobody knows which PIC you're using. Also post which version of the compiler, as there may be a 'bug' in your version.

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 23, 2012 5:23 pm     Reply with quote

Come on guys, the problem is that he didn't follow Ttelmah's instructions.
Ttelmah said to put a while at the end, not to put everything in a loop.
His timer is getting reloaded every few micro-seconds. It will never work.

Example of how to do it:
Code:

void main()
{

// Put your timer setup code, and your interrupt
// enable code here.  Don't put a while() loop here.



while(1);  // Put this line here.  Prevent PIC from going to sleep.
}
Simone



Joined: 23 Oct 2012
Posts: 4

View user's profile Send private message

PostPosted: Wed Oct 24, 2012 12:57 am     Reply with quote

Thanks,

Now, my timer works!
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