|
|
View previous topic :: View next topic |
Author |
Message |
Andrewv
Joined: 20 Apr 2005 Posts: 1
|
Interrupts kill program |
Posted: Wed Apr 20, 2005 4:41 pm |
|
|
Hi.
I've been having huge problems the last few days trying to get my timer interrupts working. I have taken almost everything out of my code and it still doesn't work.
I am trying to get an interrupt on timer2 every 5 ms. I am using a PIC 18F6680. With a 10 Mhz clock. Using the Phase lock loop for a clock speed of 40 Mhz.
My problem is that when I enable interrupts my outputs go dead and the board doesn't seem to do anything.
Here is my code
Code: |
#include <18f6680.h>
#device ADC=10
#fuses H4,NOWDT,WDT128,NOPROTECT,NOLVP,CCP2C1,BROWNOUT,BORV45,PUT
#use delay(clock=40000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#use fast_io(F)
#use fast_io(G)
/**************************************************************************/
/* Initialize the I/O direction registers */
void initialize_IO_direction(void)
{
SET_TRIS_A(0b11111111);
SET_TRIS_B(0b11111111);
SET_TRIS_C(0b00000000);
SET_TRIS_D(0b11111111);
SET_TRIS_E(0b11111001);
SET_TRIS_F(0b11111110);
SET_TRIS_G(0b11111110);
}
/**************************************************************************/
/* Timer 2 Overflow, general purpose timing, gontrol action timeout */
#int_TIMER2
void control_timer_isr()
{
output_high(PIN_C0);
counter++;
if (stdDemandDebounce) stdDemandDebounce--;
if (enableCompDebounce) enableCompDebounce--;
if (dualRunDebounce) dualRunDebounce--;
if (compSelDebounce) compSelDebounce--;
if (blinkTimer) blinkTimer--;
if (compUnlTimer) compUnlTimer--;
} // int_timer2
/*****************************************************************************/
/* Main routine. Called at power up and reset */
/*****************************************************************************/
#zero_ram
void main()
{
//double
setup_wdt(WDT_OFF);
//Initialize timer 2 for general timing with a 5ms overflow
setup_timer_2(T2_DIV_BY_16, 222, 14); //5ms overflows
//Enable overflow interrupts on timer 2 (every 5ms).
enable_interrupts(INT_TIMER2);
disable_interrupts(INT_RTCC);
disable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER1);
disable_interrupts(INT_TIMER3);
disable_interrupts(INT_EXT);
disable_interrupts(INT_EXT1);
disable_interrupts(INT_EXT2);
disable_interrupts(INT_EXT3);
disable_interrupts(INT_RB);
disable_interrupts(INT_PSP);
disable_interrupts(INT_AD);
disable_interrupts(INT_RDA);
disable_interrupts(INT_TBE);
disable_interrupts(INT_SSP);// 0x9D08
disable_interrupts(INT_CCP1);// 0x9D04
disable_interrupts(INT_CCP2);// 0xA001
disable_interrupts(INT_BUSCOL);// 0xA008
disable_interrupts(INT_LOWVOLT);// 0xA004
disable_interrupts(INT_CANIRX);// 0xA380
disable_interrupts(INT_CANWAKE);// 0xA340
disable_interrupts(INT_CANERR);// 0xA320
disable_interrupts(INT_COMP);// 0xA040
disable_interrupts(INT_EEPROM);// 0xA010
disable_interrupts(INT_CANTX2);// 0xA310
disable_interrupts(INT_CANTX1);// 0xA308
disable_interrupts(INT_CANTX0);// 0xA304
disable_interrupts(INT_CANRX1);// 0xA302
disable_interrupts(INT_CANRX0);// 0xA301
disable_interrupts(INT_LVD);// 0xA004
bit_clear(*RCSTA, 7); //disable the serial port as we are using C6 for I/O
initialize_IO_direction();
// delay_ms(100);
// set_timer2(0);
enable_interrupts(GLOBAL);
output_c(0);
do //Main program loop
{
//restart_wdt();
output_high(PIN_C7);
delay_ms(1000);
output_low(PIN_C7);
delay_ms(500);
}
}
|
If I remove the enable_interrupts(global); line then the LED I have picked up to pic_c7 blinks. If I have enable_interrupts(GLOBAL) on then nothing happens and the LED I have hooked up to PIN_C0 does not go on.
I'm sure I am not doing something really really simple but can't figure it out.
Thanks for your help,
Andrew Valeri |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 20, 2005 5:08 pm |
|
|
Quote: | I have taken almost everything out of my code and it still doesn't work. |
The program that you posted is not a simple test program.
If you want to test Timer2 interrupts, then you can remove
about 95% of your program.
Look at my post in the following thread. It has a small test program
which is designed to only test Timer2 interrupts. It doesn't do anything
else. You should try to make a test program similar to this.
http://www.ccsinfo.com/forum/viewtopic.php?t=22447 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Apr 21, 2005 7:22 am |
|
|
Andrewv wrote:
Code: |
do //Main program loop
{
//restart_wdt();
output_high(PIN_C7);
delay_ms(1000);
output_low(PIN_C7);
delay_ms(500);
}
|
do statement is not a loop, it execute only once
To get a loop it needs to test a while(TRUE) at the end.
Code: |
do //Main program loop
{
//restart_wdt();
output_high(PIN_C7);
delay_ms(1000);
output_low(PIN_C7);
delay_ms(500);
}while(1);
|
Humberto |
|
|
|
|
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
|