View previous topic :: View next topic |
Author |
Message |
uhoh-robbo Guest
|
Help with Interrupts 18F248 |
Posted: Fri Feb 17, 2006 10:38 am |
|
|
Hello,
I cant seem to get any othe interrupts working on the PIC. I am using the following:
enable_interrupts ( INT_TIMER0 );
enable_interrupts (INT_EXT);
enable_interrupts (INT_EXT1);
enable_interrupts ( GLOBAL );
I dont think the internal interrupt is working and I know that niether of the exteral EXT and EXT1 are working.
Any ideas?
Cheers |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 17, 2006 10:57 am |
|
|
What is in your interrupt handler (you must have code for _all_the enabled interrupts)?.
Best Wishes |
|
|
Guest
|
|
Posted: Fri Feb 17, 2006 11:07 am |
|
|
This is for the external interrupts. Oh and by the way I have used set_tris_B to enable these pins as inputs.
/*Manual On Override*/
#INT_EXT1
void external1(void)
{
OverrideOn++;
output_high(GREEN);
}
/*Manual Off Override*/
#INT_EXT
void external0(void)
{
OverrideOff++;
output_high(YELLOW);
} |
|
|
Guest
|
|
Posted: Fri Feb 17, 2006 11:08 am |
|
|
This is for the external interrupts. Oh and by the way I have used set_tris_B to enable these pins as inputs.
/*Manual On Override*/
#INT_EXT1
void external1(void)
{
OverrideOn++;
output_high(GREEN);
}
/*Manual Off Override*/
#INT_EXT
void external0(void)
{
OverrideOff++;
output_high(YELLOW);
} |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 17, 2006 11:24 am |
|
|
Where is the timer handler?.
Best Wishes |
|
|
uhoh-robbo Guest
|
|
Posted: Fri Feb 17, 2006 11:28 am |
|
|
Here it is :-)
#INT_TIMER0
TIM0_ISR()
{
static unsigned char Second_Ticks = 0, SecCount = 0;
/* set the timer to 112 to maintain frequency to 100Hz */
set_timer0(TIM_TIMER0_RELOAD_VAL);
Second_Ticks++;
/* do the following every 1s */
if (100 == Second_Ticks)
{
Second_Ticks=0; /* reset 1s timer */
SecCount++;
if (SecCount==60)
{
if (Node.RobTime == MIN_IN_A_DAY)
{
Node.RobTime = 0;
}
Node.RobTime++;
SecCount=0;
}
if (Node.RunTimer) Node.Timer--;
if (CANTimer.Running) RunCANTimer();
}
} |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 17, 2006 11:51 am |
|
|
First comment. Use the code button!. It makes things vastly easier to understand.
What makes you think it isn't running?. There are a few caveats (for instance, NodeRobTime, will never be '0'. You set it to zero, and then execute the instruction to increment it, so it'll always be one or more.
Setting the timer 'to' a value, is very dangerous, since if anything delays arriving at the interrupt handler, the count may well have already changed. From the low frequency you are talking about, I'd suspect you have a high prescaler though, and in which case this may be OK.
Is it possible the code is getting stuck in 'RunCanTimer'?.
Realistically, do a simple test, and toggle an LED, inside this routine. Remove any external calls, and I suspect you will find it is running.
Best Wishes |
|
|
Guest
|
|
Posted: Sun Feb 19, 2006 7:45 pm |
|
|
Well I know that the external interrupts aren't working. As they dont turn on an led.
I expect that none of the interrupts are working, but I will do as u suggest on the timer interrupt.
As for RobTime it doesn't affect anything although it does meani would be loosin a minute every day! oops...
I really dont think that the code is getting stuck in 'RunCanTimer' as I have the same function running on other pic's.
Thanks |
|
|
uhoh-robbo Guest
|
|
Posted: Tue Feb 21, 2006 6:32 am |
|
|
I have commented out all of the code in the TIM0_ISR() and tried to make an LED flash. But it did nothin. So I dont think that ANY of the interrupts are working. But I have no idea why. Any Suggestions???? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Feb 21, 2006 7:14 am |
|
|
The fragments of your code you gave us look alright, but it is very well possible there are problems in the other parts. Maybe the problem is not in the interrupts at all, are you sure the processor is running?
Please create a small test program that does something simple like blinking a led, when that works add a simple interrupt routine. In case of problems you can post the small program and we will have a look. This sounds boring and way beyond your capabilities but there might be a simple error like #fuse that you are overlooking. |
|
|
uhoh-robbo Guest
|
|
Posted: Tue Feb 21, 2006 3:21 pm |
|
|
I know the program is running. It uses CAN and happily transmits and recieves messages as expected. In fact the whole program is running perfectly except for the interrupts |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Feb 21, 2006 6:11 pm |
|
|
In the situation of problems like you are having I always try to go back to the basics and write a small as possible test program. You've added three interrupts and want us to tell you why none of them is working? First try to get one interrupt working before making things too complex.
I don't want to see your complete program, it'll take too much of my time to study. Write a simple test program with the timer0 interrupt that blinks a led every second. Post that complete program including fuses, etc, here and we'll have a look.
If you don't want to do so I refuse to help any further. |
|
|
uhoh-robbo Guest
|
|
Posted: Tue Feb 21, 2006 6:56 pm |
|
|
Ok here is a small program. It should just toggle the C2 pin. But still no joy. Thanks for your help so far.
Code: |
#include "18F248.h"
#define TIM_TIMER0_RELOAD_VAL 112
#fuses HS, NOWDT, NOPROTECT, NOPUT
void main (void)
{
/* setup timer */
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT );
/* enable timer 0 overflow interrupt */
enable_interrupts ( INT_TIMER0 );
enable_interrupts ( GLOBAL );
}
#INT_TIMER0
void TIM0_ISR()
{
static unsigned char Second_Ticks = 0;
static int1 OnorOff=0;
/* set the timer to 112 to maintain frequency to 100Hz */
set_timer0(TIM_TIMER0_RELOAD_VAL);
Second_Ticks++;
output_high(PIN_C0);
/* do the following every 1s */
if (100 == Second_Ticks)
{
if(!OnorOff)
{
output_high(PIN_C2);
OnorOff=1;
}
else
{
output_low(PIN_C2);
OnorOff=0;
}
Second_Ticks=0;
}
}
|
|
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Feb 21, 2006 7:40 pm |
|
|
You're initializing Second_Ticks and OnorOff INSIDE your isr.
Every time timer 0 interrupts, these variables are reset to 0. Will Second_Ticks ever get to 100 this way? |
|
|
uhoh-robbo Guest
|
|
Posted: Tue Feb 21, 2006 7:52 pm |
|
|
its a static unsigned char. Hence everytime the function is called it will use its previous value. |
|
|
|