Author Topic: timer1 interrupt killing everything else?  (Read 2812 times)

0 Members and 1 Guest are viewing this topic.

Offline szhangTopic starter

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
timer1 interrupt killing everything else?
« on: October 03, 2008, 03:50:33 PM »
So I have this funny problem.  I have a dsPIC running at 40MIPS (20MHz external crystal with PLL), and as long as I don't enable timer1 interrupt, everything seems to work fine.  But when I enable it, it seems the chip just freezes after a few ms.

So the following code pulse RB7 at about 80Hz, when T1IE=0, it works like it should.  With T1IE=1 however, all kinds of weird stuff happen.  From my logic analyzer output, sometimes the RB7 gets latched low after 1 pulse, sometimes after 3 or 4, sometimes there is a extra long pulse.

It all seems the code is not exiting from the ISR, but I don't know why.

Code: [Select]
#include <p33fj128gp202.h>

_FOSCSEL(FNOSC_PRIPLL & IESO_ON);

_FOSC(FCKSM_CSECME & OSCIOFNC_OFF & POSCMD_HS);

volatile unsigned long TICK;


void _ISR _T1Interrupt(void)
{
  /* Interrupt Service Routine code goes here */
  IFS0bits.T1IF = 0; //Clear Timer1 interrupt flag
}
void clock_init()
{
  CLKDIVbits.PLLPRE=2;           //4x PLLPRE
  PLLFBDbits.PLLDIV=0x1E;      //32x PLLDIV
  CLKDIVbits.PLLPOST=0;         //2x PLLPOST
}
void timers_init()
{
  T1CONbits.TON = 0;      // Disable Timer
  T1CONbits.TCS = 0;      // Select internal instruction cycle clock
  T1CONbits.TGATE = 0;    // Disable Gated Timer mode
  T1CONbits.TCKPS = 0b00; // Select 1:1 Prescaler
  TMR1 = 0x00;            // Clear timer register
  PR1 = 40000;            // Load the period value
  IFS0bits.T1IF = 0;      // Clear Timer1 Interrupt Flag
  T1CONbits.TON = 1;      // Start Timer
  IEC0bits.T1IE = 1;      // Enable Timer1 interrupt
}
int main(void)
{
  unsigned int i,j;

  unsigned int v=0;

  clock_init();

  timers_init();

  AD1PCFGL = 0xffff; //All analog capable pins in digital mode
  TRISA = 0; //All pins output
  TRISB = 0; //All pins output
  LATA = 0;  //All pins low
  LATB = 0;  //All pins low


  while(1)
  {
    for(i=0;i<65535;i++);
     
    LATBbits.LATB7=v;

    v=!v;
  }
  return 0;
}

Offline szhangTopic starter

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
    • szhang.net
Re: timer1 interrupt killing everything else?
« Reply #1 on: October 06, 2008, 12:45:58 AM »
OMG i'm stupid...

I have two tantalum capacitors, one 1uF, one .1uF, I was using the .1uF when I though I was using the 1uF.  Can't believe it took me forever to fix it...  The T1 interrupt problem completely threw me off.
« Last Edit: October 06, 2008, 01:01:23 AM by szhang »

 


Get Your Ad Here