View previous topic :: View next topic |
Author |
Message |
Simone
Joined: 23 Oct 2012 Posts: 4
|
Problem with PIC24E 32-bit timer |
Posted: Tue Oct 23, 2012 8:21 am |
|
|
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: 19515
|
|
Posted: Tue Oct 23, 2012 8:37 am |
|
|
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
|
|
Posted: Tue Oct 23, 2012 9:03 am |
|
|
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
|
|
Posted: Tue Oct 23, 2012 9:13 am |
|
|
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: 9228 Location: Greensville,Ontario
|
|
Posted: Tue Oct 23, 2012 9:15 am |
|
|
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
|
|
Posted: Tue Oct 23, 2012 5:23 pm |
|
|
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
|
|
Posted: Wed Oct 24, 2012 12:57 am |
|
|
Thanks,
Now, my timer works! |
|
|
|