Periodic Interrupt Timer Problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Periodic Interrupt Timer Problem

2,440 Views
Forsaken
Contributor III

Hi,

 

on my code I have configured 4 PITs, they are working fine with the expected timming, but when I let the program running for a while the PIT stops requesting the interrupts, and the functions usleep and sleep enters on forever loop. I have comment the all the PIT code and I don't have any problem with my code execution, so I presume some errors on PIT code or on PIT interrupt.

 

Thanks for your help in advance.

 

Here is my code.

 

 

on clock source file:

 

void init_pit0(void)
{
  PITINTE|=0x01;  /* (PITMTLD+1)*(PITLD+1)/fbus */
  PITLD0=0xF423;  /* 256*62500*25ns=400ms */
  PITMUX|=0x00;
  PITCFLMT=0xA0;  /* Set the configuration registers before the PITE bit in the PITCFLMT register is set. Before PITE is set, the
                     configuration registers can be written in arbitrary order. */
}

void init_pit1(void)
{
  PITINTE|=0x02;  /* (PITMTLD+1)*(PITLD+1)/fbus */
  PITLD1=0x004E;  /* 256*79*25ns=505.6us */
  PITMUX|=0x00;
  PITCFLMT=0xA0;  /* Set the configuration registers before the PITE bit in the PITCFLMT register is set. Before PITE is set, the
                     configuration registers can be written in arbitrary order. */
}

void init_pit2(void)
{
  PITINTE|=0x04;  /* (PITMTLD+1)*(PITLD+1)/fbus */
  PITLD2=0x0F9F;  /* 1*4000*25ns=100us */
  PITMUX|=0x04;
  PITCFLMT=0xA0;  /* Set the configuration registers before the PITE bit in the PITCFLMT register is set. Before PITE is set, the
                     configuration registers can be written in arbitrary order. */
}

void init_pit3(void)
{
  PITINTE|=0x08;  /* (PITMTLD+1)*(PITLD+1)/fbus */
  PITLD3=0x9C3F;  /* 1*40000*25ns=1ms */
  PITMUX|=0x08;
  PITCFLMT=0xA0;  /* Set the configuration registers before the PITE bit in the PITCFLMT register is set. Before PITE is set, the
                     configuration registers can be written in arbitrary order. */
}

void enable_pit0(void){ PITCE|=0x01;}
void enable_pit1(void){ PITCE|=0x02;}
void enable_pit2(void){ PITCE|=0x04;}
void enable_pit3(void){ PITCE|=0x08;}

 

void enable_pit0(void){ PITCE|=0x01;}
void enable_pit1(void){ PITCE|=0x02;}
void enable_pit2(void){ PITCE|=0x04;}
void enable_pit3(void){ PITCE|=0x08;}

void disable_pit0(void){ PITCE&=(~0x01);}
void disable_pit1(void){ PITCE&=(~0x02);}
void disable_pit2(void){ PITCE&=(~0x04);}
void disable_pit3(void){ PITCE&=(~0x08);}

void usleep(UINT32 Time)
{
  SleepUsTick=0;
  while(SleepUsTick<Time){ W_DOG_Refresh(); asm(NOP);}
}

void sleep(UINT32 Time)
{
  SleepMsTick=0;
  while(SleepMsTick<Time){ W_DOG_Refresh(); asm(NOP);}
}

 

 

 

on main source file:

 

interrupt void PIT0_ISR(void)
{
  asm(MOVB #$01, PITTF);                         /* Write '1' to clear flag */
}

interrupt void PIT1_ISR(void)
{
  asm(MOVB #$02, PITTF);                         /* Write '1' to clear flag */
  STATUS2=!STATUS2;
}

interrupt void PIT2_ISR(void)
{
  asm(MOVB #$04, PITTF);                         /* Write '1' to clear flag */
  SleepUsTick+=100;
}

interrupt void PIT3_ISR(void)
{
  asm(MOVB #$08, PITTF);                         /* Write '1' to clear flag */
  SleepMsTick++;
}

Labels (1)
0 Kudos
4 Replies

785 Views
jsmcortina
Contributor III

Have you tried to BDM this?

 

Start a BDM session, leave it running and then "STOP" when it appears to have hung up.

 

(This assumes that your BDM pod is reliable enough to last that long.)

 

James

0 Kudos

785 Views
Forsaken
Contributor III
Yes, i have tried use BDM. When it crashes, it appears on status bar "INVALID BREAKPOINT", and i don't have any breakpoints.
0 Kudos

785 Views
nandu
Contributor III

Hi Forsaken,

 

You said, "the functions 'usleep' and 'sleep' enters on forever loop".

 

Where are you calling those functions in your code ? can you please be more specific on it ?

 

And in both the functions please check the "while" condition.

 

SleepUsTick=0;
while(SleepUsTick<Time){ W_DOG_Refresh(); asm(NOP);}

 

and 

 

SleepMsTick=0;
while(SleepMsTick<Time){ W_DOG_Refresh(); asm(NOP);}

 

That means, in both the above two cases, if value of the variable "Time" greater than zero, then the while condition will be always true and the controll will be always in one of those functions.

Please recheck the variables "SleepUsTick" and "SleepMsTick". Clearing these two variables just before the while condition looks suspisious to me.

 

And what value the variable "Time" has ? and where does it get the value from ?

 

If possible, please provide more information like, your Microcontroller, Compiler details etc.

 

 

0 Kudos

785 Views
Forsaken
Contributor III

Sorry for my delay.

 

I don't think the problem resides on the usleep and sleep functions. After some tests not using this functions, i had the same problem.

 

On my code i have a extern interrupt that triggers a software procedure on xgate, this extern interrupt is frequent trigger on a timer basis ~500 ms, meanwhile i have the 4 timers running on free mode setting a interruption flag after the timer has reach the configuration value for timeout. During my tests, after a while between 30 minutes to 2 hours (the "crash" doesnot have a exact time), the CPU has stopped, and xgate too.

 

I have write code on CPU to send something to the serial port whenever the main cicle has ended, and on xgate to toggle a led on the begining of the software procedure begin.

 

Before the crash i have received both "signals", the serial port character to my hyperterminal and i have seen the led toggling, after the crash, no characters and no led toggling.

 

 

If i comment the xgate rotine, the crash takes a lot longer time to crash, but it crashes.

If i comment the timers, the CPU and xgate does not crashes.

 

I believe there is some problem attending the interrupts caused by the timers. Maybe the timers for some reason stops generating the interrupts.

0 Kudos